-
Notifications
You must be signed in to change notification settings - Fork 1
/
vikiprint.cpp
179 lines (143 loc) · 4.15 KB
/
vikiprint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "vikiprint.h"
#include <QTextCodec>
#include <QDebug>
VikiPrint::VikiPrint(QString setPortName, int setPortSpeed)
:Fiscal()
{
if (setPortName.startsWith("COM"))
portName = setPortName;
else
portName = "COM" + setPortName;
portSpeed = setPortSpeed;
taxNumber = static_cast<unsigned char>(1);
qDebug() << "pName -" << portName << ", pSpeed -" << portSpeed;
int result = openPort(portName, portSpeed);
qDebug() << "Result: " << result;
if (!result)
qWarning() << "Порт не открыт!";
commandStart();
statuses = QVector<int>();
}
bool VikiPrint::Ready()
{
int fatalStatus = 0, currentFlagsStatus = 0, documentStatus = 0;
int flagsStatus = getStatusFlags(&fatalStatus, ¤tFlagsStatus, &documentStatus);
return flagsStatus == 0;
}
void VikiPrint::_OpenDocument(byte type)
{
libOpenDocument(type, numDepart, constConvertTo866(cashierName), docNumber);
}
void VikiPrint::CloseDocument()
{
//MData test = MData();
libCloseDocument(1);
//libCloseDocument(test, 1);
ScrollPaper(4);
}
QVector<int> VikiPrint::GetStatuses()
{
return statuses;
}
void VikiPrint::SetTaxNumber(byte number)
{
taxNumber = number;
}
void VikiPrint::SetCashierName(QString name)
{
cashierName = name;
}
void VikiPrint::SetNumDepart(byte number)
{
numDepart = number;
}
void VikiPrint::SetDocNumber(int number)
{
docNumber = number;
}
void VikiPrint::ScrollPaper()
{
scrollPaper();
}
void VikiPrint::ScrollPaper(int count)
{
for (int i = 0; i < count; i++)
scrollPaper();
}
void VikiPrint::PrintString(QString text)
{
libPrintString(constConvertTo866(text), 0);
libCloseDocument(1);
//MData test = MData();
libCloseDocument(1);
}
void VikiPrint::RegisterProduct(QString name, QString barcode, double quantity, double price, int numPos)
{
libAddPosition(constConvertTo866(name), constConvertTo866(barcode), quantity, price, taxNumber, numPos, numDepart, 0, "", 0);
}
void VikiPrint::AnnulateProduct(QString name, double quantity, double price)
{
int numPos = 1;
libAddPosition(constConvertTo866(name), constConvertTo866(name), quantity, price, taxNumber, numPos, numDepart, 0, "", 0);
}
void VikiPrint::RegisterPayment(double sum, byte type)
{
int result = libAddPaymentD(type, sum, "");
}
void VikiPrint::PrintTotal()
{
libSubTotal();
}
void VikiPrint::RegisterSummDiscount(QString nameDiscount, double sum)
{
libAddDiscount(DISCOUNT_PERCENT, constConvertTo866(nameDiscount), (int)(sum*1000));
}
void VikiPrint::RegisterPercentDiscount(QString nameDiscount, double sum)
{
libAddDiscount(DISCOUNT_SUM, constConvertTo866(nameDiscount), (int)(sum*100));
}
void VikiPrint::PrintServiceData()
{
libPrintServiceData();
}
void VikiPrint::OpenSession()
{
libOpenShift(constConvertTo866(cashierName));
}
void VikiPrint::CloseSession()
{
libPrintZReport(constConvertTo866(cashierName), 0);
}
bool VikiPrint::IsSessionOpen()
{
int fatalStatus = 0, currentFlagsStatus = 0, documentStatus = 0;
int flagsStatus = getStatusFlags(&fatalStatus, ¤tFlagsStatus, &documentStatus);
if (flagsStatus == 0)
{
if (currentFlagsStatus & 8)
{
qDebug() << "Смена длится более 24 часов. Смена перезапустится самостоятельно.";
CloseSession();
OpenSession();
return true;
}
if (currentFlagsStatus & 4)
{
return true;
}
}
return false;
}
QByteArray VikiPrint::constConvertTo866(QString str)
{
return QTextCodec::codecForName("CP866")->fromUnicode(str);
}
char* VikiPrint::ConvertTo866(QString str)
{
QTextEncoder* codec866 = QTextCodec::codecForName("CP866")->makeEncoder();
return const_cast<char*>(codec866->fromUnicode(str).operator const char *());
}
void VikiPrint::PrintBarcode(QString barcode, int type)
{
libPrintBarCode(0, 8, 50, type, constConvertTo866(barcode));
}