Skip to content

Commit

Permalink
[-] Fixed errors with receipt duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalyKravtsov2016 committed Aug 16, 2023
1 parent dc1a9a7 commit 2cdac14
Show file tree
Hide file tree
Showing 22 changed files with 996 additions and 883 deletions.
2 changes: 1 addition & 1 deletion History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

11.07.2023
16.08.2023
deviceServiceVersion = 1013700

[-] Fixed errors with receipt duplicate
Expand Down
36 changes: 25 additions & 11 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SMFiscalPrinterNull implements SMFiscalPrinter {
private final PrinterPort port;
private final FptrParameters params;
private final PrinterImages printerImages = new PrinterImages();
public final PrinterTables tables = new PrinterTables();
private int resultCode = 0;

public SMFiscalPrinterNull(
Expand Down Expand Up @@ -76,7 +77,14 @@ public SMFiscalPrinterNull(
printerStatus.setSubmode(submode);
shortStatus.setSubmode(submode);
longStatus.setSubmode(submode);


deviceMetrics.setDeviceType(1);
deviceMetrics.setDeviceSubType(2);
deviceMetrics.setProtocolVersion(3);
deviceMetrics.setProtocolSubVersion(4);
deviceMetrics.setModel(5);
deviceMetrics.setLanguage(0);
deviceMetrics.setDeviceName("DeviceName");
}

public boolean getCapFiscalStorage() {
Expand Down Expand Up @@ -245,16 +253,22 @@ public int writeTable(int tableNumber, int rowNumber, int fieldNumber,
}

public int readTable(int tableNumber, int rowNumber, int fieldNumber,
String[] fieldValue) throws Exception {
return 0;
}

public int readTableInfo(int tableNumber, Object[] out) throws Exception {
return 0;
}

public ReadTableInfo readTableInfo(int tableNumber) throws Exception {
return new ReadTableInfo();
String[] fieldValue) throws Exception
{
PrinterTable table = tables.find(tableNumber);
if (table == null) return 0x33;
PrinterField field = table.getFields().find(tableNumber, rowNumber, fieldNumber);
if (field == null) return 0x33;
fieldValue[0] = field.getValue();
return 0;
}

public ReadTableInfo readTableInfo(int tableNumber) throws Exception
{
PrinterTable table = tables.find(tableNumber);
ReadTableInfo result = new ReadTableInfo();
result.setTable(table);
return result;
}

public PrintCashIn printCashIn(long sum) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class LongPrinterStatus implements PrinterConst {
private String fmFirmwareVersion = "";
private int fmFirmwareBuild = 0;
private PrinterDate fmFirmwareDate = new PrinterDate();
private PrinterDate date = new PrinterDate();
private PrinterTime time = new PrinterTime();
private PrinterDate date = new PrinterDate(1, 2, 3);
private PrinterTime time = new PrinterTime(1, 2, 3);
private int fmFlags = 0;
private int serialNumber = 0;
private int dayNumber = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public PrinterTable getTable() {
return table;
}

public void setTable(PrinterTable table) {
this.table = table;
}

public boolean getIsRepeatable() {
return true;
}
Expand Down
104 changes: 64 additions & 40 deletions Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,59 +55,76 @@ public class TextGenerator implements ReceiptVisitor {
private List<String> lines = new Vector<String>();
private static CompositeLogger logger = CompositeLogger.getLogger(TextGenerator.class);

public TextGenerator(SMFiscalPrinter printer) throws Exception {
public TextGenerator(SMFiscalPrinter printer) {
this.printer = printer;
}

public void visitCustomReceipt(Object element) {
public void visitCustomReceipt(Object element) throws Exception {
}

public void visitSalesReceipt(Object element) {
public void visitCashInReceipt(Object element) throws Exception{
if (!(element instanceof CashInReceipt)) {
return;
}
CashInReceipt receipt = (CashInReceipt) element;

printReceiptHeader();
add(PrinterConst.SCashInText, amountToStr(receipt.getSubtotal()));
// Change
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
}

public void visitCashOutReceipt(Object element) throws Exception{
if (!(element instanceof CashOutReceipt)) {
return;
}
CashOutReceipt receipt = (CashOutReceipt) element;

printReceiptHeader();
add(PrinterConst.SCashOutText, amountToStr(receipt.getSubtotal()));
// Change
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
}

public void visitSalesReceipt(Object element) throws Exception {
if (!(element instanceof FSSalesReceipt)) {
return;
}
FSSalesReceipt receipt = (FSSalesReceipt) element;
try {
connect();
operatorNumber = printer.getOperatorNumber();
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) {
add(PrinterConst.STotalText, summToStr(receipt.getSubtotal()));
/*
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]));
}
lines.clear();
printReceiptHeader();
for (int i = 0; i < receipt.items.size(); i++) {
process((Object) receipt.items.get(i));
}
if (receipt.getDiscountsTotal() > 0) {
add(PrinterConst.STotalText, summToStr(receipt.getSubtotal()));
if (receipt.isRounded()) {
add(PrinterConst.SRoundingText, summToStr(receipt.getDiscountsTotal()));
}
// Change
if (receipt.getChange() > 0)
{
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
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]));
}

} catch (Exception e) {
logger.error("Failed duplicate receipt", e);
}
// Change
if (receipt.getChange() > 0) {
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}

}


public void addFiscalSign() {
try {
printer.waitForPrinting();
Expand Down Expand Up @@ -228,11 +245,11 @@ private void process(FSSaleReceiptItem item) throws Exception {
add(item.getText());

line = String.format("%s X %s",
quantityToStr(item.getQuantity() / 1000000.0),
quantityToStr(item.getQuantity()),
amountToStr(item.getPrice()));
add("", line);

line = summToStr(item.getPrice(), item.getQuantity() / 1000000.0)
line = summToStr(item.getPrice(), item.getQuantity())
+ getTaxData(item.getTax1(), 0, 0, 0);
add(String.format("%02d", item.getDepartment()), line);

Expand Down Expand Up @@ -298,6 +315,13 @@ private int getLineLength() throws Exception {
}

private void add(String s1, String s2) throws Exception {
if (s1 == null) {
return;
}
if (s2 == null) {
return;
}

int len = getLineLength() - s1.length() - s2.length();
String line = s1 + StringUtils.stringOfChar(' ', len) + s2;
add(line);
Expand Down
10 changes: 8 additions & 2 deletions Source/Core/src/com/shtrih/fiscalprinter/table/PrinterField.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public PrinterField(FieldInfo fieldInfo, int row) {
this.row = row;
}

public PrinterField(FieldInfo fieldInfo, int row, String value) {
this.fieldInfo = fieldInfo;
this.row = row;
this.value = value;
}

public PrinterField getCopy() throws Exception {
PrinterField res = new PrinterField(getFieldInfo(), getRow());
res.setValue(value);
Expand Down Expand Up @@ -70,8 +76,8 @@ public void checkValue(String value) throws Exception {

}

public void setValue(String value) throws Exception {
checkValue(value);
public void setValue(String value) {
//checkValue(value);
this.value = value;
}

Expand Down
Loading

0 comments on commit 2cdac14

Please sign in to comment.