Skip to content

Commit

Permalink
[-] Fixed error with socket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Kravtsov committed Jun 5, 2023
1 parent c646619 commit 2385e2e
Show file tree
Hide file tree
Showing 16 changed files with 1,136 additions and 752 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

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

05.06.2023
deviceServiceVersion = 1013697

[-] Fixed error with socket connection

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

14.04.2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AmountItem {
private int tax2;
private int tax3;
private int tax4;
private String text;
private String text = "";

/** Creates a new instance of AmountItem */
public AmountItem() {
Expand Down
26 changes: 26 additions & 0 deletions Source/Core/src/com/shtrih/fiscalprinter/command/PrinterConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@

public interface PrinterConst {

// ///////////////////////////////////////////////////////////////////
// Duplicate document text

public static final String SFiscalSign = "ФП";
public static final String SSaleText = "ПРОДАЖА";
public static final String SBuyText = "ПОКУПКА";
public static final String SRetSaleText = "ВОЗВРАТ ПРОДАЖИ";
public static final String SRetBuyText = "ВОЗВРАТ ПОКУПКИ";
public static final String SCashInText = "ВНЕСЕНИЕ";
public static final String SCashOutText = "ВЫПЛАТА";
public static final String SStornoText = "СТОРНО";
public static final String STotalText = "ВСЕГО";
public static final String SRoundingText = "ОКРУГЛЕНИЕ";
public static final String SDiscountText = "СКИДКА";
public static final String SChargeText = "НАДБАВКА";
public static final String SReceiptTotal = "ИТОГ";
public static final String SChangeText = "СДАЧА";
public static final String SReceiptCancelled = "ЧЕК АННУЛИРОВАН";
public static final String SDiscountStornoText = "СТОРНО СКИДКИ";
public static final String SChargeStornoText = "СТОРНО НАДБАВКИ";
public static final String SXReportText = "СУТОЧНЫЙ ОТЧЕТ БЕЗ ГАШЕНИЯ";
public static final String SZReportText = "СУТОЧНЫЙ ОТЧЕТ С ГАШЕНИЕМ";
public static final String SDayClosed = "СМЕНА ЗАКРЫТА";
public static final String SINN = "ИНН";
public static final String[] docNames = {SSaleText, SBuyText, SRetSaleText, SRetBuyText};

// ///////////////////////////////////////////////////////////////////
// Print mode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class TextDocumentFilter implements IPrinterEvents {
private XReport report = new XReport();
private final String[] paymentNames = new String[16];
private final List<Operator> operators = new ArrayList<Operator>();
private List<String> docLines = new Vector<String>();
private SKLStorage storage;
private SKLStorage lastDoc;

Expand All @@ -69,6 +68,10 @@ public class TextDocumentFilter implements IPrinterEvents {
private static String SDayClosed = "СМЕНА ЗАКРЫТА";
public static final String SINN = "ИНН";
private static String[] docNames = {SSaleText, SBuyText, SRetSaleText, SRetBuyText};
public boolean receiptEnabled = false;
public boolean isDocumentActive = false;
private final List<String> lines = new ArrayList<String>();


public TextDocumentFilter() {
}
Expand All @@ -78,7 +81,6 @@ public void init(SMFiscalPrinter printer) throws Exception
this.printer = printer;
saveToStorage = printer.getParams().textReportEnabled;
lineLength = printer.getMessageLength(FontNumber.getNormalFont());
readLastDoc();
}

public boolean getEnabled() {
Expand Down Expand Up @@ -139,11 +141,15 @@ public void afterCommand(PrinterCommand command) throws Exception {
switch (command.getCode())
{
case 0x17:
add(((PrintString) command).getLine());
if (isDocumentActive){
add(((PrintString) command).getLine());
}
break;

case 0x2F:
if (isDocumentActive){
add(((PrintStringFont) command).getLine());
}
break;

case 0x40:
Expand Down Expand Up @@ -226,15 +232,6 @@ public void afterCommand(PrinterCommand command) throws Exception {

private void openReceipt(OpenReceipt command) throws Exception {
openReceipt2(command.getReceiptType());
clearLastDoc();
}

private void clearLastDoc() {
docLines.clear();
File file = new File(getLastDocFilePath());
if (!file.delete()){
logger.error("Failed to delete file, " + getLastDocFilePath());
}
}

private void openReceipt2(int receiptType) throws Exception {
Expand Down Expand Up @@ -396,34 +393,40 @@ private String getPaymentName(int paymentIndex) throws Exception
}

private void printSale(PrintSale command) throws Exception {
if (!receiptEnabled) return;
operatorNumber = command.getOperator();
openReceipt2(PrinterConst.SMFP_RECTYPE_SALE);
printReceiptItem(command.getItem());
}

private void printSale(FSPrintRecItem command) throws Exception {
if (!receiptEnabled) return;
printReceiptItem(command.getItem());
}

private void printRefund(PrintRefund command) throws Exception {
if (!receiptEnabled) return;
operatorNumber = command.getOperator();
openReceipt2(PrinterConst.SMFP_RECTYPE_BUY);
printReceiptItem(command.getItem());
}

private void printVoidSale(PrintVoidSale command) throws Exception {
if (!receiptEnabled) return;
operatorNumber = command.getOperator();
openReceipt2(PrinterConst.SMFP_RECTYPE_RETSALE);
printReceiptItem(command.getItem());
}

private void printVoidRefund(PrintVoidRefund command) throws Exception {
if (!receiptEnabled) return;
operatorNumber = command.getOperator();
openReceipt2(PrinterConst.SMFP_RECTYPE_RETBUY);
printReceiptItem(command.getItem());
}

private void printVoidItem(PrintVoidItem command) throws Exception {
if (!receiptEnabled) return;
operatorNumber = command.getOperator();
PriceItem item = command.getItem();
// Line 1
Expand Down Expand Up @@ -628,7 +631,6 @@ public void connect() throws Exception {
}

public XReport readXReport() throws Exception {
clearLastDoc();
XReport report = new XReport();
FMTotals totals = printer.readFPTotals(1);
report.salesAmountBefore = totals.getSalesAmount();
Expand Down Expand Up @@ -669,7 +671,6 @@ public XReport readXReport() throws Exception {
}

public void printCashIn(PrintCashIn command) throws Exception {
clearLastDoc();
isDocumentPrinted = true;
operatorNumber = command.getOperator();
long docNumber = printer.readCashRegister(155);
Expand All @@ -682,7 +683,6 @@ public void printCashIn(PrintCashIn command) throws Exception {
}

public void printCashOut(PrintCashOut command) throws Exception {
clearLastDoc();
isDocumentPrinted = true;
operatorNumber = command.getOperator();
long docNumber = printer.readCashRegister(156);
Expand All @@ -704,9 +704,12 @@ public void add(String text, long value) throws Exception {

private void beginDocument() throws Exception {
printReceiptHeader();
isDocumentActive = true;
lines.clear();
}

private void endDocument() throws Exception {
isDocumentActive = false;
}

private void printReceiptHeader() throws Exception {
Expand Down Expand Up @@ -968,10 +971,6 @@ public void add(String line) throws Exception
}
}

public List<String> getDocLines() {
return docLines;
}

private SKLStorage getStorage() throws Exception {
if (storage == null) {
String filePath = SysUtils.getFilesPath() + printer.getParams().textReportFileName;
Expand All @@ -980,44 +979,13 @@ private SKLStorage getStorage() throws Exception {
return storage;
}

public static String getLastDocFilePath() {
return SysUtils.getFilesPath() + "document.txt";
public List<String> getLines(){
return lines;
}

private void readLastDoc() {
try
{
docLines.clear();
File file = new File(getLastDocFilePath());
if (!file.exists()) {
logger.debug("Last document not found");
return;
}

BufferedReader reader = new BufferedReader(new FileReader(file));
try {
String line;
while ((line = reader.readLine()) != null) {
docLines.add(line);
}
} finally {
reader.close();
}
} catch (Exception e) {
logger.error("Failed to read last document, ", e);
}
}

private SKLStorage getLastDoc() throws Exception {
if (lastDoc == null) {
lastDoc = new FileSKLStorage(getLastDocFilePath());
}
return lastDoc;
}

private void writeLn(String line) throws Exception {
docLines.add(line);
getLastDoc().writeLine(line);

private void writeLn(String line) throws Exception
{
lines.add(line);
if (saveToStorage) {
getStorage().writeLine(line);
}
Expand Down
Loading

0 comments on commit 2385e2e

Please sign in to comment.