Skip to content

Commit

Permalink
[-] Fixed errors with receipt duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Kravtsov committed Jul 11, 2023
1 parent 480c857 commit dc1a9a7
Show file tree
Hide file tree
Showing 23 changed files with 460 additions and 651 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

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

11.07.2023
deviceServiceVersion = 1013700

[-] Fixed errors with receipt duplicate

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

14.06.2023
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,7 @@ public ReadOperationRegister readOperationRegister2(int number)
public void writeTLVItems() throws Exception;

public void checkFDOConnection() throws Exception;

public int getOperatorNumber();

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ enum Boolean {
private final Map<Integer, Integer> taxRates = new HashMap<Integer, Integer>();
private int printMode = PrinterConst.PRINT_MODE_ENABLED;
private boolean connected = false;
private int operatorNumber = 1;


public SMFiscalPrinterImpl(PrinterPort port, PrinterProtocol device,
FptrParameters params) {
Expand Down Expand Up @@ -649,6 +651,7 @@ public LongPrinterStatus readLongStatus() throws Exception {
command.setPassword(usrPassword);
execute(command);
longStatus = command.getStatus();
operatorNumber = longStatus.getOperatorNumber();
return command.getStatus();
}

Expand Down Expand Up @@ -694,6 +697,7 @@ public ShortPrinterStatus readShortStatus() throws Exception {
ReadShortStatus command = new ReadShortStatus(usrPassword);
execute(command);
shortStatus = command.getStatus();
operatorNumber = longStatus.getOperatorNumber();

/*
NumberFormat formatter = new DecimalFormat("#0.00");
Expand Down Expand Up @@ -1726,8 +1730,11 @@ public void openReceipt(int receiptType) throws Exception {
command.setPassword(usrPassword);
command.setReceiptType(receiptType);
int rc = executeCommand(command);
if (command.isSucceeded()){
operatorNumber = command.getOperator();
}

capOpenReceipt = isCommandSupported(rc);

if (capOpenReceipt) {
check(rc);
writeTLVItems();
Expand Down Expand Up @@ -5394,5 +5401,9 @@ public String getText(String text) {
}
return text;
}

public int getOperatorNumber(){
return operatorNumber;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1320,4 +1320,8 @@ public void writeTLVItems() throws Exception{

public void checkFDOConnection() throws Exception{
}

public int getOperatorNumber(){
return 1;
}
}
167 changes: 93 additions & 74 deletions Source/Core/src/com/shtrih/fiscalprinter/command/TextGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import com.shtrih.barcode.PrinterBarcode;
import com.shtrih.fiscalprinter.FontNumber;
import com.shtrih.fiscalprinter.SMFiscalPrinter;
import com.shtrih.fiscalprinter.TLVItems;
import com.shtrih.fiscalprinter.TLVReader;
import com.shtrih.fiscalprinter.TLVTextWriter;
import com.shtrih.fiscalprinter.command.PrinterConst;
import static com.shtrih.fiscalprinter.command.PrinterConst.SMFP_STATION_REC;
import static com.shtrih.fiscalprinter.command.TextDocumentFilter.quantityToStr;
import com.shtrih.fiscalprinter.skl.FileSKLStorage;
import com.shtrih.fiscalprinter.skl.SKLStorage;
Expand All @@ -20,6 +24,7 @@
import com.shtrih.jpos.fiscalprinter.receipt.FSSalesReceipt;
import com.shtrih.jpos.fiscalprinter.receipt.FSTextReceiptItem;
import com.shtrih.jpos.fiscalprinter.receipt.FSSaleReceiptItem;
import com.shtrih.jpos.fiscalprinter.receipt.FSTLVItem;
import com.shtrih.util.CompositeLogger;
import com.shtrih.util.StringUtils;
import com.shtrih.util.SysUtils;
Expand Down Expand Up @@ -53,72 +58,67 @@ public class TextGenerator implements ReceiptVisitor {
public TextGenerator(SMFiscalPrinter printer) throws Exception {
this.printer = printer;
}
public void visitCustomReceipt(Object element){

public void visitCustomReceipt(Object element) {
}
public void visitSalesReceipt(Object element)
{
if (!(element instanceof FSSalesReceipt)) return;
FSSalesReceipt receipt = (FSSalesReceipt)element;
try
{

public void visitSalesReceipt(Object element) {
if (!(element instanceof FSSalesReceipt)) {
return;
}
FSSalesReceipt receipt = (FSSalesReceipt) element;
try {
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)
{
if (receipt.discounts.getTotal() > 0) {
add(PrinterConst.STotalText, summToStr(receipt.getSubtotal()));
/*
if (receipt.isRounded()){
add(PrinterConst.SRoundingText, summToStr(receipt.getRounding()));
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]));
}
*/
}
//add(PrinterConst.SReceiptTotal, summToStr(receipt.getTotal()));
/*
receipt.getPaymentAmount()
long[] payments = params.getPayments();
for (int i = 0; i < payments.length; i++) {
if (payments[i] > 0) {
add(getPaymentName(i), summToStr(payments[i]));
// Change
if (receipt.getChange() > 0)
{
add(PrinterConst.SChangeText, summToStr(receipt.getChange()));
}
}

// Change
if (command.getChange() > 0) {
add(SChangeText, summToStr(command.getChange()));
}
addFiscalSign();
readEJReport(true);
endDocument();
}
*/

}
catch(Exception e){
} catch (Exception e) {
logger.error("Failed duplicate receipt", e);
}
}

