Skip to content

Commit

Permalink
[+] Added correction receipt support and sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Kravtsov committed Nov 3, 2021
1 parent f791ca1 commit 87aee65
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 37 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

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

03.11.2021
deviceServiceVersion = 1013636

[+] Added correction receipt support and sample

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

28.10.2021
Expand Down
51 changes: 32 additions & 19 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void correctDate() {
}
}
} catch (Exception e) {
logger.error("Correct date failed: " + e.getMessage());
logger.error("Correct date failed "+ e.getMessage());
}
}

Expand Down Expand Up @@ -313,7 +313,7 @@ private void beforeCommand(PrinterCommand command) throws Exception {
try {
printerEvents.beforeCommand(command);
} catch (Exception e) {
logger.error(e);
logger.error("beforeCommand "+ e.getMessage());
}
}
}
Expand All @@ -323,7 +323,7 @@ private void afterCommand(PrinterCommand command) throws Exception {
try {
printerEvents.afterCommand(command);
} catch (Exception e) {
logger.error(e);
logger.error("afterCommand " + e.getMessage());
}
}
}
Expand Down Expand Up @@ -1314,7 +1314,7 @@ public void printSale(PriceItem item) throws Exception {
item.setText(text);

if (capFSPrintItem) {
int rc = fsPrintRecItem2(1, item);
int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_SALE, item);
if (isCommandSupported(rc)) {
check(rc);
return;
Expand All @@ -1330,7 +1330,7 @@ public void printVoidSale(PriceItem item) throws Exception {
item.setText(text);

if (capFSPrintItem) {
int rc = fsPrintRecItem2(2, item);
int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_RETSALE, item);
if (isCommandSupported(rc)) {
check(rc);
return;
Expand All @@ -1347,7 +1347,7 @@ public void printRefund(PriceItem item) throws Exception {
item.setText(text);

if (capFSPrintItem) {
int rc = fsPrintRecItem2(3, item);
int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_BUY, item);
if (isCommandSupported(rc)) {
check(rc);
return;
Expand All @@ -1364,7 +1364,7 @@ public void printVoidRefund(PriceItem item) throws Exception {
item.setText(text);

if (capFSPrintItem) {
int rc = fsPrintRecItem2(4, item);
int rc = fsPrintRecItem2(PrinterConst.SMFP_OPERATION_RETBUY, item);
if (isCommandSupported(rc)) {
check(rc);
return;
Expand Down Expand Up @@ -1473,8 +1473,7 @@ public int fsStartDayOpen() throws Exception {
return executeCommand(command);
}

public void resetPrinter() throws Exception
{
public void resetPrinter() throws Exception {
tlvItems.clear();
interrupted = false;
}
Expand Down Expand Up @@ -3157,7 +3156,7 @@ public void updateModels() {
writer.save(SysUtils.getFilesPath() + "models2.xml");

} catch (Exception e) {
logger.error(e.getMessage());
logger.error("updateModels "+ e.getMessage());
}
}

Expand Down Expand Up @@ -3346,10 +3345,10 @@ public FSReadSerial fsReadSerial() throws Exception {
}

@Override
public String getFullSerial(){
public String getFullSerial() {
return fullSerial;
}

@Override
public String readFullSerial() throws Exception {
if (serial.isEmpty()) {
Expand Down Expand Up @@ -3559,7 +3558,7 @@ public void openFiscalDay() throws Exception {
try {
waitForPrinting();
} catch (Exception e) {
logger.error("openFiscalDay wait for printing failed", e);
logger.error("openFiscalDay wait for printing failed"+ e.getMessage());
}
}
}
Expand Down Expand Up @@ -3737,7 +3736,7 @@ public void printItems(List<PrintItem> items) throws Exception {
try {
item.print(this);
} catch (Exception e) {
logger.error(e.getMessage());
logger.error("printItems "+ e.getMessage());
}
}
items.clear();
Expand Down Expand Up @@ -3815,11 +3814,25 @@ public void printReceiptHeader(String docName) throws Exception {
};

public String getReceiptName(int receiptType) {
if (getCapFiscalStorage()) {
return "КАССОВЫЙ ЧЕК/" + fsDocNames[receiptType];
String receiptName = "";
boolean isCorrection = (receiptType & 0xF0) == 0x80;
receiptType = receiptType & 0x0F;

if ((receiptType < 0) || (receiptType > 3)) {
return receiptName;
}

if (getCapFiscalStorage())
{
receiptName = "КАССОВЫЙ ЧЕК";
if (isCorrection){
receiptName = "ЧЕК КОРРЕКЦИИ";
}
receiptName = receiptName + "/" + fsDocNames[receiptType];
} else {
return docNames[receiptType];
receiptName = docNames[receiptType];
}
return receiptName;
}

public FSReadBlock fsReadBlock(int offset, int size) throws Exception {
Expand Down Expand Up @@ -4274,7 +4287,7 @@ public void updateFirmware() throws Exception {
}
logger.debug("updateFirmware(): OK");
} catch (Exception e) {
logger.error("updateFirmware", e);
logger.error("updateFirmware "+ e.getMessage());
}
}

Expand Down Expand Up @@ -4557,7 +4570,7 @@ private boolean connectDevice(String searchPortName, int searchBaudRate) throws
}
return true;
} catch (Exception e) {
logger.error(e);
logger.error("connectDevice "+ e.getMessage());
return false;
}
}
Expand Down
20 changes: 17 additions & 3 deletions Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,29 @@ public interface PrinterConst {

// Sale receipt
public static final int SMFP_RECTYPE_SALE = 0;

// Buy receipt
public static final int SMFP_RECTYPE_BUY = 1;

// Sale return receipt
public static final int SMFP_RECTYPE_RETSALE = 2;

// Buy return receipt
public static final int SMFP_RECTYPE_RETBUY = 3;
// Correction sale receipt
public static final int SMFP_RECTYPE_CORRECTION_SALE = 0x80;
// Correction buy receipt
public static final int SMFP_RECTYPE_CORRECTION_BUY = 0x81;
// Correction sale return receipt
public static final int SMFP_RECTYPE_CORRECTION_RETSALE = 0x82;
// Correction buy return receipt
public static final int SMFP_RECTYPE_CORRECTION_RETBUY = 0x83;

//////////////////////////////////////////////////////////////////////
// Operation types
//////////////////////////////////////////////////////////////////////

public static final int SMFP_OPERATION_SALE = 1;
public static final int SMFP_OPERATION_RETSALE = 2;
public static final int SMFP_OPERATION_BUY = 3;
public static final int SMFP_OPERATION_RETBUY = 4;

// ###################################################################
// #### Fiscal printer error codes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ private void openReceipt2(int receiptType) throws Exception {
isDocumentPrinted = false;
beginDocument();
long recNumber = getNextRecNumber(getRecNumber(receiptType));
add(docNames[receiptType], String.format("№%04d", recNumber));
String docName = printer.getReceiptName(receiptType);
add(docName, String.format("№%04d", recNumber));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4595,6 +4595,21 @@ public FiscalReceipt createReceipt(int fiscalReceiptType) throws Exception {
case SmFptrConst.SMFPTR_RT_RETBUY:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_RETBUY);

case SmFptrConst.SMFPTR_RT_CORRECTION:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_SALE);

case SmFptrConst.SMFPTR_RT_CORRECTION_SALE:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_SALE);

case SmFptrConst.SMFPTR_RT_CORRECTION_BUY:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_BUY);

case SmFptrConst.SMFPTR_RT_CORRECTION_RETSALE:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_RETSALE);

case SmFptrConst.SMFPTR_RT_CORRECTION_RETBUY:
return createSalesReceipt(PrinterConst.SMFP_RECTYPE_CORRECTION_RETBUY);

default:
throw new JposException(JPOS_E_ILLEGAL,
Localizer.getString(Localizer.invalidParameterValue));
Expand Down
16 changes: 11 additions & 5 deletions Source/Core/src/com/shtrih/jpos/fiscalprinter/SmFptrConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,17 @@ private SmFptrConst(){

// ///////////////////////////////////////////////////////////////////
// Receipt type constants
public static final int SMFPTR_RT_SALE = 100;
public static final int SMFPTR_RT_BUY = 101;
public static final int SMFPTR_RT_RETSALE = 102;
public static final int SMFPTR_RT_RETBUY = 103;

public static final int SMFPTR_RT_SALE = 100;
public static final int SMFPTR_RT_BUY = 101;
public static final int SMFPTR_RT_RETSALE = 102;
public static final int SMFPTR_RT_RETBUY = 103;

public static final int SMFPTR_RT_CORRECTION = 104;
public static final int SMFPTR_RT_CORRECTION_SALE = 105;
public static final int SMFPTR_RT_CORRECTION_BUY = 106;
public static final int SMFPTR_RT_CORRECTION_RETSALE = 107;
public static final int SMFPTR_RT_CORRECTION_RETBUY = 108;

// ///////////////////////////////////////////////////////////////////
// KTN types
// КН Код неопределенного идентификатора товара 00h 00h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public FSSalesReceipt(ReceiptContext context, int receiptType) throws Exception
}

public boolean isSaleReceipt() {
return receiptType == PrinterConst.SMFP_RECTYPE_SALE;
return ((receiptType & 0x0F) == PrinterConst.SMFP_RECTYPE_SALE);
}

public void printRecMessage(int station, FontNumber font, String message)
Expand Down Expand Up @@ -114,9 +114,11 @@ public void beginFiscalReceipt(boolean printHeader) throws Exception {

public void openReceipt(boolean isSale) throws Exception {
if (!isOpened) {
if (!isSale) {
if (receiptType == PrinterConst.SMFP_RECTYPE_SALE) {
receiptType = PrinterConst.SMFP_RECTYPE_RETSALE;
if (!isSale)
{
if ((receiptType & 0x0F) == PrinterConst.SMFP_RECTYPE_SALE)
{
receiptType = (receiptType & 0xF0) + PrinterConst.SMFP_RECTYPE_RETSALE;
}
}
getPrinter().openReceipt(receiptType);
Expand Down Expand Up @@ -617,18 +619,22 @@ public void printReceiptItem(FSSaleReceiptItem item) throws Exception {
if (!item.getIsStorno()) {
switch (receiptType) {
case PrinterConst.SMFP_RECTYPE_SALE:
case PrinterConst.SMFP_RECTYPE_CORRECTION_SALE:
getDevice().printSale(priceItem);
break;

case PrinterConst.SMFP_RECTYPE_RETSALE:
case PrinterConst.SMFP_RECTYPE_CORRECTION_RETSALE:
getDevice().printVoidSale(priceItem);
break;

case PrinterConst.SMFP_RECTYPE_BUY:
case PrinterConst.SMFP_RECTYPE_CORRECTION_BUY:
getDevice().printRefund(priceItem);
break;

case PrinterConst.SMFP_RECTYPE_RETBUY:
case PrinterConst.SMFP_RECTYPE_CORRECTION_RETBUY:
getDevice().printVoidRefund(priceItem);
break;
default:
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 = "634";
public static final String VERSION = "635";
}
6 changes: 3 additions & 3 deletions Source/FiscalPrinterTest/Res/jpos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<!-- device state polling interval in milliseconds -->
<prop name="pollInterval" type="String" value="500"/>
<!-- Amount coefficient -->
<prop name="amountFactor" type="String" value="0.01"/>
<prop name="amountFactor" type="String" value="1"/>
<!-- Quantity coefficient -->
<prop name="quantityFactor" type="String" value="1"/>
<!-- Strings encoding -->
Expand Down Expand Up @@ -319,9 +319,9 @@
<prop name="markingType" type="String" value="1"/>

<prop name="quantityCorrectionEnabled" type="String" value="1"/>
<prop name="FSServiceEnabled" type="String" value="1"/>
<prop name="FSServiceEnabled" type="String" value="0"/>
<!-- device state polling enabled -->
<prop name="pollEnabled" type="String" value="1"/>
<prop name="pollEnabled" type="String" value="0"/>
<prop name="fastConnect" type="String" value="0"/>
</JposEntry>

Expand Down
25 changes: 24 additions & 1 deletion Source/FiscalPrinterTest/src/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,11 @@ public void printFiscalReceipt() {
//printer.readFiscalizationTag(1, 0xFFFF);
//printer.readFiscalizationTLV(1);

printSalesReceipt1235();
//printSalesReceipt1235();
//printFiscalReceipt145_4();

printCorrectionReceipts();

} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -4393,4 +4395,25 @@ private void printSalesReceipt1235() {
}
}

public void printCorrectionReceipts() {
try {
int[] recTypes = {
SmFptrConst.SMFPTR_RT_CORRECTION,
SmFptrConst.SMFPTR_RT_CORRECTION_SALE,
SmFptrConst.SMFPTR_RT_CORRECTION_RETSALE,
SmFptrConst.SMFPTR_RT_CORRECTION_BUY,
SmFptrConst.SMFPTR_RT_CORRECTION_RETBUY
};
for (int i = 0; i < recTypes.length; i++) {
printer.resetPrinter();
printer.setFiscalReceiptType(recTypes[i]);
printer.beginFiscalReceipt(false);
printer.printRecItem("", 100, 1000000, 1, 100, "");
printer.printRecTotal(106, 106, "30");
printer.endFiscalReceipt(false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 87aee65

Please sign in to comment.