Skip to content

Commit

Permalink
[-] Fixed error with receipt item discount
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Kravtsov committed Apr 21, 2022
1 parent 1a6f164 commit 1637a3c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
1 change: 1 addition & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
deviceServiceVersion = 1013648

[-] Fixed error header printing
[-] Fixed error with receipt item discount
[-] Fixed extended error code 299 to JPOS_E_TIMEOUT

********************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public long getTotal() {

public void addDiscount(AmountItem discount) {
getDiscounts().add(discount);
updatePrice();
}

/**
Expand Down Expand Up @@ -291,7 +290,7 @@ public long calcPriceWithDiscount() {
return price1;
}

public void updatePrice() {
public void applyDiscounts() {
priceWithDiscount = price;
if (discounts.getTotal() != 0) {
if (quantity == 1.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class FSSalesReceipt extends CustomReceipt implements FiscalReceipt {
private static CompositeLogger logger = CompositeLogger.getLogger(FSSalesReceipt.class);
private List<byte[]> itemCodes = new Vector<byte[]>();
private Vector itemTags = new Vector();
private boolean itemDiscountsApplied = false;

public FSSalesReceipt(ReceiptContext context, int receiptType) throws Exception {
super(context);
Expand Down Expand Up @@ -94,7 +95,7 @@ private void clearReceipt() throws Exception {
voidDescription = "";
messages.clear();
cancelled = false;

itemDiscountsApplied = false;
getParams().itemTaxAmount = null;
getParams().itemTotalAmount = null;
}
Expand Down Expand Up @@ -452,12 +453,11 @@ public void endFiscalReceipt(boolean printHeader) throws Exception {
items.add(discounts.get(i));
}
} else {
if (discounts.getTotal() >= 100)
{
if (discounts.getTotal() >= 100) {
addItemsDiscounts();
}
}

updateItemPositions();
if (getParams().writeTagMode == SmFptrConst.WRITE_TAG_MODE_BEFORE_ITEMS) {
printTLVItems();
Expand Down Expand Up @@ -507,13 +507,13 @@ public void endFiscalReceipt(boolean printHeader) throws Exception {
int taxNumber = (int) getParams().taxAmount[0];
if (getParams().taxCalculation == SmFptrConst.TAX_CALCULATION_DRIVER) {
for (int i = 0; i < 6; i++) {
getParams().taxAmount[i] = calculateTaxAmount(i, taxNumber, (int)discounts.getTotal());
getParams().taxAmount[i] = calculateTaxAmount(i, taxNumber, (int) discounts.getTotal());
}
}
for (int i = 0; i < 6; i++) {
closeReceipt.setTaxValue(i, getParams().taxAmount[i]);
}
closeReceipt.setDiscount((int)discounts.getTotal());
closeReceipt.setDiscount((int) discounts.getTotal());
closeReceipt.setTaxSystem(getParams().taxSystem);
closeReceipt.setText(getParams().closeReceiptText);

Expand All @@ -528,7 +528,7 @@ public void endFiscalReceipt(boolean printHeader) throws Exception {
closeParams.setTax2(0);
closeParams.setTax3(0);
closeParams.setTax4(0);
closeParams.setDiscount((int)discounts.getTotal());
closeParams.setDiscount((int) discounts.getTotal());
closeParams.setText(getParams().closeReceiptText);

EndFiscalReceipt command = new EndFiscalReceipt();
Expand Down Expand Up @@ -794,6 +794,7 @@ private void addTextItem(String text) throws Exception {

public void printRecTotal(long total, long payment, long payType,
String description) throws Exception {
applyItemDiscounts();
checkTotal(getSubtotal(), total);
addPayment(payment, payType);
clearPrePostLine();
Expand Down Expand Up @@ -1083,7 +1084,7 @@ private double correctQuantity(long price, double quantity, long unitPrice) {
}
return quantity;
}

public void printStorno(long price, double quantity, long unitPrice,
int department, int vatInfo, String description) throws Exception {
if (unitPrice == 0) {
Expand Down Expand Up @@ -1198,7 +1199,6 @@ public void doPrintSale(long price, double quantity, long unitPrice,
getDevice().checkItemCode(request);
}
}
item.updatePrice();
items.add(item);

getParams().paymentType = 4;
Expand Down Expand Up @@ -1235,11 +1235,11 @@ public void printItemDiscount(long amount, int tax1, String text)
throws Exception {
logger.debug("printDiscount: " + amount);

if ((amount + discounts.getTotal()) < 100){
if ((amount + discounts.getTotal()) < 100) {
printTotalDiscount(amount, tax1, text);
return;
}

AmountItem item = new AmountItem();
item.setAmount(amount);
item.setTax1(tax1);
Expand Down Expand Up @@ -1407,4 +1407,26 @@ public void setItemBarcode(String barcode) throws Exception {
public void addItemCode(byte[] mcdata) throws Exception {
itemCodes.add(mcdata);
}

public void applyItemDiscounts() throws Exception
{
if (itemDiscountsApplied) return;

for (int i = 0; i < items.size(); i++) {
Object recItem = items.get(i);
if (recItem instanceof FSSaleReceiptItem) {
FSSaleReceiptItem item = (FSSaleReceiptItem) recItem;
item.applyDiscounts();
long amount = Math.round(item.getPriceWithDiscount() * item.getQuantity());
long discountAmount = amount - item.getTotal();
if (discountAmount > 0)
{
printTotalDiscount(discountAmount, 0, "");
item.setAmount(amount);
item.getDiscounts().clear();
}
}
}
itemDiscountsApplied = true;
}
}
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 = "647-3-gb8f370f";
public static final String VERSION = "647-4-g1a6f164";
}
4 changes: 2 additions & 2 deletions Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4843,8 +4843,8 @@ public void printReceiptWithError3() {
printer.setFiscalReceiptType(4);
printer.beginFiscalReceipt(true);
printer.printRecItem("ДвД МолокоУльтрап 3.2%950г БЗ для Капуч", 387092, 4000, 2, 96773, "УПК");
printer.printRecItemAdjustment(1, "Discount", 102, 2);
printer.printRecTotal(386990, 386990, "0");
printer.printRecItemAdjustment(1, "Discount", 2, 2);
printer.printRecTotal(387090, 387090, "0");
printer.endFiscalReceipt(false);
} catch (Exception e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion Source/kktnetd/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_202-b08 (Oracle Corporation)
Bundle-Name: kktnetd
Bundle-Version: 1.0.1
Bundle-Date: 2022-04-21 14:11:20 MSK
Bundle-Date: 2022-04-21 16:08:10 MSK
Implementation-Title: kktnetd
Implementation-Version: 1.0.1
Implementation-URL: http://www.shtrih-m.com
Expand Down

0 comments on commit 1637a3c

Please sign in to comment.