diff --git a/History.txt b/History.txt index 698613bb..432eae10 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 +******************************************************************************** + + 11.07.2023 + deviceServiceVersion = 1013700 + + [-] Fixed errors with receipt duplicate + ******************************************************************************** 14.06.2023 diff --git a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java index b7848278..fe1f72a6 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java @@ -741,4 +741,7 @@ public ReadOperationRegister readOperationRegister2(int number) public void writeTLVItems() throws Exception; public void checkFDOConnection() throws Exception; + + public int getOperatorNumber(); + } diff --git a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java index d9c8ded8..84243808 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java @@ -165,6 +165,8 @@ enum Boolean { private final Map taxRates = new HashMap(); private int printMode = PrinterConst.PRINT_MODE_ENABLED; private boolean connected = false; + private int operatorNumber = 1; + public SMFiscalPrinterImpl(PrinterPort port, PrinterProtocol device, FptrParameters params) { @@ -649,6 +651,7 @@ public LongPrinterStatus readLongStatus() throws Exception { command.setPassword(usrPassword); execute(command); longStatus = command.getStatus(); + operatorNumber = longStatus.getOperatorNumber(); return command.getStatus(); } @@ -694,6 +697,7 @@ public ShortPrinterStatus readShortStatus() throws Exception { ReadShortStatus command = new ReadShortStatus(usrPassword); execute(command); shortStatus = command.getStatus(); + operatorNumber = longStatus.getOperatorNumber(); /* NumberFormat formatter = new DecimalFormat("#0.00"); @@ -1726,8 +1730,11 @@ public void openReceipt(int receiptType) throws Exception { command.setPassword(usrPassword); command.setReceiptType(receiptType); int rc = executeCommand(command); + if (command.isSucceeded()){ + operatorNumber = command.getOperator(); + } + capOpenReceipt = isCommandSupported(rc); - if (capOpenReceipt) { check(rc); writeTLVItems(); @@ -5394,5 +5401,9 @@ public String getText(String text) { } return text; } + + public int getOperatorNumber(){ + return operatorNumber; + } } diff --git a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterNull.java b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterNull.java index 534bb923..454fdda8 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterNull.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterNull.java @@ -1320,4 +1320,8 @@ public void writeTLVItems() throws Exception{ public void checkFDOConnection() throws Exception{ } + + public int getOperatorNumber(){ + return 1; + } } diff --git a/Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java b/Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java index 54b4e16c..e04b7755 100644 --- a/Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java +++ b/Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java @@ -9,7 +9,11 @@ import com.shtrih.barcode.PrinterBarcode; import com.shtrih.fiscalprinter.FontNumber; import com.shtrih.fiscalprinter.SMFiscalPrinter; +import com.shtrih.fiscalprinter.TLVItems; +import com.shtrih.fiscalprinter.TLVReader; +import com.shtrih.fiscalprinter.TLVTextWriter; import com.shtrih.fiscalprinter.command.PrinterConst; +import static com.shtrih.fiscalprinter.command.PrinterConst.SMFP_STATION_REC; import static com.shtrih.fiscalprinter.command.TextDocumentFilter.quantityToStr; import com.shtrih.fiscalprinter.skl.FileSKLStorage; import com.shtrih.fiscalprinter.skl.SKLStorage; @@ -20,6 +24,7 @@ import com.shtrih.jpos.fiscalprinter.receipt.FSSalesReceipt; import com.shtrih.jpos.fiscalprinter.receipt.FSTextReceiptItem; import com.shtrih.jpos.fiscalprinter.receipt.FSSaleReceiptItem; +import com.shtrih.jpos.fiscalprinter.receipt.FSTLVItem; import com.shtrih.util.CompositeLogger; import com.shtrih.util.StringUtils; import com.shtrih.util.SysUtils; @@ -53,72 +58,67 @@ public class TextGenerator implements ReceiptVisitor { public TextGenerator(SMFiscalPrinter printer) throws Exception { this.printer = printer; } - - public void visitCustomReceipt(Object element){ + + public void visitCustomReceipt(Object element) { } - - public void visitSalesReceipt(Object element) - { - if (!(element instanceof FSSalesReceipt)) return; - FSSalesReceipt receipt = (FSSalesReceipt)element; - try - { + + public void visitSalesReceipt(Object element) { + if (!(element instanceof FSSalesReceipt)) { + return; + } + FSSalesReceipt receipt = (FSSalesReceipt) element; + try { connect(); + operatorNumber = printer.getOperatorNumber(); + lines.clear(); printReceiptHeader(); for (int i = 0; i < receipt.items.size(); i++) { process((Object) receipt.items.get(i)); } - if (receipt.discounts.getTotal() > 0) - { + if (receipt.discounts.getTotal() > 0) { add(PrinterConst.STotalText, summToStr(receipt.getSubtotal())); /* - if (receipt.isRounded()){ - add(PrinterConst.SRoundingText, summToStr(receipt.getRounding())); + if (receipt.isRounded()){ + add(PrinterConst.SRoundingText, summToStr(receipt.getRounding())); + } + */ + } + + add(PrinterConst.SReceiptTotal, summToStr(receipt.getSubtotal())); + // payments + long[] payments = receipt.getPayments(); + for (int i = 0; i < payments.length; i++) + { + if (payments[i] > 0) + { + String paymentName = printer.readTable(PrinterConst.SMFP_TABLE_PAYTYPE, i + 1, 1); + add(paymentName, summToStr(payments[i])); } - */ } - //add(PrinterConst.SReceiptTotal, summToStr(receipt.getTotal())); - /* - receipt.getPaymentAmount() - long[] payments = params.getPayments(); - - for (int i = 0; i < payments.length; i++) { - if (payments[i] > 0) { - add(getPaymentName(i), summToStr(payments[i])); + // Change + if (receipt.getChange() > 0) + { + add(PrinterConst.SChangeText, summToStr(receipt.getChange())); } - } - // Change - if (command.getChange() > 0) { - add(SChangeText, summToStr(command.getChange())); - } - - addFiscalSign(); - readEJReport(true); - endDocument(); - } - */ - - } - catch(Exception e){ + } catch (Exception e) { logger.error("Failed duplicate receipt", e); } } - public void addFiscalSign() - { - try{ + + public void addFiscalSign() { + try { printer.waitForPrinting(); long docNumber = printer.fsReadStatus().getDocNumber(); long docSign = printer.fsFindDocument(docNumber).getDocument().getDocSign(); add(String.format("ФД:%d ФП:%10d", docNumber, docSign)); - } - catch(Exception e){ + } catch (Exception e) { logger.error("addFiscalSign", e); } } - + private void connect() throws Exception { if (!connected) { printer.check(printer.readDeviceMetrics()); //! @@ -133,19 +133,18 @@ private void connect() throws Exception { connected = true; } } - + private String getOperatorName() throws Exception { String operatorName = operators.get(operatorNumber); - if (operatorName == null) - { + if (operatorName == null) { String[] fieldValue = new String[1]; printer.check(printer.readTable(PrinterConst.SMFP_TABLE_CASHIER, operatorNumber, 2, fieldValue)); operatorName = fieldValue[0]; operators.put(operatorNumber, operatorName); } return operatorName; - } - + } + private void printReceiptHeader() throws Exception { LongPrinterStatus status = printer.readLongStatus(); int documentNumber = status.getDocumentNumber() + 1; @@ -160,12 +159,15 @@ private void printReceiptHeader() throws Exception { time.getHour(), time.getMin()); add(s, getOperatorName()); } - + private void process(Object item) throws Exception { try { if (item instanceof FSSaleReceiptItem) { process((FSSaleReceiptItem) item); } + if (item instanceof FSTLVItem) { + process((FSTLVItem) item); + } if (item instanceof FSTextReceiptItem) { process((FSTextReceiptItem) item); } @@ -191,15 +193,15 @@ private String amountToStr(long value) { DecimalFormat formatter = new DecimalFormat("0.00", symbols); return formatter.format(value / 100.0); } - + private String summToStr(long price, double quantity) { return summToStr(Math.round(quantity * price)); } - + private String summToStr(long amount) { return "=" + amountToStr(amount); } - + private String getTaxData(int tax1, int tax2, int tax3, int tax4) throws Exception { String result = ""; String taxLetters = " АБВГДЕ"; @@ -220,19 +222,42 @@ private String getTaxData(int tax1, int tax2, int tax3, int tax4) throws Excepti } return result; } - + private void process(FSSaleReceiptItem item) throws Exception { String line = ""; add(item.getText()); - line = String.format("%s X %s", - quantityToStr(item.getQuantity() / 1000000.0), + line = String.format("%s X %s", + quantityToStr(item.getQuantity() / 1000000.0), amountToStr(item.getPrice())); add("", line); line = summToStr(item.getPrice(), item.getQuantity() / 1000000.0) + getTaxData(item.getTax1(), 0, 0, 0); add(String.format("%02d", item.getDepartment()), line); + + addTags(item.getTags()); + } + + private void process(FSTLVItem item) throws Exception { + addTag(item.getData()); + } + + public void addTags(List items) throws Exception { + for (int i = 0; i < items.size(); i++) { + addTag(items.get(i).getData()); + } + } + + public void addTag(byte[] data) throws Exception { + TLVReader reader = new TLVReader(); + TLVItems tlvItems = reader.read(data); + TLVTextWriter writer = new TLVTextWriter(tlvItems); + List lines = new Vector(); + writer.getPrintText(lines); + for (String line : lines) { + add(line); + } } private void process(FSTextReceiptItem item) throws Exception { @@ -240,38 +265,32 @@ private void process(FSTextReceiptItem item) throws Exception { add(item.text); add(item.postLine); } - + private void process(PrinterBarcode item) throws Exception { add("BARCODE"); add(item.getLabel()); add(item.getText()); } - - private void process(AmountItem item) throws Exception - { - if (item.getAmount() > 0) - { - if (item.getText().isEmpty()) - { + + private void process(AmountItem item) throws Exception { + if (item.getAmount() > 0) { + if (item.getText().isEmpty()) { add("СКИДКА", "=" + amountToStr(item.getAmount())); - } else - { + } else { add("СКИДКА"); add(item.getText(), "=" + amountToStr(item.getAmount())); } - } else{ - if (item.getText().isEmpty()) - { + } else { + if (item.getText().isEmpty()) { add("НАДБАВКА", "=" + amountToStr(Math.abs(item.getAmount()))); - } else - { + } else { add("НАДБАВКА"); add(item.getText(), "=" + amountToStr(Math.abs(item.getAmount()))); } } } - - private int getLineLength() throws Exception{ + + private int getLineLength() throws Exception { if (lineLength == 0) { lineLength = printer.getMessageLength(); } @@ -285,10 +304,10 @@ private void add(String s1, String s2) throws Exception { } - public List getLines(){ + public List getLines() { return lines; } - + private void add(String line) throws Exception { if (line == null) { return; @@ -296,4 +315,4 @@ private void add(String line) throws Exception { lines.add(line); } -} \ No newline at end of file +} diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/DiscountFilter.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/DiscountFilter.java deleted file mode 100644 index 138e0300..00000000 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/DiscountFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.shtrih.jpos.fiscalprinter; - -/** - * - * @author V.Kravtsov - */ -import com.shtrih.fiscalprinter.receipt.PrinterAmount; -import com.shtrih.fiscalprinter.receipt.PrinterReceipt; -import com.shtrih.fiscalprinter.receipt.ReceiptItem; -import com.shtrih.fiscalprinter.receipt.ReceiptItems; -import com.shtrih.jpos.fiscalprinter.request.PrintRecItemAdjustmentRequest; -import com.shtrih.jpos.fiscalprinter.request.PrintRecItemVoidRequest; - -public class DiscountFilter extends FiscalPrinterFilter implements - FiscalPrinterFilter113 { - - private final FiscalPrinterImpl printer; - - /** Creates a new instance of DiscountFilter */ - public DiscountFilter(FiscalPrinterImpl printer) { - this.printer = printer; - } - - - public PrintRecItemAdjustmentRequest printRecItemAdjustment( - PrintRecItemAdjustmentRequest request) throws Exception { - return request; - } - - public long getItemAmount(long price, int quantity, long unitPrice) { - if (unitPrice == 0) { - quantity = 1000; - } else { - if (quantity == 0) { - quantity = 1000; - } - price = unitPrice; - } - return PrinterAmount.getAmount(price, quantity); - } - - - public PrintRecItemVoidRequest printRecItemVoid( - PrintRecItemVoidRequest request) throws Exception { - long amount = getItemAmount(request.getPrice(), request.getQuantity(), - request.getUnitPrice()); - PrinterReceipt receipt = printer.getReceipt(); - String description = request.getDescription(); - ReceiptItems items = receipt.getItems(); - - for (int i = 0; i < items.size(); i++) { - ReceiptItem item = items.get(i); - if (item.getId() == ReceiptItem.RECEIPT_ITEM_SALE) { - if (item.getDescription().equalsIgnoreCase(description)) { - if (item.getDiscount() > 0) { - if (item.getAmount() == amount) { - request.setQuantity(1000); - request.setPrice(amount - item.getDiscount()); - } - } - } - } - } - return request; - } -} diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java index 8bee4acb..195a88b3 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FiscalPrinterImpl.java @@ -61,8 +61,6 @@ import com.shtrih.jpos.fiscalprinter.receipt.NonfiscalReceipt; import com.shtrih.jpos.fiscalprinter.receipt.NullReceipt; import com.shtrih.jpos.fiscalprinter.receipt.ReceiptContext; -import com.shtrih.jpos.fiscalprinter.receipt.ReceiptPrinter; -import com.shtrih.jpos.fiscalprinter.receipt.ReceiptPrinterImpl; import com.shtrih.jpos.fiscalprinter.receipt.SalesReceipt; import com.shtrih.jpos.fiscalprinter.request.FiscalPrinterRequest; import com.shtrih.jpos.fiscalprinter.request.PrintNormalRequest; @@ -154,7 +152,6 @@ public class FiscalPrinterImpl extends DeviceService implements PrinterConst, private PrinterPort port; private PrinterProtocol device = null; private SMFiscalPrinter printer; - private ReceiptPrinter receiptPrinter; private final FiscalPrinterStatistics statistics; // -------------------------------------------------------------------------- // Variables @@ -262,7 +259,6 @@ public class FiscalPrinterImpl extends DeviceService implements PrinterConst, private String logicalName = ""; private boolean asyncMode = false; private FiscalReceipt receipt = new NullReceipt(); - private final PrinterReceipt printerReceipt = new PrinterReceipt(); private boolean connected = false; private boolean isLicenseValid = false; private final MonitoringServerX5 monitoringServer = new MonitoringServerX5(this); @@ -2254,7 +2250,6 @@ public void open(String logicalName, EventCallbacks cb) throws Exception { if (params.receiptReportEnabled) { getPrinter().addEvents(new ReceiptReportFilter(printer, params)); } - receiptPrinter = new ReceiptPrinterImpl(printer, params); getPrinter().setTaxPassword(params.taxPassword); getPrinter().setUsrPassword(params.usrPassword); getPrinter().setSysPassword(params.sysPassword); @@ -2331,11 +2326,6 @@ private void createFilters() throws Exception { filters.add(filter); } - - if (params.discountFilterEnabled) { - FiscalPrinterFilter113 filter = new DiscountFilter(this); - filters.add(filter); - } } public void release() throws Exception { @@ -4732,8 +4722,8 @@ private FiscalReceipt createSalesReceipt(int receiptType) throws Exception { private ReceiptContext getReceiptContext() { if (receiptContext == null) { - receiptContext = new ReceiptContext(receiptPrinter, params, - fiscalDay, printerReceipt, printerState, this); + receiptContext = new ReceiptContext(printer, params, + fiscalDay, printerState, this); } return receiptContext; } @@ -4742,10 +4732,6 @@ public FptrParameters getParams() { return params; } - public PrinterReceipt getReceipt() { - return printerReceipt; - } - public FontNumber getFont() { return params.getFont(); } @@ -4937,4 +4923,11 @@ private void readLastDocument() { } } + /* + private final PrinterReceipt printerReceipt = new PrinterReceipt(); + public PrinterReceipt getReceipt() { + return printerReceipt; + } + */ + } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FptrParameters.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FptrParameters.java index d02bed2c..1ed49c23 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/FptrParameters.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/FptrParameters.java @@ -89,7 +89,6 @@ public class FptrParameters { public String zeroPriceFilterTime1 = "21:00"; public String zeroPriceFilterTime2 = "11:00"; public String zeroPriceFilterErrorText = ""; - public boolean discountFilterEnabled = false; public int RFAmountLength = 8; public int RFQuantityLength = 10; @@ -340,8 +339,6 @@ public void load(JposEntry entry) throws Exception { "11:00"); zeroPriceFilterErrorText = reader.readString( "ZeroPriceFilterErrorText", ""); - discountFilterEnabled = reader.readBoolean("DiscountFilterEnabled", - false); salesReceiptType = reader.readInteger("salesReceiptType", SmFptrConst.SMFPTR_RECEIPT_NORMAL); cutPaperDelay = reader.readInteger("cutPaperDelay", 0); diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashInReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashInReceipt.java index 9526e3be..f746fd81 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashInReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashInReceipt.java @@ -27,14 +27,14 @@ public void printRecCash(long amount) throws Exception { public void endFiscalReceipt(boolean printHeader) throws Exception { logger.debug("endFiscalReceipt"); - getPrinter().getPrinter().printCashIn(total); + getPrinter().printCashIn(total); } public void printRecTotal(long total, long payment, long payType, String description) throws Exception { logger.debug("printRecTotal"); - getPrinter().printPreLine(); - getPrinter().printPostLine(); + printPreLine(); + printPostLine(); this.payment += payment; } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashOutReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashOutReceipt.java index 3097324f..1ecb712d 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashOutReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CashOutReceipt.java @@ -27,14 +27,14 @@ public void printRecCash(long amount) throws Exception { public void endFiscalReceipt(boolean printHeader) throws Exception { logger.debug("endFiscalReceipt"); - getPrinter().getPrinter().printCashOut(total); + getPrinter().printCashOut(total); } public void printRecTotal(long total, long payment, long payType, String description) throws Exception { logger.debug("printRecTotal"); - getPrinter().printPreLine(); - getPrinter().printPostLine(); + printPreLine(); + printPostLine(); this.payment += payment; } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CustomReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CustomReceipt.java index 73b800dc..709325f8 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CustomReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/CustomReceipt.java @@ -17,6 +17,7 @@ import com.shtrih.fiscalprinter.GS1Barcode; import com.shtrih.fiscalprinter.SMFiscalPrinter; import com.shtrih.fiscalprinter.command.ItemCode; +import com.shtrih.fiscalprinter.command.PrinterConst; import com.shtrih.fiscalprinter.command.PrinterStatus; import com.shtrih.fiscalprinter.model.PrinterModel; import com.shtrih.fiscalprinter.receipt.PrinterReceipt; @@ -29,6 +30,8 @@ import static jpos.FiscalPrinterConst.JPOS_EFPTR_BAD_ITEM_AMOUNT; import static jpos.JposConst.JPOS_E_EXTENDED; import com.shtrih.fiscalprinter.command.TextLine; +import com.shtrih.jpos.fiscalprinter.JposPrinterStation; +import com.shtrih.util.Localizer; import java.util.Vector; public abstract class CustomReceipt implements FiscalReceipt { @@ -41,38 +44,83 @@ public CustomReceipt(ReceiptContext context) { this.context = context; } + public FptrParameters getParams() { + return context.getParams(); + } + + public SMFiscalPrinter getPrinter() { + return context.getPrinter(); + } + + public FiscalDay getFiscalDay() { + return context.getFiscalDay(); + } + public ReceiptContext getContext() { return context; } - + public FiscalPrinterImpl getService() { return context.getService(); } + + public PrinterModel getModel() throws Exception { + return getPrinter().getModel(); + } - public void setPrinterState(int state) { - context.setPrinterState(state); + public void printRecMessage(int station, FontNumber font, String message) + throws Exception { + getPrinter().printText(station, message, font); } - public ReceiptPrinter getPrinter() { - return context.getPrinter(); + public void printNormal(int station, String data) throws Exception { + getPrinter().printText(getStation(station), data, + getParams().font); } - public FptrParameters getParams() { - return context.getParams(); + public void checkTotal(long recTotal, long appTotal) throws Exception { + if (!getParams().checkTotalEnabled) { + return; + } + + if (!getService().getCheckTotal()) { + return; + } + + if (recTotal != appTotal) { + logger.error("Totals compare failed!"); + logger.debug("Receipt total: " + recTotal); + logger.debug("Application total: " + appTotal); + + setPrinterState(FPTR_PS_MONITOR); + throw new JposException(JPOS_E_EXTENDED, + JPOS_EFPTR_BAD_ITEM_AMOUNT); + } + } + + public void printBarcode(PrinterBarcode barcode) throws Exception { + getPrinter().printBarcode(barcode); } - public FiscalDay getFiscalDay() { - return context.getFiscalDay(); + public void printGraphics(PrinterGraphics graphics) throws Exception { + graphics.print(getPrinter()); } - public PrinterReceipt getReceipt() { - return context.getReceipt(); + public long getSubtotal() throws Exception { + long total = 0; + PrinterStatus status = getPrinter().readPrinterStatus(); + if (status.getPrinterMode().isReceiptOpened()) { + total = getPrinter().getSubtotal(); + } + return total; } - public PrinterModel getModel() throws Exception { - return getPrinter().getPrinter().getModel(); + + public void setPrinterState(int state) { + context.setPrinterState(state); } + public boolean getCapAutoCut() throws Exception { return false; } @@ -205,35 +253,6 @@ public void printRecItemRefundVoid(String description, long amount, notSupported(); } - public void printRecMessage(int station, FontNumber font, String message) - throws Exception { - getPrinter().printText(station, message, font); - } - - public void printNormal(int station, String data) throws Exception { - getPrinter().printText(getPrinter().getStation(station), data, - getParams().font); - } - - public void checkTotal(long recTotal, long appTotal) throws Exception { - if (!getParams().checkTotalEnabled) { - return; - } - - if (!getService().getCheckTotal()) { - return; - } - - if (recTotal != appTotal) { - logger.error("Totals compare failed!"); - logger.debug("Receipt total: " + recTotal); - logger.debug("Application total: " + appTotal); - - setPrinterState(FPTR_PS_MONITOR); - throw new JposException(JPOS_E_EXTENDED, - JPOS_EFPTR_BAD_ITEM_AMOUNT); - } - } public void fsWriteTLV(byte[] data, boolean print) throws Exception { } @@ -244,33 +263,106 @@ public void fsWriteOperationTLV(byte[] data, boolean print) throws Exception{ public void setDiscountAmount(int amount) throws Exception { } - public void printBarcode(PrinterBarcode barcode) throws Exception { - getPrinter().getPrinter().printBarcode(barcode); + public void setItemBarcode2(String barcode) throws Exception { } - public void printGraphics(PrinterGraphics graphics) throws Exception { - graphics.print(getPrinter().getPrinter()); + public void addItemCode(ItemCode itemCode) throws Exception{ } - - public void setItemBarcode2(String barcode) throws Exception { + + public void printReceiptEnding() throws Exception{ } + + public void accept(ReceiptVisitor visitor) throws Exception{ + visitor.visitCustomReceipt(this); + } + + public void checkZeroReceipt() throws Exception { - public void addItemCode(ItemCode itemCode) throws Exception{ + if (!context.getParams().getZeroReceiptEnabled()) { + if (getSubtotal() == 0) { + throw new JposException(JposConst.JPOS_E_ILLEGAL, + "Zero receipts sre disabled"); + } + } } - public long getSubtotal() throws Exception { - long total = 0; - PrinterStatus status = getPrinter().getPrinter().readPrinterStatus(); - if (status.getPrinterMode().isReceiptOpened()) { - total = getPrinter().getSubtotal(); + public int getStation(int station) throws Exception { + // check valid stations + JposPrinterStation printerStation = new JposPrinterStation(station); + if (printerStation.isRecStation() + && (!getModel().getCapRecPresent())) { + throw new JposException(JposConst.JPOS_E_ILLEGAL, + Localizer.getString(Localizer.receiptStationNotPresent)); + } + if (printerStation.isJrnStation() + && (!getModel().getCapJrnPresent())) { + throw new JposException(JposConst.JPOS_E_ILLEGAL, + Localizer.getString(Localizer.journalStationNotPresent)); + } + if (printerStation.isSlpStation() + && (!getModel().getCapSlpPresent())) { + throw new JposException(JposConst.JPOS_E_ILLEGAL, + Localizer.getString(Localizer.slipStationNotPresent)); + } + return printerStation.getStation(); + } + + public void printPreLine() throws Exception { + if (getParams().preLine.length() > 0) { + printText(getParams().preLine); + getParams().preLine = ""; } - return total; + } + + public void printPostLine() throws Exception { + if (getParams().postLine.length() > 0) { + printText(getParams().postLine); + getParams().postLine = ""; + } + } + + public void printText(String text) throws Exception { + getPrinter().printText(PrinterConst.SMFP_STATION_REC, text, + getPrinter().getParams().getFont()); } - public void printReceiptEnding() throws Exception{ + public String[] parseText(String text) throws Exception { + logger.debug("parseText: " + text); + FontNumber font = getParams().getFont(); + return getPrinter().splitText(text, font); } - public void accept(ReceiptVisitor visitor) throws Exception{ - visitor.visitCustomReceipt(this); + public String printDescription(String description) throws Exception { + String result = ""; + String[] lines = parseText(description); + if (lines.length == 1) { + result = lines[0]; + } else { + for (int i = 0; i < lines.length - 1; i++) { + printText(lines[i]); + } + result = lines[lines.length - 1]; + } + return result; + } + + private String formatStrings(String line1, String line2) throws Exception { + int len; + String S = ""; + len = getPrinter().getMessageLength() - line2.length(); + + for (int i = 0; i < len; i++) { + if (i < line1.length()) { + S = S + line1.charAt(i); + } else { + S = S + " "; + } + } + return S + line2; + } + + + public void printStrings(String line1, String line2) throws Exception { + printText(formatStrings(line1, line2)); } -} +} 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 26de5d20..6bd6eb57 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceipt.java @@ -80,7 +80,7 @@ public void printNormal(int station, String data) throws Exception { } public SMFiscalPrinter getDevice() { - return getPrinter().getPrinter(); + return getPrinter(); } public boolean isOpened() { @@ -289,7 +289,7 @@ public void printReceiptItems() throws Exception { if (item instanceof PrintItem) { PrintItem printItem = (PrintItem) item; - printItem.print(getPrinter().getPrinter()); + printItem.print(getPrinter()); } if (getParams().writeTagMode == SmFptrConst.WRITE_TAG_MODE_IN_PLACE) { printTLVItem(item); @@ -330,7 +330,7 @@ public void templatePrintReceiptItems() throws Exception { if (item instanceof PrintItem) { PrintItem printItem = (PrintItem) item; - printItem.print(getPrinter().getPrinter()); + printItem.print(getPrinter()); } if (getParams().writeTagMode == SmFptrConst.WRITE_TAG_MODE_IN_PLACE) { printTLVItem(item); @@ -509,8 +509,8 @@ public void endFiscalReceipt(boolean printHeader) throws Exception { if (getParams().printVoidedReceipt) { String docName = getDevice().getReceiptName(receiptType); getDevice().printReceiptHeader(docName); - getPrinter().printText(voidDescription); - getPrinter().printText(getParams().receiptVoidText); + printText(voidDescription); + printText(getParams().receiptVoidText); } } catch (Exception e) { logger.error("Cancel receipt", e); @@ -1090,6 +1090,10 @@ public boolean isPayed() throws Exception long paymentAmount = getPaymentAmount(); return paymentAmount >= subtotal; } + + public long getChange(){ + return getPaymentAmount() - getSubtotal(); + } public void clearPrePostLine() { getParams().clearPrePostLine(); @@ -1294,7 +1298,7 @@ public void printTotalDiscount(long amount, int tax1, String text) discounts.add(item); } - public long getSubtotal() throws Exception { + public long getSubtotal() { long total = 0; for (int i = 0; i < items.size(); i++) { Object object = items.get(i); @@ -1414,7 +1418,7 @@ protected void printTotalAndTax(FSSaleReceiptItem item) throws Exception { } public String formatLines(String line1, String line2) throws Exception { - return StringUtils.alignLines(line1, line2, getPrinter().getTextLength()); + return StringUtils.alignLines(line1, line2, getPrinter().getMessageLength()); } public void printBarcode(PrinterBarcode barcode) throws Exception { @@ -1536,4 +1540,8 @@ public void accept(ReceiptVisitor visitor) throws Exception{ visitor.visitSalesReceipt(this); } + public long[] getPayments(){ + return payments; + } + } \ No newline at end of file diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/GlobusSalesReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/GlobusSalesReceipt.java index 36f784c8..51a50308 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/GlobusSalesReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/GlobusSalesReceipt.java @@ -68,12 +68,18 @@ public int getStation() { private static CompositeLogger logger = CompositeLogger.getLogger(GlobusSalesReceipt.class); private int receiptType = 0; private boolean endSeparatorPrinted = false; + private final PrinterReceipt receipt = new PrinterReceipt(); public GlobusSalesReceipt(ReceiptContext context, int receiptType) { super(context); this.receiptType = receiptType; } + public PrinterReceipt getReceipt() { + return receipt; + } + + public boolean isOpened() { return getReceipt().isOpened(); } @@ -104,9 +110,9 @@ public void printRecItem(String description, long price, double quantity, } price = unitPrice; } - description = getPrinter().printDescription(description); + description = printDescription(description); printReceiptItem(description, price, quantity, vatInfo); - getPrinter().printPostLine(); + printPostLine(); } public String getVatText(int vatInfo) { @@ -129,11 +135,11 @@ public String getVatText(int vatInfo) { public void printLines(String line1, String line2) throws Exception { String text = formatLines(line1, line2); - getPrinter().printText(text); + printText(text); } public String formatLines(String line1, String line2) throws Exception { - return StringUtils.alignLines(line1, line2, getPrinter().getTextLength()); + return StringUtils.alignLines(line1, line2, getPrinter().getMessageLength()); } public void printReceiptItem(String description, long price, double quantity, @@ -166,7 +172,7 @@ public void printReceiptItem(String description, long price, double quantity, + getVatText(vatInfo); text = formatLines(description, text); - getPrinter().printText(text); + printText(text); } public void printReceiptItemVoid(String description, long price, double quantity, @@ -200,21 +206,17 @@ public void printReceiptItemVoid(String description, long price, double quantity + getVatText(vatInfo); text = formatLines(description, text); - getPrinter().printText(text); - } - - public PrinterReceipt getReceipt() { - return getContext().getReceipt(); + printText(text); } public void endFiscalReceipt(boolean printHeader) throws Exception { - PrinterStatus status = getPrinter().getPrinter().waitForPrinting(); + PrinterStatus status = getPrinter().waitForPrinting(); if (status.getPrinterMode().isReceiptOpened()) { if (getReceipt().isCancelled()) { - getPrinter().getPrinter().cancelReceipt(); + getPrinter().cancelReceipt(); getFiscalDay().cancelFiscalRec(); } else { - getPrinter().checkZeroReceipt(); + checkZeroReceipt(); printEndSeparator(); printReceiptItems(); getPrinter().printText(" "); @@ -234,7 +236,7 @@ public void endFiscalReceipt(boolean printHeader) throws Exception { } } else if (getReceipt().isCancelled()) { - getPrinter().printText(getParams().receiptVoidText); + printText(getParams().receiptVoidText); } } @@ -247,8 +249,8 @@ private void printEndSeparator() throws Exception { private void printSeparator() throws Exception { if (getParams().RFSeparatorLine == SmFptrConst.SMFPTR_SEPARATOR_LINE_DASHES) { - String text = StringUtils.stringOfChar('-', getPrinter() - .getTextLength()); + String text = StringUtils.stringOfChar('-', + getPrinter().getMessageLength()); getPrinter().printText(text); } if (getParams().RFSeparatorLine == SmFptrConst.SMFPTR_SEPARATOR_LINE_GRAPHICS) { @@ -266,7 +268,7 @@ public void printRecRefund(String description, long amount, int vatInfo) doOpenReceipt(); printPreLine(); printReceiptItem(description, amount, 1, vatInfo); - getPrinter().printPostLine(); + printPostLine(); } public void printRecTotal(long total, long payment, long payType, @@ -279,7 +281,7 @@ public void printRecTotal(long total, long payment, long payType, payment = total - getPayment(); } getReceipt().addPayment(payment, paymentType.getValue()); - getPrinter().printPostLine(); + printPostLine(); } public void printRecItemVoid(String description, long price, double quantity, @@ -308,8 +310,8 @@ public void printRecSubtotal(long amount) throws Exception { printPreLine(); String text = "=" + StringUtils.amountToString(getReceipt().getTotal()); - getPrinter().getPrinter().printLines(getParams().subtotalText, text, getParams().subtotalFont); - getPrinter().printPostLine(); + getPrinter().printLines(getParams().subtotalText, text, getParams().subtotalFont); + printPostLine(); } @@ -359,7 +361,7 @@ public void printRecSubtotalAdjustment(int adjustmentType, printPreLine(); checkAdjAmount(adjustmentType, amount); recSubtotalAdjustment(description, adjustmentType, amount); - getPrinter().printPostLine(); + printPostLine(); } public void printRecVoidItem(String description, long amount, double quantity, @@ -548,7 +550,7 @@ public void printDiscount(String description, long amount, int vatInfo) String text = "= " + StringUtils.amountToString(amount) + getVatText(vatInfo); text = formatLines(PrinterDiscountText + " " + description, text); - getPrinter().printText(text); + printText(text); } public void printCharge(String description, long amount, int vatInfo) @@ -566,7 +568,7 @@ public void printCharge(String description, long amount, int vatInfo) String text = "= " + StringUtils.amountToString(amount) + getVatText(vatInfo); text = formatLines(PrinterChargeText + " " + description, text); - getPrinter().printText(text); + printText(text); } private void checkPercents(long amount) throws Exception { @@ -752,7 +754,7 @@ long roundAmount(double amount) { } private SMFiscalPrinter getFPrinter() throws Exception { - return getPrinter().getPrinter(); + return getPrinter(); } public void printPreLine() throws Exception { diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/NullReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/NullReceipt.java index 22fd4cf5..767d5aa5 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/NullReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/NullReceipt.java @@ -22,13 +22,12 @@ import com.shtrih.jpos.fiscalprinter.PrintItem; import java.util.Vector; -public class NullReceipt implements FiscalReceipt { +public class NullReceipt extends CustomReceipt implements FiscalReceipt { - private boolean cancelled = false; - private ReceiptContext context = null; private final Vector messages = new Vector(); public NullReceipt() { + super(null); } public Vector getMessages() { @@ -36,15 +35,11 @@ public Vector getMessages() { } public NullReceipt(ReceiptContext context) { - this.context = context; + super(context); } public FptrParameters getParams() { - return context.getParams(); - } - - public ReceiptPrinter getPrinter() { - return context.getPrinter(); + return getContext().getParams(); } public boolean getCapAutoCut() throws Exception { @@ -185,9 +180,8 @@ public void printRecMessage(int station, FontNumber font, String message) } public void printNormal(int station, String data) throws Exception { - if (context != null) { - getPrinter().printText(getPrinter().getStation(station), data, - getParams().font); + if (getContext() != null) { + getPrinter().printText(getStation(station), data, getParams().font); } } @@ -200,22 +194,22 @@ public void disablePrintOnce() throws Exception { } public void fsWriteTLV(byte[] data, boolean print) throws Exception { - getPrinter().getPrinter().fsWriteTLV(data); + getPrinter().fsWriteTLV(data); } public void fsWriteOperationTLV(byte[] data, boolean print) throws Exception { - getPrinter().getPrinter().fsWriteOperationTLV(data); + getPrinter().fsWriteOperationTLV(data); } public void setDiscountAmount(int amount) throws Exception { } public void printBarcode(PrinterBarcode barcode) throws Exception { - getPrinter().getPrinter().printBarcode(barcode); + getPrinter().printBarcode(barcode); } public void printGraphics(PrinterGraphics graphics) throws Exception { - graphics.print(getPrinter().getPrinter()); + graphics.print(getPrinter()); } public void setMessages(Vector messages) { diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptContext.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptContext.java index a002088b..5445143d 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptContext.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptContext.java @@ -8,6 +8,7 @@ * * @author V.Kravtsov */ +import com.shtrih.fiscalprinter.SMFiscalPrinter; import com.shtrih.fiscalprinter.receipt.PrinterReceipt; import com.shtrih.jpos.fiscalprinter.FiscalDay; import com.shtrih.jpos.fiscalprinter.FiscalPrinterState; @@ -16,22 +17,22 @@ public class ReceiptContext { - private final ReceiptPrinter printer; + private final SMFiscalPrinter printer; private final FptrParameters params; private final FiscalDay fiscalDay; - private final PrinterReceipt receipt; private final FiscalPrinterState printerState; private final FiscalPrinterImpl service; - public ReceiptContext(ReceiptPrinter printer, FptrParameters params, - FiscalDay fiscalDay, PrinterReceipt receipt, + public ReceiptContext( + SMFiscalPrinter printer, + FptrParameters params, + FiscalDay fiscalDay, FiscalPrinterState printerState, FiscalPrinterImpl service) { this.printer = printer; this.params = params; this.fiscalDay = fiscalDay; - this.receipt = receipt; this.printerState = printerState; this.service = service; } @@ -39,7 +40,7 @@ public ReceiptContext(ReceiptPrinter printer, FptrParameters params, public FiscalPrinterImpl getService(){ return service; } - + public FiscalPrinterState getPrinterState() { return printerState; } @@ -48,7 +49,7 @@ public void setPrinterState(int printerState) { this.printerState.setValue(printerState); } - public ReceiptPrinter getPrinter() { + public SMFiscalPrinter getPrinter() { return printer; } @@ -60,7 +61,4 @@ public FiscalDay getFiscalDay() { return fiscalDay; } - public PrinterReceipt getReceipt() { - return receipt; - } } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinter.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinter.java deleted file mode 100644 index 25d69e56..00000000 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.shtrih.jpos.fiscalprinter.receipt; - -/** - * - * @author V.Kravtsov - */ - -import com.shtrih.fiscalprinter.FontNumber; -import com.shtrih.fiscalprinter.SMFiscalPrinter; - -public interface ReceiptPrinter { - - public void waitForPrinting() throws Exception; - - public void printPreLine() throws Exception; - - public void printPostLine() throws Exception; - - public long getSubtotal() throws Exception; - - public void openReceipt(int receiptType) throws Exception; - - public String printDescription(String description) throws Exception; - - public void printText(String line) throws Exception; - - public void printText(int station, String text, FontNumber font) - throws Exception; - - public void printStrings(String line1, String line2) throws Exception; - - public SMFiscalPrinter getPrinter(); - - public int getTextLength() throws Exception; - - public void printSeparator(int separatorType, int height) throws Exception; - - public int getStation(int station) throws Exception; - - public void checkZeroReceipt() throws Exception; -} diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinterImpl.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinterImpl.java deleted file mode 100644 index 73052ed3..00000000 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptPrinterImpl.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.shtrih.jpos.fiscalprinter.receipt; - -/** - * @author V.Kravtsov - */ - -import jpos.JposConst; -import jpos.JposException; - -import com.shtrih.util.CompositeLogger; - -import com.shtrih.fiscalprinter.FontNumber; -import com.shtrih.fiscalprinter.SMFiscalPrinter; -import com.shtrih.fiscalprinter.command.PrinterConst; -import com.shtrih.fiscalprinter.command.PrinterStatus; -import com.shtrih.jpos.fiscalprinter.FptrParameters; -import com.shtrih.jpos.fiscalprinter.JposPrinterStation; -import com.shtrih.util.Localizer; - -public class ReceiptPrinterImpl implements ReceiptPrinter { - - private final SMFiscalPrinter printer; - private final FptrParameters params; - private static CompositeLogger logger = CompositeLogger.getLogger(ReceiptPrinterImpl.class); - - public ReceiptPrinterImpl(SMFiscalPrinter printer, FptrParameters params) { - this.printer = printer; - this.params = params; - } - - public void printPreLine() throws Exception { - if (params.preLine.length() > 0) { - printText(params.preLine); - params.preLine = ""; - } - } - - public void printPostLine() throws Exception { - if (params.postLine.length() > 0) { - printText(params.postLine); - params.postLine = ""; - } - } - - public void openReceipt(int receiptType) throws Exception { - printer.openReceipt(receiptType); - } - - - public void printText(String text) throws Exception { - printer.printText(PrinterConst.SMFP_STATION_REC, text, printer - .getParams().getFont()); - } - - - public long getSubtotal() throws Exception { - long total = 0; - PrinterStatus status = printer.readPrinterStatus(); - if (status.getPrinterMode().isReceiptOpened()) { - total = printer.getSubtotal(); - } - return total; - } - - private String formatStrings(String line1, String line2) throws Exception { - int len; - String S = ""; - len = printer.getMessageLength() - line2.length(); - - for (int i = 0; i < len; i++) { - if (i < line1.length()) { - S = S + line1.charAt(i); - } else { - S = S + " "; - } - } - return S + line2; - } - - - public void printStrings(String line1, String line2) throws Exception { - printText(formatStrings(line1, line2)); - } - - - public SMFiscalPrinter getPrinter() { - return printer; - } - - - public void printText(int station, String text, FontNumber font) - throws Exception { - printer.printText(station, text, font); - } - - - public String printDescription(String description) throws Exception { - String result = ""; - String[] lines = parseText(description); - if (lines.length == 1) { - result = lines[0]; - } else { - for (int i = 0; i < lines.length - 1; i++) { - printText(lines[i]); - } - result = lines[lines.length - 1]; - } - return result; - } - - public String[] parseText(String text) throws Exception { - logger.debug("parseText: " + text); - FontNumber font = printer.getParams().getFont(); - return printer.splitText(text, font); - } - - public String processEscCommands(String text) throws Exception { - return text; - } - - - public void waitForPrinting() throws Exception { - printer.waitForPrinting(); - } - - - public int getTextLength() throws Exception { - return printer.getMessageLength(); - } - - - public void printSeparator(int separatorType, int height) throws Exception { - printer.printSeparator(separatorType, height); - } - - - public int getStation(int station) throws Exception { - // check valid stations - JposPrinterStation printerStation = new JposPrinterStation(station); - if (printerStation.isRecStation() - && (!printer.getModel().getCapRecPresent())) { - throw new JposException(JposConst.JPOS_E_ILLEGAL, - Localizer.getString(Localizer.receiptStationNotPresent)); - } - if (printerStation.isJrnStation() - && (!printer.getModel().getCapJrnPresent())) { - throw new JposException(JposConst.JPOS_E_ILLEGAL, - Localizer.getString(Localizer.journalStationNotPresent)); - } - if (printerStation.isSlpStation() - && (!printer.getModel().getCapSlpPresent())) { - throw new JposException(JposConst.JPOS_E_ILLEGAL, - Localizer.getString(Localizer.slipStationNotPresent)); - } - return printerStation.getStation(); - } - - public void checkZeroReceipt() throws Exception { - - if (!params.getZeroReceiptEnabled()) { - if (getPrinter().getSubtotal() == 0) { - throw new JposException(JposConst.JPOS_E_ILLEGAL, - "Zero receipts sre disabled"); - } - } - } -} diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptTemplate.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptTemplate.java index db4c1948..fae8a38e 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptTemplate.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/ReceiptTemplate.java @@ -346,11 +346,11 @@ private String getTagText(Field f, FSSaleReceiptItem item) throws Exception { static String taxLetters = "АБВГДЕ"; private String getTaxName(int tax) throws Exception { - return context.getPrinter().getPrinter().getTaxName(tax); + return context.getPrinter().getTaxName(tax); } private String getTaxAmount(FSSaleReceiptItem item) throws Exception { - long taxAmount = context.getPrinter().getPrinter().getTaxAmount(item.getTax1(), item.getTotal()); + long taxAmount = context.getPrinter().getTaxAmount(item.getTax1(), item.getTotal()); return StringUtils.amountToString(taxAmount); } diff --git a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/SalesReceipt.java b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/SalesReceipt.java index 4b63ffe4..92a2db54 100644 --- a/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/SalesReceipt.java +++ b/Source/Core/src/com/shtrih/jpos/fiscalprinter/receipt/SalesReceipt.java @@ -13,6 +13,7 @@ import jpos.FiscalPrinterConst; import com.shtrih.util.CompositeLogger; +import com.shtrih.fiscalprinter.receipt.PrinterReceipt; import com.shtrih.fiscalprinter.command.AmountItem; import com.shtrih.fiscalprinter.command.CloseRecParams; import com.shtrih.fiscalprinter.command.PriceItem; @@ -42,6 +43,7 @@ public class SalesReceipt extends CustomReceipt implements FiscalReceipt { private boolean isOpened = false; private final long[] vatAmounts = new long[5]; private final ReceiptItems items = new ReceiptItems(); + private final PrinterReceipt receipt = new PrinterReceipt(); private static CompositeLogger logger = CompositeLogger.getLogger(SalesReceipt.class); public SalesReceipt(ReceiptContext context, int receiptType) { @@ -49,6 +51,10 @@ public SalesReceipt(ReceiptContext context, int receiptType) { this.receiptType = receiptType; } + public PrinterReceipt getReceipt(){ + return receipt; + } + public boolean isOpened() { return isOpened; } @@ -82,7 +88,7 @@ public void printRecItem(String description, long price, double quantity, int vatInfo, long unitPrice, String unitName) throws Exception { openReceipt(true); - getPrinter().printPreLine(); + printPreLine(); // if unitPrice is zero then we use price and quantity = 1 long itemPrice = price; if (unitPrice == 0) { @@ -93,14 +99,14 @@ public void printRecItem(String description, long price, double quantity, } itemPrice = unitPrice; } - description = getPrinter().printDescription(description); + description = printDescription(description); printReceiptItem(description, itemPrice, quantity, vatInfo); long amount = Math.round(unitPrice * Math.abs(quantity)); if (amount > price) { printDiscount(amount - price, vatInfo, ""); } - getPrinter().printPostLine(); + printPostLine(); } public void printReceiptItem(String description, long price, double quantity, @@ -132,13 +138,13 @@ public void printReceiptItem(String description, long price, double quantity, } public void endFiscalReceipt(boolean printHeader) throws Exception { - PrinterStatus status = getPrinter().getPrinter().waitForPrinting(); + PrinterStatus status = getPrinter().waitForPrinting(); if (status.getPrinterMode().isReceiptOpened()) { if (getReceipt().isCancelled()) { - getPrinter().getPrinter().cancelReceipt(); + getPrinter().cancelReceipt(); getFiscalDay().cancelFiscalRec(); } else { - getPrinter().checkZeroReceipt(); + checkZeroReceipt(); long[] sum = getReceipt().getPayments(); CloseRecParams closeParams = new CloseRecParams(); closeParams.setSum1(sum[0]); @@ -151,37 +157,37 @@ public void endFiscalReceipt(boolean printHeader) throws Exception { closeParams.setTax4(0); closeParams.setDiscount(0); closeParams.setText(getParams().closeReceiptText); - getPrinter().getPrinter().closeReceipt(closeParams); + getPrinter().closeReceipt(closeParams); getFiscalDay().closeFiscalRec(); // Print may not respond for some time Time.delay(getParams().recCloseSleepTime); } } else if (getReceipt().isCancelled()) { - getPrinter().printText(getParams().receiptVoidText); + printText(getParams().receiptVoidText); } } public void printRecRefund(String description, long amount, int vatInfo) throws Exception { openReceipt(false); - getPrinter().printPreLine(); - description = getPrinter().printDescription(description); + printPreLine(); + description = printDescription(description); printReceiptItem(description, amount, 1, vatInfo); } public void printRecTotal(long total, long payment, long payType, String description) throws Exception { - long receiptSubtotal = getPrinter().getSubtotal(); + long receiptSubtotal = getSubtotal(); checkTotal(receiptSubtotal, total); getReceipt().addPayment(payment, payType); - getPrinter().printPreLine(); - getPrinter().printPostLine(); + printPreLine(); + printPostLine(); } public void printRecItemVoid(String description, long price, double quantity, int vatInfo, long unitPrice, String unitName) throws Exception { openReceipt(false); - getPrinter().printPreLine(); + printPreLine(); // if unitPrice is zero - use price and quantity = 1 if (unitPrice == 0) { quantity = 1; @@ -191,43 +197,43 @@ public void printRecItemVoid(String description, long price, double quantity, } price = unitPrice; } - description = getPrinter().printDescription(description); + description = printDescription(description); printReceiptItem(description, price, quantity, vatInfo); - getPrinter().printPostLine(); + printPostLine(); } public void printRecSubtotal(long amount) throws Exception { - long receiptSubtotal = getPrinter().getSubtotal(); + long receiptSubtotal = getSubtotal(); checkTotal(receiptSubtotal, amount); - getPrinter().printPreLine(); - getPrinter().printStrings(getParams().subtotalText, - "=" + StringUtils.amountToString(getPrinter().getSubtotal())); - getPrinter().printPostLine(); + printPreLine(); + printStrings(getParams().subtotalText, + "=" + StringUtils.amountToString(getSubtotal())); + printPostLine(); } public void printRecItemAdjustment(int adjustmentType, String description, long amount, int vatInfo) throws Exception { - getPrinter().printPreLine(); + printPreLine(); switch (adjustmentType) { case FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT: - description = getPrinter().printDescription(description); + description = printDescription(description); printDiscount(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_AMOUNT_SURCHARGE: - description = getPrinter().printDescription(description); + description = printDescription(description); printCharge(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_DISCOUNT: - description = getPrinter().printDescription(description); + description = printDescription(description); amount = getReceipt().getItemPercentAdjustmentAmount(amount); printDiscount(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_SURCHARGE: - description = getPrinter().printDescription(description); + description = printDescription(description); amount = getReceipt().getItemPercentAdjustmentAmount(amount); printCharge(amount, vatInfo, description); break; @@ -243,27 +249,27 @@ public void printRecSubtotalAdjustment(int adjustmentType, String description, long amount) throws Exception { checkAdjustment(adjustmentType, amount); - getPrinter().printPreLine(); + printPreLine(); switch (adjustmentType) { case FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT: - description = getPrinter().printDescription(description); + description = printDescription(description); printDiscount(amount, 0, description); break; case FiscalPrinterConst.FPTR_AT_AMOUNT_SURCHARGE: - description = getPrinter().printDescription(description); + description = printDescription(description); printCharge(amount, 0, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_DISCOUNT: - description = getPrinter().printDescription(description); - amount = Math.round(getPrinter().getSubtotal() * amount / 10000.0); + description = printDescription(description); + amount = Math.round(getSubtotal() * amount / 10000.0); printDiscount(amount, 0, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_SURCHARGE: - description = getPrinter().printDescription(description); - amount = Math.round(getPrinter().getSubtotal() * amount / 10000.0); + description = printDescription(description); + amount = Math.round(getSubtotal() * amount / 10000.0); printCharge(amount, 0, description); break; @@ -272,13 +278,13 @@ public void printRecSubtotalAdjustment(int adjustmentType, Localizer.getString(Localizer.invalidParameterValue) + "AdjustmentType"); } - getPrinter().printPostLine(); + printPostLine(); } public void printRecVoidItem(String description, long amount, double quantity, int adjustmentType, long adjustment, int vatInfo) throws Exception { openReceipt(false); - description = getPrinter().printDescription(description); + description = printDescription(description); printStorno(amount, quantity, getParams().department, vatInfo, description); } @@ -286,7 +292,7 @@ public void printRecVoidItem(String description, long amount, double quantity, public void printRecRefundVoid(String description, long amount, int vatInfo) throws Exception { openReceipt(true); - description = getPrinter().printDescription(description); + description = printDescription(description); printStorno(amount, 1, getParams().department, vatInfo, description); } @@ -304,9 +310,7 @@ public void printRecPackageAdjustment(int adjustmentType, adjustments.parse(vatAdjustment); checkAdjustments(FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT, adjustments); - getPrinter().printText(PrinterConst.SMFP_STATION_REC, - description, - getPrinter().getPrinter().getParams().getFont()); + printText(description); for (int i = 0; i < adjustments.size(); i++) { adjustment = adjustments.getItem(i); printDiscount(adjustment.amount, adjustment.vat, ""); @@ -319,7 +323,7 @@ public void printRecPackageAdjustment(int adjustmentType, checkAdjustments(FiscalPrinterConst.FPTR_AT_AMOUNT_SURCHARGE, adjustments); - getPrinter().printText(description); + printText(description); for (int i = 0; i < adjustments.size(); i++) { adjustment = adjustments.getItem(i); printCharge(adjustment.amount, adjustment.vat, ""); @@ -347,7 +351,7 @@ public void printRecPackageAdjustVoid(int adjustmentType, checkAdjustments(FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT, adjustments); - getPrinter().printText("Void discount"); + printText("Void discount"); for (int i = 0; i < adjustments.size(); i++) { adjustment = adjustments.getItem(i); printCharge(adjustment.amount, adjustment.vat, ""); @@ -360,7 +364,7 @@ public void printRecPackageAdjustVoid(int adjustmentType, checkAdjustments(FiscalPrinterConst.FPTR_AT_AMOUNT_SURCHARGE, adjustments); - getPrinter().printText("Void charge"); + printText("Void charge"); for (int i = 0; i < adjustments.size(); i++) { adjustment = adjustments.getItem(i); printDiscount(adjustment.amount, adjustment.vat, ""); @@ -376,7 +380,7 @@ public void printRecPackageAdjustVoid(int adjustmentType, public void printRecSubtotalAdjustVoid(int adjustmentType, long amount) throws Exception { - getPrinter().printPreLine(); + printPreLine(); switch (adjustmentType) { case FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT: printDiscount(amount, 0, ""); @@ -387,12 +391,12 @@ public void printRecSubtotalAdjustVoid(int adjustmentType, long amount) break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_DISCOUNT: - amount = Math.round(getPrinter().getSubtotal() * amount / 10000.0); + amount = Math.round(getSubtotal() * amount / 10000.0); printCharge(amount, 0, ""); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_SURCHARGE: - amount = Math.round(getPrinter().getSubtotal() * amount / 10000.0); + amount = Math.round(getSubtotal() * amount / 10000.0); printDiscount(amount, 0, ""); break; @@ -406,26 +410,26 @@ public void printRecSubtotalAdjustVoid(int adjustmentType, long amount) public void printRecItemAdjustmentVoid(int adjustmentType, String description, long amount, int vatInfo) throws Exception { checkAdjustment(adjustmentType, amount); - getPrinter().printPreLine(); + printPreLine(); switch (adjustmentType) { case FiscalPrinterConst.FPTR_AT_AMOUNT_DISCOUNT: - description = getPrinter().printDescription(description); + description = printDescription(description); printCharge(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_AMOUNT_SURCHARGE: - description = getPrinter().printDescription(description); + description = printDescription(description); printDiscount(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_DISCOUNT: - description = getPrinter().printDescription(description); + description = printDescription(description); amount = getReceipt().getItemPercentAdjustmentAmount(amount); printCharge(amount, vatInfo, description); break; case FiscalPrinterConst.FPTR_AT_PERCENTAGE_SURCHARGE: - description = getPrinter().printDescription(description); + description = printDescription(description); amount = getReceipt().getItemPercentAdjustmentAmount(amount); printDiscount(amount, vatInfo, description); break; @@ -441,7 +445,7 @@ public void printRecItemRefund(String description, long amount, double quantity, int vatInfo, long unitAmount, String unitName) throws Exception { openReceipt(false); - getPrinter().printPreLine(); + printPreLine(); // if unitPrice is zero then we use price and quantity = 1 if (unitAmount == 0) { quantity = 1; @@ -451,16 +455,16 @@ public void printRecItemRefund(String description, long amount, } amount = unitAmount; } - description = getPrinter().printDescription(description); + description = printDescription(description); printReceiptItem(description, amount, quantity, vatInfo); - getPrinter().printPostLine(); + printPostLine(); } public void printRecItemRefundVoid(String description, long amount, double quantity, int vatInfo, long unitAmount, String unitName) throws Exception { openReceipt(true); - getPrinter().printPreLine(); + printPreLine(); // if unitPrice is zero - use price and quantity = 1 if (unitAmount == 0) { quantity = 1; @@ -470,14 +474,14 @@ public void printRecItemRefundVoid(String description, long amount, } amount = unitAmount; } - description = getPrinter().printDescription(description); + description = printDescription(description); printStorno(amount, quantity, getParams().department, vatInfo, description); - getPrinter().printPostLine(); + printPostLine(); } public void printRecVoid(String description) throws Exception { - getPrinter().printText(description); + printText(description); getReceipt().cancel(); } @@ -496,7 +500,7 @@ public void printSale(long price, double quantity, int department, item.setTax3(0); item.setTax4(0); item.setText(description); - getPrinter().getPrinter().printSale(item); + getPrinter().printSale(item); vatAmounts[vatInfo] = vatAmounts[vatInfo] + item.getAmount(); getReceipt().printSale(item); } @@ -512,7 +516,7 @@ public void printVoidSale(long price, double quantity, int department, item.setTax3(0); item.setTax4(0); item.setText(description); - getPrinter().getPrinter().printVoidSale(item); + getPrinter().printVoidSale(item); getReceipt().printSaleRefund(item); } @@ -527,7 +531,7 @@ public void printRefund(long price, double quantity, int department, item.setTax3(0); item.setTax4(0); item.setText(description); - getPrinter().getPrinter().printRefund(item); + getPrinter().printRefund(item); getReceipt().printSaleRefund(item); } @@ -542,7 +546,7 @@ public void printVoidRefund(long price, double quantity, int department, item.setTax3(0); item.setTax4(0); item.setText(description); - getPrinter().getPrinter().printVoidRefund(item); + getPrinter().printVoidRefund(item); getReceipt().printSale(item); } @@ -559,7 +563,7 @@ public void printStorno(long price, double quantity, int department, item.setTax3(0); item.setTax4(0); item.setText(description); - getPrinter().getPrinter().printVoidItem(item); + getPrinter().printVoidItem(item); getReceipt().printStorno(item); vatAmounts[vatInfo] = vatAmounts[vatInfo] - vatAmount; } else { @@ -589,7 +593,7 @@ public void printStornoItems() throws Exception { + String.valueOf(vatAmounts[item.getTax1()])); if (item.getAmount() <= vatAmounts[item.getTax1()]) { - getPrinter().getPrinter().printVoidItem(item.getItem()); + getPrinter().printVoidItem(item.getItem()); getReceipt().printStorno(item.getItem()); vatAmounts[item.getTax1()] = vatAmounts[item.getTax1()] - item.getAmount(); @@ -610,7 +614,7 @@ public void printDiscount(long amount, int tax1, String text) item.setTax3(PrinterConst.SMFPTR_TAX_NOTAX); item.setTax4(PrinterConst.SMFPTR_TAX_NOTAX); item.setText(text); - getPrinter().getPrinter().printDiscount(item); + getPrinter().printDiscount(item); getReceipt().printDiscount(item); vatAmounts[tax1] = vatAmounts[tax1] - amount; printStornoItems(); @@ -626,7 +630,7 @@ public void printCharge(long amount, int tax1, String text) item.setTax3(PrinterConst.SMFPTR_TAX_NOTAX); item.setTax4(PrinterConst.SMFPTR_TAX_NOTAX); item.setText(text); - getPrinter().getPrinter().printCharge(item); + getPrinter().printCharge(item); getReceipt().printCharge(item); vatAmounts[tax1] = vatAmounts[tax1] + amount; printStornoItems(); diff --git a/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java b/Source/FiscalPrinterService/src/com/shtrih/util/ServiceVersion.java index cd0ba89b..a7ddc58f 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 = "698"; + public static final String VERSION = "699"; } \ No newline at end of file diff --git a/Source/FiscalPrinterService/test/com/shtrih/fiscalprinter/command/TextGeneratorTest.java b/Source/FiscalPrinterService/test/com/shtrih/fiscalprinter/command/TextGeneratorTest.java new file mode 100644 index 00000000..cb88c4e5 --- /dev/null +++ b/Source/FiscalPrinterService/test/com/shtrih/fiscalprinter/command/TextGeneratorTest.java @@ -0,0 +1,43 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.shtrih.fiscalprinter.command; + +import java.util.List; +import org.junit.Test; +import static org.junit.Assert.*; + +import com.shtrih.fiscalprinter.SMFiscalPrinter; +import com.shtrih.fiscalprinter.SMFiscalPrinterNull; +import com.shtrih.jpos.fiscalprinter.receipt.FSTLVItem; +import com.shtrih.jpos.fiscalprinter.receipt.FSSalesReceipt; +import com.shtrih.jpos.fiscalprinter.receipt.ReceiptContext; + + +/** + * + * @author Виталий + */ +public class TextGeneratorTest { + + public TextGeneratorTest() { + } + + /** + * Test of visitSalesReceipt method, of class TextGenerator. + */ + @Test + public void testVisitSalesReceipt() { + System.out.println("visitSalesReceipt"); + /* + ReceiptContext context = new ReceiptContext(); + FSSalesReceipt receipt = new FSSalesReceipt(context, PrinterConst.SMFP_RECTYPE_SALE); + SMFiscalPrinter printer = new SMFiscalPrinterNull(null, null, null); + TextGenerator instance = new TextGenerator(printer); + instance.visitSalesReceipt(receipt); + */ + } + +} diff --git a/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceiptTest.java b/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceiptTest.java index e7f21722..dad6a8af 100644 --- a/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceiptTest.java +++ b/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/FSSalesReceiptTest.java @@ -43,14 +43,11 @@ private FSSalesReceipt createReceipt() throws Exception PrinterPort port = PrinterPortFactory.createInstance(params); PrinterProtocol device = ProtocolFactory.getProtocol(params, port); SMFiscalPrinter printer = new SMFiscalPrinterNull(port, device, params); - ReceiptPrinter receiptPrinter = new ReceiptPrinterImpl(printer, params); FiscalDay fiscalDay = new FiscalDay(); - PrinterReceipt printerReceipt = new PrinterReceipt(); FiscalPrinterState printerState = new FiscalPrinterState(); FiscalPrinterImpl impl = new FiscalPrinterImpl(); ReceiptContext context = new ReceiptContext( - receiptPrinter, params, fiscalDay, - printerReceipt, printerState, impl); + printer, params, fiscalDay, printerState, impl); return new FSSalesReceipt(context, PrinterConst.SMFP_RECTYPE_SALE); } diff --git a/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/MockReceiptPrinter.java b/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/MockReceiptPrinter.java deleted file mode 100644 index 38b9971a..00000000 --- a/Source/FiscalPrinterService/test/com/shtrih/jpos/fiscalprinter/receipt/MockReceiptPrinter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.shtrih.jpos.fiscalprinter.receipt; - -/** - * - * @author V.Kravtsov - */ -import com.shtrih.fiscalprinter.FontNumber; -import com.shtrih.fiscalprinter.SMFiscalPrinter; - -public class MockReceiptPrinter implements ReceiptPrinter { - - public void waitForPrinting() - throws Exception { - } - - public void printPreLine() - throws Exception { - } - - public void printPostLine() - throws Exception { - } - - public SMFiscalPrinter getPrinter(){ - return null; - } - - public void openReceipt(int receiptType) - throws Exception { - } - - public String printDescription(String description) - throws Exception { - return ""; - } - - public void printText(String line) - throws Exception { - } - - public void printText(int station, String text, FontNumber font) - throws Exception { - } - - public void printStrings(String line1, String line2) - throws Exception { - } - - public void printSeparator(int separatorType, int height) - throws Exception { - } - - public int getTextLength() - throws Exception { - return 0; - } - - public int getStation(int station) - throws Exception { - return 0; - } - - @Override - public void checkZeroReceipt() throws Exception { - - } - - public long getSubtotal() - throws Exception { - return 0; - } - -}