diff --git a/History.txt b/History.txt index 3b6a070a..0863bc3e 100644 --- a/History.txt +++ b/History.txt @@ -5,6 +5,13 @@ Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090 Url : https://github.com/shtrih-m/javapos_shtrih +******************************************************************************** + + 03.11.2021 + deviceServiceVersion = 1013636 + + [+] Added correction receipt support and sample + ******************************************************************************** 28.10.2021 diff --git a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java index 33e1b895..3661a4cd 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java @@ -285,7 +285,7 @@ public void correctDate() { } } } catch (Exception e) { - logger.error("Correct date failed: " + e.getMessage()); + logger.error("Correct date failed "+ e.getMessage()); } } @@ -313,7 +313,7 @@ private void beforeCommand(PrinterCommand command) throws Exception { try { printerEvents.beforeCommand(command); } catch (Exception e) { - logger.error(e); + logger.error("beforeCommand "+ e.getMessage()); } } } @@ -323,7 +323,7 @@ private void afterCommand(PrinterCommand command) throws Exception { try { printerEvents.afterCommand(command); } catch (Exception e) { - logger.error(e); + logger.error("afterCommand " + e.getMessage()); } } } @@ -1314,7 +1314,7 @@ public void printSale(PriceItem item) throws Exception { item.setText(text); if (capFSPrintItem) { - int rc = fsPrintRecItem2(1, item); + int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_SALE, item); if (isCommandSupported(rc)) { check(rc); return; @@ -1330,7 +1330,7 @@ public void printVoidSale(PriceItem item) throws Exception { item.setText(text); if (capFSPrintItem) { - int rc = fsPrintRecItem2(2, item); + int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_RETSALE, item); if (isCommandSupported(rc)) { check(rc); return; @@ -1347,7 +1347,7 @@ public void printRefund(PriceItem item) throws Exception { item.setText(text); if (capFSPrintItem) { - int rc = fsPrintRecItem2(3, item); + int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_BUY, item); if (isCommandSupported(rc)) { check(rc); return; @@ -1364,7 +1364,7 @@ public void printVoidRefund(PriceItem item) throws Exception { item.setText(text); if (capFSPrintItem) { - int rc = fsPrintRecItem2(4, item); + int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_RETBUY, item); if (isCommandSupported(rc)) { check(rc); return; @@ -1473,8 +1473,7 @@ public int fsStartDayOpen() throws Exception { return executeCommand(command); } - public void resetPrinter() throws Exception - { + public void resetPrinter() throws Exception { tlvItems.clear(); interrupted = false; } @@ -3157,7 +3156,7 @@ public void updateModels() { writer.save(SysUtils.getFilesPath() + "models2.xml"); } catch (Exception e) { - logger.error(e.getMessage()); + logger.error("updateModels "+ e.getMessage()); } } @@ -3346,10 +3345,10 @@ public FSReadSerial fsReadSerial() throws Exception { } @Override - public String getFullSerial(){ + public String getFullSerial() { return fullSerial; } - + @Override public String readFullSerial() throws Exception { if (serial.isEmpty()) { @@ -3559,7 +3558,7 @@ public void openFiscalDay() throws Exception { try { waitForPrinting(); } catch (Exception e) { - logger.error("openFiscalDay wait for printing failed", e); + logger.error("openFiscalDay wait for printing failed"+ e.getMessage()); } } } @@ -3737,7 +3736,7 @@ public void printItems(List items) throws Exception { try { item.print(this); } catch (Exception e) { - logger.error(e.getMessage()); + logger.error("printItems "+ e.getMessage()); } } items.clear(); @@ -3815,11 +3814,25 @@ public void printReceiptHeader(String docName) throws Exception { }; public String getReceiptName(int receiptType) { - if (getCapFiscalStorage()) { - return "КАССОВЫЙ ЧЕК/" + fsDocNames[receiptType]; + String receiptName = ""; + boolean isCorrection = (receiptType & 0xF0) == 0x80; + receiptType = receiptType & 0x0F; + + if ((receiptType < 0) || (receiptType > 3)) { + return receiptName; + } + + if (getCapFiscalStorage()) + { + receiptName = "КАССОВЫЙ ЧЕК"; + if (isCorrection){ + receiptName = "ЧЕК КОРРЕКЦИИ"; + } + receiptName = receiptName + "/" + fsDocNames[receiptType]; } else { - return docNames[receiptType]; + receiptName = docNames[receiptType]; } + return receiptName; } public FSReadBlock fsReadBlock(int offset, int size) throws Exception { @@ -4274,7 +4287,7 @@ public void updateFirmware() throws Exception { } logger.debug("updateFirmware(): OK"); } catch (Exception e) { - logger.error("updateFirmware", e); + logger.error("updateFirmware "+ e.getMessage()); } } @@ -4557,7 +4570,7 @@ private boolean connectDevice(String searchPortName, int searchBaudRate) throws } return true; } catch (Exception e) { - logger.error(e); + logger.error("connectDevice "+ e.getMessage()); return false; } } diff --git a/Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java b/Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java index ba913d78..b050051e 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java @@ -348,15 +348,29 @@ public interface PrinterConst { // Sale receipt public static final int SMFP_RECTYPE_SALE = 0; - // Buy receipt public static final int SMFP_RECTYPE_BUY = 1; - // Sale return receipt public static final int SMFP_RECTYPE_RETSALE = 2; - // Buy return receipt public static final int SMFP_RECTYPE_RETBUY = 3; + // Correction sale receipt + public static final int SMFP_RECTYPE_CORRECTION_SALE = 0x80; + // Correction buy receipt + public static final int SMFP_RECTYPE_CORRECTION_BUY = 0x81; + // Correction sale return receipt + public static final int SMFP_RECTYPE_CORRECTION_RETSALE = 0x82; + // Correction buy return receipt + public static final int SMFP_RECTYPE_CORRECTION_RETBUY = 0x83; + + ////////////////////////////////////////////////////////////////////// + // Operation types + ////////////////////////////////////////////////////////////////////// + + public static final int SMFP_OPERATION_SALE = 1; + public static final int SMFP_OPERATION_RETSALE = 2; + public static final int SMFP_OPERATION_BUY = 3; + public static final int SMFP_OPERATION_RETBUY = 4; // ################################################################### // #### Fiscal printer error codes diff --git a/Source/Core/src/com/shtrih/fiscalprinter/command/TextDocumentFilter.java b/Source/Core/src/com/shtrih/fiscalprinter/command/TextDocumentFilter.java index 89797bcd..474f5455 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/command/TextDocumentFilter.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/command/TextDocumentFilter.java @@ -198,7 +198,8 @@ private void openReceipt2(int receiptType) throws Exception { isDocumentPrinted = false; beginDocument(); long recNumber = getNextRecNumber(getRecNumber(receiptType)); - add(docNames[receiptType], String.format("№%04d", recNumber)); + String docName = printer.getReceiptName(receiptType); + add(docName, String.format("№%04d", recNumber)); } } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java index 6b8c6218..47a17dfc 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java @@ -4595,6 +4595,21 @@ public FiscalReceipt createReceipt(int fiscalReceiptType) throws Exception { case SmFptrConst.SMFPTR_RT_RETBUY: return createSalesReceipt(PrinterConst.SMFP_RECTYPE_RETBUY); + case SmFptrConst.SMFPTR_RT_CORRECTION: + return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_SALE); + + case SmFptrConst.SMFPTR_RT_CORRECTION_SALE: + return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_SALE); + + case SmFptrConst.SMFPTR_RT_CORRECTION_BUY: + return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_BUY); + + case SmFptrConst.SMFPTR_RT_CORRECTION_RETSALE: + return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_RETSALE); + + case SmFptrConst.SMFPTR_RT_CORRECTION_RETBUY: + return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_RETBUY); + default: throw new JposException(JPOS_E_ILLEGAL, Localizer.getString(Localizer.invalidParameterValue)); diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/SmFptrConst.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/SmFptrConst.java index fe577eae..bc272ae9 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/SmFptrConst.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/SmFptrConst.java @@ -899,11 +899,17 @@ private SmFptrConst(){ // /////////////////////////////////////////////////////////////////// // Receipt type constants - public static final int SMFPTR_RT_SALE = 100; - public static final int SMFPTR_RT_BUY = 101; - public static final int SMFPTR_RT_RETSALE = 102; - public static final int SMFPTR_RT_RETBUY = 103; - + public static final int SMFPTR_RT_SALE = 100; + public static final int SMFPTR_RT_BUY = 101; + public static final int SMFPTR_RT_RETSALE = 102; + public static final int SMFPTR_RT_RETBUY = 103; + + public static final int SMFPTR_RT_CORRECTION = 104; + public static final int SMFPTR_RT_CORRECTION_SALE = 105; + public static final int SMFPTR_RT_CORRECTION_BUY = 106; + public static final int SMFPTR_RT_CORRECTION_RETSALE = 107; + public static final int SMFPTR_RT_CORRECTION_RETBUY = 108; + // /////////////////////////////////////////////////////////////////// // KTN types // КН Код неопределенного идентификатора товара 00h 00h diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java index fcf9dc90..62f117b0 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java @@ -64,7 +64,7 @@ public FSSalesReceipt(ReceiptContext context, int receiptType) throws Exception } public boolean isSaleReceipt() { - return receiptType == PrinterConst.SMFP_RECTYPE_SALE; + return ((receiptType & 0x0F) == PrinterConst.SMFP_RECTYPE_SALE); } public void printRecMessage(int station, FontNumber font, String message) @@ -114,9 +114,11 @@ public void beginFiscalReceipt(boolean printHeader) throws Exception { public void openReceipt(boolean isSale) throws Exception { if (!isOpened) { - if (!isSale) { - if (receiptType == PrinterConst.SMFP_RECTYPE_SALE) { - receiptType = PrinterConst.SMFP_RECTYPE_RETSALE; + if (!isSale) + { + if ((receiptType & 0x0F) == PrinterConst.SMFP_RECTYPE_SALE) + { + receiptType = (receiptType & 0xF0) + PrinterConst.SMFP_RECTYPE_RETSALE; } } getPrinter().openReceipt(receiptType); @@ -617,18 +619,22 @@ public void printReceiptItem(FSSaleReceiptItem item) throws Exception { if (!item.getIsStorno()) { switch (receiptType) { case PrinterConst.SMFP_RECTYPE_SALE: + case PrinterConst.SMFP_RECTYPE_CORRECTION_SALE: getDevice().printSale(priceItem); break; case PrinterConst.SMFP_RECTYPE_RETSALE: + case PrinterConst.SMFP_RECTYPE_CORRECTION_RETSALE: getDevice().printVoidSale(priceItem); break; case PrinterConst.SMFP_RECTYPE_BUY: + case PrinterConst.SMFP_RECTYPE_CORRECTION_BUY: getDevice().printRefund(priceItem); break; case PrinterConst.SMFP_RECTYPE_RETBUY: + case PrinterConst.SMFP_RECTYPE_CORRECTION_RETBUY: getDevice().printVoidRefund(priceItem); break; default: diff --git a/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java b/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java index c2ef01cc..8502aaee 100644 --- a/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java +++ b/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java @@ -1,5 +1,5 @@ package com.shtrih.util; public class ServiceVersion { - public static final String VERSION = "634"; + public static final String VERSION = "635"; } \ No newline at end of file diff --git a/Source/FiscalPrinterTest/Res/jpos.xml b/Source/FiscalPrinterTest/Res/jpos.xml index 80dcc13b..4544699b 100644 --- a/Source/FiscalPrinterTest/Res/jpos.xml +++ b/Source/FiscalPrinterTest/Res/jpos.xml @@ -62,7 +62,7 @@ - + @@ -319,9 +319,9 @@ - + - + diff --git a/Source/FiscalPrinterTest/src/PrinterTest.java b/Source/FiscalPrinterTest/src/PrinterTest.java index f67dbac7..866ea5b9 100644 --- a/Source/FiscalPrinterTest/src/PrinterTest.java +++ b/Source/FiscalPrinterTest/src/PrinterTest.java @@ -1024,9 +1024,11 @@ public void printFiscalReceipt() { //printer.readFiscalizationTag(1, 0xFFFF); //printer.readFiscalizationTLV(1); - printSalesReceipt1235(); + //printSalesReceipt1235(); //printFiscalReceipt145_4(); + printCorrectionReceipts(); + } catch (Exception e) { e.printStackTrace(); } @@ -4393,4 +4395,25 @@ private void printSalesReceipt1235() { } } + public void printCorrectionReceipts() { + try { + int[] recTypes = { + SmFptrConst.SMFPTR_RT_CORRECTION, + SmFptrConst.SMFPTR_RT_CORRECTION_SALE, + SmFptrConst.SMFPTR_RT_CORRECTION_RETSALE, + SmFptrConst.SMFPTR_RT_CORRECTION_BUY, + SmFptrConst.SMFPTR_RT_CORRECTION_RETBUY + }; + for (int i = 0; i < recTypes.length; i++) { + printer.resetPrinter(); + printer.setFiscalReceiptType(recTypes[i]); + printer.beginFiscalReceipt(false); + printer.printRecItem("", 100, 1000000, 1, 100, ""); + printer.printRecTotal(106, 106, "30"); + printer.endFiscalReceipt(false); + } + } catch (Exception e) { + e.printStackTrace(); + } + } }