Skip to content

Commit

Permalink
[-] Fixed error with header and trailer print
Browse files Browse the repository at this point in the history
[-] Fixed error with discount in receipt template
  • Loading branch information
Vitaly Kravtsov committed May 13, 2022
1 parent 6d6f416 commit af728e7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 38 deletions.
2 changes: 2 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

[+] Added parameter autoPrintZReport to jpos.xml to automatically print
Z report in beginFiscalReceipt method
[-] Fixed error with header and trailer print
[-] Fixed error with discount in receipt template

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

Expand Down
30 changes: 10 additions & 20 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ enum Boolean {
private volatile boolean interrupted = false;
private Integer fdVersion = null;
private boolean capLastErrorText = true;
private int[] taxRates = null;
private FDOParameters fdoParameters = null;
public boolean isTableTextCleared = false;
private final Map<Integer, Integer> taxRates = new HashMap<Integer, Integer>();

public SMFiscalPrinterImpl(PrinterPort port, PrinterProtocol device,
FptrParameters params) {
Expand Down Expand Up @@ -352,22 +352,6 @@ private void beforeCommand(PrinterCommand command) throws Exception {
}
}

private void readTaxRates() throws Exception
{
if (taxRates != null){
return;
}

ReadTableInfo command = readTableInfo(PrinterConst.SMFP_TABLE_TAX);
if (command.isSucceeded()) {
int rowCount = command.getRowCount();
taxRates = new int[rowCount + 1];
for (int i = 1; i <= rowCount; i++) {
taxRates[i] = Integer.parseInt(readTable2(PrinterConst.SMFP_TABLE_TAX, i, 1));
}
}
}

private void afterCommand(PrinterCommand command) throws Exception {
for (IPrinterEvents printerEvents : events) {
try {
Expand Down Expand Up @@ -3717,13 +3701,19 @@ public String getTaxName(int number) throws Exception {
return readTable2(PrinterConst.SMFP_TABLE_TAX, number, 2);
}

public int getTaxRate(int number) throws Exception {
return taxRates[number];
public int getTaxRate(int number) throws Exception
{
Integer taxRate = taxRates.get(number);
if (taxRate == null)
{
taxRate = Integer.parseInt(readTable2(PrinterConst.SMFP_TABLE_TAX, number, 1));
taxRates.put(number, taxRate);
}
return taxRate;
}

public long getTaxAmount(int tax, long amount) throws Exception
{
readTaxRates();
double taxRate = getTaxRate(tax) / 10000.0;
return Math.round(amount * taxRate / (1 + taxRate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ public DriverHeader(SMFiscalPrinter printer) throws Exception {
this.printer = printer;

int numHeaderLines = printer.getParams().numHeaderLines;
if (numHeaderLines < printer.getNumHeaderLines()){
numHeaderLines = printer.getNumHeaderLines();
}
header = new ReceiptLines(numHeaderLines);

int numTrailerLines = printer.getParams().numTrailerLines;
if (numTrailerLines < printer.getNumTrailerLines()){
numTrailerLines = printer.getNumTrailerLines();
}
trailer = new ReceiptLines(numTrailerLines);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public String getPostLine() {
/**
* @return the discounts
*/
public FSDiscounts getDiscounts() {
private FSDiscounts getDiscounts() {
return discounts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public void printFSSaleNoTemplate(FSSaleReceiptItem item) throws Exception {
printReceiptItem(item);
printOperationTLV(item);

long discountTotal = item.getDiscounts().getTotal();
long discountTotal = item.getDiscount();
if (discountTotal != 0) {
String text = "=" + StringUtils.amountToString(discountTotal);
getDevice().printLines("СКИДКА", text);
Expand Down Expand Up @@ -1432,13 +1432,11 @@ public void applyDiscounts() throws Exception {
public void applyItemDiscounts(FSSaleReceiptItem item, Vector fpItems)
throws Exception
{
long discount = item.getDiscounts().getTotal();
long discount = item.getDiscount();
long total = item.getTotal() - discount;
long price = item.getPrice();
double quantity = item.getQuantity();

item.getDiscounts().clear();

if (discount == 0) {
fpItems.add(item);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.shtrih.util;

public class ServiceVersion {
public static final String VERSION = "651-1-gb844f91";
public static final String VERSION = "651-2-g6d6f416";
}
8 changes: 3 additions & 5 deletions Source/FiscalPrinterTest/Res/jpos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<!-- 0 - command 10h, short status request -->
<!-- 1 - command 11h, long status request -->
<!-- 2 - status command selected by driver -->
<prop name="statusCommand" type="String" value="2"/>
<prop name="statusCommand" type="String" value="1"/>
<!-- Localization file name -->
<prop name="messagesFileName" type="String" value="shtrihjavapos_ru.properties"/>
<!-- Wrap text enabled -->
Expand Down Expand Up @@ -255,13 +255,11 @@
<prop name="textReportEmptyLinesEnabled" type="String" value="0"/>
<!-- Receipt template -->
<prop name="FSCombineItemAdjustments" type="String" value="0"/>
<prop name="ReceiptTemplateEnabled" type="String" value="0"/>
<prop name="ReceiptTemplateEnabled" type="String" value="1"/>
<prop name="FieldSeparator" type="String" value=":"/>
<prop name="ItemTableHeader" type="String" value="-------------------HEADER-----------------"/>
<prop name="ItemTableTrailer" type="String" value="-------------------TRAILER----------------"/>
<prop name="ItemRowFormat" type="String" value="%3lFIELD0%%36lTITLE%%3FIELD1%%22SUM% X %5lQUAN%%=$10TOTAL_TAX%:
%TAG_NAME2108% %TAG_VALUE2108%:
%TAG_NAME2115% %TAG_VALUE2115%"/>
<prop name="ItemRowFormat" type="String" value="%TAG_VALUE2115%%38lTITLE% %8SUBJECT_TYPE%:%7lTAX_NAME% %8PRICE% %8DISCOUNT% %8SUM%*%6lQUAN%%2lTAG_VALUE2108%%8TOTAL%:%5TAG_VALUE1222%:%TAG_VALUE1225%:%TAG_NAME1226% %TAG_VALUE1226%:%TAG_NAME1171% %TAG_VALUE1171%"/>
<!-- <prop name="DiscountFormat" type="String" value=" СКИДКА %29lTITLE%%=$10TOTAL%"/> -->
<prop name="DiscountFormat" type="String" value=""/>
<!-- <prop name="ChargeFormat" type="String" value=" НАДБАВКА %29lTITLE%%=$10TOTAL%"/> -->
Expand Down
1 change: 1 addition & 0 deletions Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ public void printFiscalReceipt() {
//printReceiptWithError5();

printReceiptWithError9();
//printFiscalReceipt666();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit af728e7

Please sign in to comment.