Skip to content

Commit

Permalink
[-] Fixed error with printing nonfiscal receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kravtsov Vitaly committed Oct 26, 2023
1 parent 00ca0fe commit da24468
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 281 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090
Url : https://github.com/shtrih-m/javapos_shtrih

********************************************************************************

26.10.2023
deviceServiceVersion = 1013704

[-] Fixed error with printing nonfiscal receipts

********************************************************************************

13.10.2023
Expand Down
11 changes: 10 additions & 1 deletion Source/Core/src/com/shtrih/fiscalprinter/PrinterProtocol_2.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ public void setByteTimeout(int value) {

public void connect() throws Exception
{
synchronizeFrames(byteTimeout);
for (int i=0;i<10;i++) {
try {
//synchronizeFrames(byteTimeout);
synchronizeFrames(100);
break;
}
catch(Exception e){
logger.error("Failed to connect", e);
}
}
}

public void disconnect(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package com.shtrih.fiscalprinter.command;

import com.shtrih.jpos.fiscalprinter.ReceiptLines;
import com.shtrih.jpos.fiscalprinter.FiscalPrinterImpl;
import com.shtrih.jpos.fiscalprinter.receipt.ReceiptVisitor;
import com.shtrih.barcode.PrinterBarcode;
import com.shtrih.fiscalprinter.FontNumber;
Expand Down Expand Up @@ -76,6 +78,7 @@ public void visitCashInReceipt(Object element) throws Exception{
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
printReceiptTrailer();
}

public void visitCashOutReceipt(Object element) throws Exception{
Expand All @@ -90,6 +93,7 @@ public void visitCashOutReceipt(Object element) throws Exception{
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
printReceiptTrailer();
}

public void visitNonfiscalReceipt(Object element) throws Exception{
Expand All @@ -103,6 +107,7 @@ public void visitNonfiscalReceipt(Object element) throws Exception{
for (int i = 0; i < receipt.items.size(); i++) {
process((Object) receipt.items.get(i));
}
printReceiptTrailer();
}

public void visitSalesReceipt(Object element) throws Exception {
Expand Down Expand Up @@ -137,7 +142,7 @@ public void visitSalesReceipt(Object element) throws Exception {
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}

printReceiptTrailer();
}

public void addFiscalSign() {
Expand Down Expand Up @@ -177,7 +182,13 @@ private String getOperatorName() throws Exception {
return operatorName;
}

private void printReceiptHeader() throws Exception {
private void printReceiptHeader() throws Exception
{
ReceiptLines lines = printer.getParams().getHeader();
for (int i=1;i<=lines.getCount();i++){
add(lines.getLine(i).getText());
}

LongPrinterStatus status = printer.readLongStatus();
int documentNumber = status.getDocumentNumber() + 1;
// ККМ
Expand All @@ -192,6 +203,13 @@ private void printReceiptHeader() throws Exception {
add(s, getOperatorName());
}

private void printReceiptTrailer()throws Exception {
ReceiptLines lines = printer.getParams().getTrailer();
for (int i=1;i<=lines.getCount();i++){
add(lines.getLine(i).getText());
}
}

private void process(Object item) throws Exception {
try {
if (item instanceof FSSaleReceiptItem) {
Expand Down
52 changes: 3 additions & 49 deletions Source/Core/src/com/shtrih/jpos/fiscalprinter/DeviceHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,24 @@
public class DeviceHeader implements PrinterHeader {

private final SMFiscalPrinter printer;
private final ReceiptLines header;
private final ReceiptLines trailer;
private final CompositeLogger logger = CompositeLogger.getLogger(DeviceHeader.class);

public DeviceHeader(SMFiscalPrinter printer) throws Exception {
this.printer = printer;
header = new ReceiptLines(printer.getNumHeaderLines());
trailer = new ReceiptLines(printer.getNumTrailerLines());
}

@Override
public int getNumHeaderLines() throws Exception {
return printer.getNumHeaderLines();
}

@Override
public int getNumTrailerLines() throws Exception {
return printer.getNumTrailerLines();
}

// numHeaderLines for device cannot be changed
@Override
public void setNumHeaderLines(int numHeaderLines) throws Exception {
}

// numTrailerLines for device cannot be changed
@Override
public void setNumTrailerLines(int numTrailerLines) throws Exception {
}

@Override
public void initDevice() throws Exception {
logger.debug("initDevice");

header.setCount(printer.getNumHeaderLines());
trailer.setCount(printer.getNumTrailerLines());
printer.getParams().setNumHeaderLines(printer.getNumHeaderLines());
printer.getParams().setNumTrailerLines(printer.getNumTrailerLines());
printer.updateTableText();
}

@Override
public ReceiptLine getHeaderLine(int number) throws Exception {
return header.getLine(number);
}

@Override
public ReceiptLine getTrailerLine(int number) throws Exception {
return trailer.getLine(number);
}

@Override
public void setHeaderLine(int number, String text, boolean doubleWidth)
throws Exception {
header.setLine(number, text, doubleWidth);

int table = printer.getModel().getHeaderTableNumber();
int row = printer.getHeaderTableRow();
printer.writeTable(table, row + number - 1, 1, text);
Expand All @@ -78,8 +42,6 @@ public void setHeaderLine(int number, String text, boolean doubleWidth)
@Override
public void setTrailerLine(int number, String text, boolean doubleWidth)
throws Exception {
trailer.setLine(number, text, doubleWidth);

int table = printer.getModel().getTrailerTableNumber();
int row = printer.getModel().getTrailerTableRow();
printer.writeTable(table, row + number - 1, 1, text);
Expand All @@ -104,7 +66,7 @@ void printTrailer(String additionalTrailer) throws Exception {
printer.getParams().getFont());
}
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_AFTER_ADDTRAILER);
if (getNumTrailerLines() >= 0) {
if (printer.getParams().getNumTrailerLines() >= 0) {
printRecLine(" ");
printRecLine(" ");
}
Expand Down Expand Up @@ -137,12 +99,4 @@ public void endFiscal(String additionalTrailer)
throws Exception {
}

public ReceiptLines getHeaderLines() {
return header;
}

public ReceiptLines getTrailerLines() {
return trailer;
}

}
72 changes: 18 additions & 54 deletions Source/Core/src/com/shtrih/jpos/fiscalprinter/DriverHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,34 @@
public class DriverHeader implements PrinterHeader {

private int lineNumber = 0;
private final ReceiptLines header;
private final ReceiptLines trailer;
private final SMFiscalPrinter printer;
protected final SMFiscalPrinter printer;
private final CompositeLogger logger = CompositeLogger.getLogger(DriverHeader.class);

/**
* Creates a new instance of PrinterHeader
*/
public DriverHeader(SMFiscalPrinter printer) throws Exception {
this.printer = printer;

int numHeaderLines = printer.getParams().numHeaderLines;
header = new ReceiptLines(numHeaderLines);
int numTrailerLines = printer.getParams().numTrailerLines;
trailer = new ReceiptLines(numTrailerLines);
}

public SMFiscalPrinter getPrinter() {
return printer;
}

@Override
public ReceiptLine getHeaderLine(int number) throws Exception {
return header.getLine(number);
}

@Override
public ReceiptLine getTrailerLine(int number) throws Exception {
return trailer.getLine(number);
}

@Override
public void initDevice() throws Exception {
logger.debug("initDevice");
printer.clearTableText();
}

@Override
public int getNumHeaderLines() throws Exception {
return header.getCount();
}

@Override
public int getNumTrailerLines() {
return trailer.getCount();
}

@Override
public void setNumHeaderLines(int numHeaderLines) throws Exception {
header.setCount(numHeaderLines);
}

@Override
public void setNumTrailerLines(int numTrailerLines) throws Exception {
trailer.setCount(numTrailerLines);
}

@Override
public void setHeaderLine(int number, String text, boolean doubleWidth)
throws Exception {
header.setLine(number, text, doubleWidth);
}

@Override
public void setTrailerLine(int number, String text, boolean doubleWidth)
throws Exception {
trailer.setLine(number, text, doubleWidth);
}

private void printLine(ReceiptLine line) throws Exception {
Expand Down Expand Up @@ -125,7 +86,7 @@ void printTrailer(String additionalTrailer) throws Exception {
printer.getParams().getFont());
}
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_AFTER_ADDTRAILER);
if (getNumTrailerLines() >= 0) {
if (printer.getParams().getNumTrailerLines() >= 0) {
printRecLine(" ");
printRecLine(" ");
}
Expand Down Expand Up @@ -153,14 +114,14 @@ void printHeaderBeforeCutter() throws Exception {
} else {
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_BEFORE_HEADER);
lineNumber = (headerHeight - imageHeight) / lineHeight;
printLines(header, 1, lineNumber);
printLines(getHeader(), 1, lineNumber);
}
printer.waitForPrinting();
}

public void printHeaderNoCutter() throws Exception {
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_BEFORE_HEADER);
printLines(header);
printLines(getHeader());
printer.waitForPrinting();
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_AFTER_HEADER);
printer.waitForPrinting();
Expand All @@ -183,10 +144,10 @@ public void printHeaderAfterCutter() throws Exception {
} else {
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_BEFORE_HEADER);
}
printLines(header);
printLines(getHeader());
} else {
lineNumber = (headerHeight - imageHeight) / lineHeight;
printLines(header, lineNumber + 1, header.getCount());
printLines(getHeader(), lineNumber + 1, getHeader().getCount());
}
printer.printReceiptImage(SmFptrConst.SMFPTR_LOGO_AFTER_HEADER);
printer.waitForPrinting();
Expand Down Expand Up @@ -224,8 +185,8 @@ void printSpaceLines(int count) throws Exception {
}

private void printTrailer() throws Exception {
for (int i = 1; i <= getNumTrailerLines(); i++) {
printLine(getTrailerLine(i));
for (int i = 1; i <= printer.getParams().getNumTrailerLines(); i++) {
printLine(getParams().getTrailerLine(i));
}
}

Expand Down Expand Up @@ -260,13 +221,16 @@ public void beginDocument(String additionalHeader) throws Exception {
logger.debug("beginDocument");
printText(additionalHeader);
}

public ReceiptLines getHeaderLines() {
return header;
public FptrParameters getParams(){
return printer.getParams();
}

public ReceiptLines getTrailerLines() {
return trailer;

public ReceiptLines getHeader(){
return getParams().getHeader();
}

public ReceiptLines getTrailer(){
return getParams().getTrailer();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public DriverHeader2(SMFiscalPrinter printer) throws Exception
public void endFiscal(String additionalTrailer)
throws Exception {
printTrailer(additionalTrailer);
printSpaceLines(getNumHeaderLines());
printSpaceLines(printer.getParams().getNumHeaderLines());
getPrinter().cutPaper();
}

Expand Down
Loading

0 comments on commit da24468

Please sign in to comment.