1 package com.atol.drivers.fptr.examples;
6 import java.math.BigDecimal;
7 import java.util.Random;
9 public class FptrExample {
10 private static final boolean USE_SHOWPROPERTIES =
false;
11 private static final boolean USE_FZ54 =
true;
12 private static final boolean PRINT_FISCAL_CHECK =
true;
13 private static final boolean PRINT_NONFISCAL_CHECK =
true;
15 private static void checkError(IFptr fptr)
throws DriverException {
16 int rc = fptr.get_ResultCode();
18 String rd = fptr.get_ResultDescription(), bpd = null;
20 bpd = fptr.get_BadParamDescription();
23 throw new DriverException(String.format(
"[%d] %s (%s)", rc, rd, bpd));
25 throw new DriverException(String.format(
"[%d] %s", rc, rd));
29 private static void printText(IFptr fptr, String text,
int alignment,
int wrap)
throws DriverException {
30 if (fptr.put_Caption(text) < 0)
32 if (fptr.put_TextWrap(wrap) < 0)
34 if (fptr.put_Alignment(alignment) < 0)
36 if (fptr.PrintString() < 0)
40 private static void printText(IFptr fptr, String text)
throws DriverException {
41 printText(fptr, text, IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
44 private static void openCheck(IFptr fptr,
int type)
throws DriverException {
45 if (fptr.put_Mode(IFptr.MODE_REGISTRATION) < 0)
47 if (fptr.SetMode() < 0)
49 if (fptr.put_CheckType(type) < 0)
51 if (fptr.OpenCheck() < 0)
55 private static void closeCheck(IFptr fptr,
int typeClose)
throws DriverException {
56 if (fptr.put_TypeClose(typeClose) < 0)
58 if (fptr.CloseCheck() < 0)
62 private static void registration(IFptr fptr, String name,
double price,
double quantity)
throws DriverException {
63 if (fptr.put_Quantity(quantity) < 0)
65 if (fptr.put_Price(price) < 0)
67 if (fptr.put_TextWrap(IFptr.WRAP_WORD) < 0)
69 if (fptr.put_Name(name) < 0)
71 if (fptr.Registration() < 0)
75 private static void registrationFZ54(IFptr fptr, String name,
double price,
double quantity,
76 double positionSum,
int taxNumber)
throws DriverException {
77 if (fptr.put_PositionSum(positionSum) < 0)
79 if (fptr.put_Quantity(quantity) < 0)
81 if (fptr.put_Price(price) < 0)
83 if (fptr.put_TaxNumber(taxNumber) < 0)
85 if (fptr.put_TextWrap(IFptr.WRAP_WORD) < 0)
87 if (fptr.put_Name(name) < 0)
89 if (fptr.Registration() < 0)
94 private static void payment(IFptr fptr,
double sum,
int type)
throws DriverException {
95 if (fptr.put_Summ(sum) < 0)
97 if (fptr.put_TypeClose(type) < 0)
99 if (fptr.Payment() < 0)
101 System.out.println(String.format(
"Remainder: %.2f, Change: %.2f", fptr.get_Remainder(), fptr.get_Change()));
104 private static void reportZ(IFptr fptr)
throws DriverException {
105 if (fptr.put_Mode(IFptr.MODE_REPORT_CLEAR) < 0)
107 if (fptr.SetMode() < 0)
109 if (fptr.put_ReportType(IFptr.REPORT_Z) < 0)
111 if (fptr.Report() < 0)
115 private static void printFooter(IFptr fptr)
throws DriverException {
116 if (fptr.put_Mode(IFptr.MODE_REPORT_NO_CLEAR) < 0)
118 if (fptr.SetMode() < 0)
120 if (fptr.PrintFooter() < 0)
124 private static void printBarcode(IFptr fptr,
int type, String barcode,
double scale)
throws DriverException {
125 if (fptr.put_Alignment(IFptr.ALIGNMENT_CENTER) < 0)
127 if (fptr.put_BarcodeType(type) < 0)
129 if (fptr.put_Barcode(barcode) < 0)
131 if (fptr.put_Height(0) < 0)
133 if (fptr.put_BarcodeVersion(0) < 0)
135 if (fptr.put_BarcodePrintType(IFptr.BARCODE_PRINTTYPE_AUTO) < 0)
137 if (fptr.put_PrintBarcodeText(
false) < 0)
139 if (fptr.put_BarcodeControlCode(
true) < 0)
141 if (fptr.put_Scale(scale) < 0)
143 if (fptr.put_BarcodeCorrection(0) < 0)
145 if (fptr.put_BarcodeColumns(3) < 0)
147 if (fptr.put_BarcodeRows(1) < 0)
149 if (fptr.put_BarcodeProportions(50) < 0)
151 if (fptr.put_BarcodeUseProportions(
true) < 0)
153 if (fptr.put_BarcodePackingMode(IFptr.BARCODE_PDF417_PACKING_MODE_DEFAULT) < 0)
155 if (fptr.put_BarcodePixelProportions(300) < 0)
157 if (fptr.PrintBarcode() < 0)
161 private static void discount(IFptr fptr,
double sum,
int type,
int destination)
throws DriverException {
162 if (fptr.put_Summ(sum) < 0)
164 if (fptr.put_DiscountType(type) < 0)
166 if (fptr.put_Destination(destination) < 0)
168 if (fptr.Discount() < 0)
172 private static void charge(IFptr fptr,
double sum,
int type,
int destination)
throws DriverException {
173 if (fptr.put_Summ(sum) < 0)
175 if (fptr.put_DiscountType(type) < 0)
177 if (fptr.put_Destination(destination) < 0)
179 if (fptr.Charge() < 0)
183 public static void main(String[] argv) {
184 Random random =
new Random();
185 IFptr fptr =
new Fptr();
191 fptr.put_DeviceSingleSetting(fptr.SETTING_SEARCHDIR, System.getProperty(
"java.library.path"));
192 fptr.ApplySingleSettings();
194 if (USE_SHOWPROPERTIES) {
196 if (fptr.ShowProperties() < 0)
206 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_PORT, IFptr.SETTING_PORT_USB) < 0)
208 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_VID, 0x2912) < 0)
210 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_PID, 0x0005) < 0)
213 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_MODEL, IFptr.MODEL_ATOL_55F) < 0)
216 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_MODEL, IFptr.MODEL_FPRINT_55) < 0)
219 if (fptr.put_DeviceSingleSetting(IFptr.SETTING_BAUDRATE, 115200) < 0)
221 if (fptr.ApplySingleSettings() < 0)
226 if (fptr.put_DeviceEnabled(
true) < 0)
230 if (fptr.GetStatus() < 0)
235 String settings = fptr.get_DeviceSettings();
243 if (fptr.CancelCheck() < 0)
245 }
catch (DriverException e) {
246 int rc = fptr.get_ResultCode();
247 if (rc != -16 && rc != -3801)
251 if (PRINT_FISCAL_CHECK) {
254 openCheck(fptr, IFptr.CHEQUE_TYPE_SELL);
255 }
catch (DriverException e) {
257 if (fptr.get_ResultCode() == -3822) {
259 openCheck(fptr, IFptr.CHEQUE_TYPE_SELL);
265 BigDecimal sum =
new BigDecimal(0);
266 for (
int i = -2; i < 5; ++i) {
268 double price = Math.pow(10, i), quantity = 1;
269 registrationFZ54(fptr, String.format(
"Позиция %d", i + 3), price, quantity, price * quantity, IFptr.TAX_VAT_18);
270 sum = sum.add(
new BigDecimal(price).multiply(
new BigDecimal(quantity)));
272 double price = Math.pow(10, i), quantity = 1;
273 registration(fptr, String.format(
"Позиция %d", i + 3), price, quantity);
274 sum = sum.add(
new BigDecimal(price).multiply(
new BigDecimal(quantity)));
277 discount(fptr, 1, IFptr.DISCOUNT_SUMM, IFptr.DESTINATION_POSITION);
279 charge(fptr, 1, IFptr.DISCOUNT_PERCENT, IFptr.DESTINATION_POSITION);
286 discount(fptr, 0, IFptr.DISCOUNT_SUMM, IFptr.DESTINATION_CHECK);
288 discount(fptr, 1, IFptr.DISCOUNT_PERCENT, IFptr.DESTINATION_CHECK);
291 payment(fptr, sum.divide(
new BigDecimal(4)).doubleValue(), 1);
292 payment(fptr, sum.divide(
new BigDecimal(4)).doubleValue(), 2);
293 payment(fptr, sum.divide(
new BigDecimal(4)).doubleValue(), 3);
294 payment(fptr, sum.doubleValue(), 0);
301 if (PRINT_NONFISCAL_CHECK) {
302 printText(fptr,
"Я сразу смазал карту будня, плеснувши краску из стакана;\n" 303 +
"Я показал на блюде студня косые скулы океана.\n" 304 +
"На чешуе жестяной рыбы прочел я зовы новых губ.", IFptr.ALIGNMENT_LEFT, IFptr.WRAP_WORD);
305 printText(fptr,
"А вы", IFptr.ALIGNMENT_LEFT, IFptr.WRAP_WORD);
306 printText(fptr,
"ноктюрн сыграть", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_WORD);
307 printText(fptr,
"могли бы", IFptr.ALIGNMENT_RIGHT, IFptr.WRAP_WORD);
308 printText(fptr,
"на флейте водосточных труб?", IFptr.ALIGNMENT_LEFT, IFptr.WRAP_WORD);
310 printText(fptr,
"\nEAN8", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
311 printBarcode(fptr, IFptr.BARCODE_TYPE_EAN8,
"40182735", 100);
313 printText(fptr,
"\nEAN13", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
314 printBarcode(fptr, IFptr.BARCODE_TYPE_EAN13,
"4007630000116", 200);
316 printText(fptr,
"\nUPCA", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
317 printBarcode(fptr, IFptr.BARCODE_TYPE_UPCA,
"697929110035", 100);
319 printText(fptr,
"\nCODE39", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
320 printBarcode(fptr, IFptr.BARCODE_TYPE_CODE39,
"ATOL.RU", 100);
322 printText(fptr,
"\nPDF417", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
323 printBarcode(fptr, IFptr.BARCODE_TYPE_PDF417,
"1234567", 100);
325 printText(fptr,
"\nQR", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
326 printBarcode(fptr, IFptr.BARCODE_TYPE_QRCODE,
"АТОЛ.РУ", 500);
328 printText(fptr,
"\nITF-14", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
329 printBarcode(fptr, IFptr.BARCODE_TYPE_ITF14,
"00012345600012", 100);
331 printText(fptr,
"\nInterleaved 2 of 5", IFptr.ALIGNMENT_CENTER, IFptr.WRAP_LINE);
332 printBarcode(fptr, IFptr.BARCODE_TYPE_INTERLEAVED_2_OF_5,
"04062300106659", 100);
336 }
catch (Exception e) {
337 System.out.println(e);
343 private static class DriverException
extends Exception {
344 private static final long serialVersionUID = 6164921645357791803L;
346 public DriverException(String msg) {