public void addFiscalSign()
{
try{

public void addFiscalSign() {
try {
printer.waitForPrinting();
long docNumber = printer.fsReadStatus().getDocNumber();
long docSign = printer.fsFindDocument(docNumber).getDocument().getDocSign();
add(String.format("ФД:%d ФП:%10d", docNumber, docSign));
}
catch(Exception e){
} catch (Exception e) {
logger.error("addFiscalSign", e);
}
}

private void connect() throws Exception {
if (!connected) {
printer.check(printer.readDeviceMetrics()); //!
Expand All @@ -133,19 +133,18 @@ private void connect() throws Exception {
connected = true;
}
}

private String getOperatorName() throws Exception {
String operatorName = operators.get(operatorNumber);
if (operatorName == null)
{
if (operatorName == null) {
String[] fieldValue = new String[1];
printer.check(printer.readTable(PrinterConst.SMFP_TABLE_CASHIER, operatorNumber, 2, fieldValue));
operatorName = fieldValue[0];
operators.put(operatorNumber, operatorName);
}
return operatorName;
}
}

private void printReceiptHeader() throws Exception {
LongPrinterStatus status = printer.readLongStatus();
int documentNumber = status.getDocumentNumber() + 1;
Expand All @@ -160,12 +159,15 @@ private void printReceiptHeader() throws Exception {
time.getHour(), time.getMin());
add(s, getOperatorName());
}

private void process(Object item) throws Exception {
try {
if (item instanceof FSSaleReceiptItem) {
process((FSSaleReceiptItem) item);
}
if (item instanceof FSTLVItem) {
process((FSTLVItem) item);
}
if (item instanceof FSTextReceiptItem) {
process((FSTextReceiptItem) item);
}
Expand All @@ -191,15 +193,15 @@ private String amountToStr(long value) {
DecimalFormat formatter = new DecimalFormat("0.00", symbols);
return formatter.format(value / 100.0);
}

private String summToStr(long price, double quantity) {
return summToStr(Math.round(quantity * price));
}

private String summToStr(long amount) {
return "=" + amountToStr(amount);
}

private String getTaxData(int tax1, int tax2, int tax3, int tax4) throws Exception {
String result = "";
String taxLetters = " АБВГДЕ";
Expand All @@ -220,58 +222,75 @@ private String getTaxData(int tax1, int tax2, int tax3, int tax4) throws Excepti
}
return result;
}

private void process(FSSaleReceiptItem item) throws Exception {
String line = "";
add(item.getText());

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

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

addTags(item.getTags());
}

private void process(FSTLVItem item) throws Exception {
addTag(item.getData());
}

public void addTags(List<FSTLVItem> items) throws Exception {
for (int i = 0; i < items.size(); i++) {
addTag(items.get(i).getData());
}
}

public void addTag(byte[] data) throws Exception {
TLVReader reader = new TLVReader();
TLVItems tlvItems = reader.read(data);
TLVTextWriter writer = new TLVTextWriter(tlvItems);
List<String> lines = new Vector<String>();
writer.getPrintText(lines);
for (String line : lines) {
add(line);
}
}

private void process(FSTextReceiptItem item) throws Exception {
add(item.preLine);
add(item.text);
add(item.postLine);
}

private void process(PrinterBarcode item) throws Exception {
add("BARCODE");
add(item.getLabel());
add(item.getText());
}

private void process(AmountItem item) throws Exception
{
if (item.getAmount() > 0)
{
if (item.getText().isEmpty())
{

private void process(AmountItem item) throws Exception {
if (item.getAmount() > 0) {
if (item.getText().isEmpty()) {
add("СКИДКА", "=" + amountToStr(item.getAmount()));
} else
{
} else {
add("СКИДКА");
add(item.getText(), "=" + amountToStr(item.getAmount()));
}
} else{
if (item.getText().isEmpty())
{
} else {
if (item.getText().isEmpty()) {
add("НАДБАВКА", "=" + amountToStr(Math.abs(item.getAmount())));
} else
{
} else {
add("НАДБАВКА");
add(item.getText(), "=" + amountToStr(Math.abs(item.getAmount())));
}
}
}
private int getLineLength() throws Exception{

private int getLineLength() throws Exception {
if (lineLength == 0) {
lineLength = printer.getMessageLength();
}
Expand All @@ -285,15 +304,15 @@ private void add(String s1, String s2) throws Exception {

}

public List<String> getLines(){
public List<String> getLines() {
return lines;
}

private void add(String line) throws Exception {
if (line == null) {
return;
}
lines.add(line);
}

}
}
Loading

0 comments on commit dc1a9a7

Please sign in to comment.