fix of summary report bug

This commit is contained in:
moon 2026-04-06 00:13:41 +06:30
parent 2238988846
commit 820dcf9aa6
2 changed files with 227 additions and 78 deletions

View File

@ -767,15 +767,169 @@ public abstract class BaseXPrint {
class TempSummary { class TempSummary {
int saleCount, voidSaleCount, refundCount, cashOutCount; int saleCount, voidSaleCount, refundCount, cashOutCount;
int preAuthSaleCount, preAuthVoidCount;
int qrPayCount, qrRefundCount; int qrPayCount, qrRefundCount;
int preAuthCompCount, preAuthCompVoidCount; int preAuthCompCount, preAuthCompVoidCount;
long saleAmount, voidSaleAmount, refundAmount, cashOutAmount; long saleAmount, voidSaleAmount, refundAmount, cashOutAmount;
long preAuthSaleAmount, preAuthVoidAmount;
long qrPayAmount, qrRefundAmount; long qrPayAmount, qrRefundAmount;
long preAuthCompAmount, preAuthCompVoidAmount; long preAuthCompAmount, preAuthCompVoidAmount;
} }
private void applyTempSummary(TempSummary summary, PayDetail item) {
int transactionType = item.getTransactionType();
long amount = item.getAmount();
if (transactionType == TransactionsType.SALE.value) {
summary.saleCount++;
summary.saleAmount += amount;
return;
}
if (transactionType == TransactionsType.VOID.value) {
summary.voidSaleCount++;
summary.voidSaleAmount += amount;
return;
}
if (transactionType == TransactionsType.REFUND.value) {
summary.refundCount++;
summary.refundAmount += amount;
return;
}
if (transactionType == TransactionsType.CASH_OUT.value) {
summary.cashOutCount++;
summary.cashOutAmount += amount;
return;
}
if (transactionType == TransactionsType.PRE_AUTH_SALE.value) {
summary.preAuthSaleCount++;
summary.preAuthSaleAmount += amount;
return;
}
if (transactionType == TransactionsType.PRE_AUTH_VOID.value) {
summary.preAuthVoidCount++;
summary.preAuthVoidAmount += amount;
return;
}
if (transactionType == TransactionsType.MMQR.value) {
summary.qrPayCount++;
summary.qrPayAmount += amount;
return;
}
if (transactionType == TransactionsType.MMQR_REFUND.value) {
summary.qrRefundCount++;
summary.qrRefundAmount += amount;
return;
}
if (transactionType == TransactionsType.PRE_AUTH_COMPLETE.value) {
summary.preAuthCompCount++;
summary.preAuthCompAmount += amount;
return;
}
if (transactionType == TransactionsType.PRE_AUTH_COMPLETE_VOID.value) {
summary.preAuthCompVoidCount++;
summary.preAuthCompVoidAmount += amount;
return;
}
String transType = item.getTransType() == null ? "" : item.getTransType().trim().toUpperCase(Locale.getDefault());
switch (transType) {
case "SALE":
summary.saleCount++;
summary.saleAmount += amount;
break;
case "VOID SALE":
case "VOID_SALE":
summary.voidSaleCount++;
summary.voidSaleAmount += amount;
break;
case "REFUND":
summary.refundCount++;
summary.refundAmount += amount;
break;
case "PRE-AUTH":
case "PRE_AUTH_SALE":
summary.preAuthSaleCount++;
summary.preAuthSaleAmount += amount;
break;
case "PREAUTH CANCELLATION":
case "PRE_AUTH_VOID":
summary.preAuthVoidCount++;
summary.preAuthVoidAmount += amount;
break;
case "CASH OUT":
case "CASH_OUT":
case "CASH_ADVANCE":
summary.cashOutCount++;
summary.cashOutAmount += amount;
break;
case "QR_PAY":
summary.qrPayCount++;
summary.qrPayAmount += amount;
break;
case "QR_REFUND":
summary.qrRefundCount++;
summary.qrRefundAmount += amount;
break;
case "PREAUTH COMPLETION":
case "PRE_AUTH_COMPLETE":
case "PREAUTH_COMP":
summary.preAuthCompCount++;
summary.preAuthCompAmount += amount;
break;
case "VOID PREAUTH COMPLETE":
case "PRE_AUTH_COMPLETE_VOID":
case "PREAUTH_COMP_VOID":
summary.preAuthCompVoidCount++;
summary.preAuthCompVoidAmount += amount;
break;
}
}
private boolean matchesSummaryHostType(PayDetail item, HostType hostType) {
if (hostType == null || item == null) {
return true;
}
int transactionType = item.getTransactionType();
if (hostType == HostType.QR) {
return transactionType == TransactionsType.MMQR.value
|| transactionType == TransactionsType.MMQR_REFUND.value;
}
if (hostType == HostType.MPU || hostType == HostType.VISA_MASTER) {
return transactionType != TransactionsType.MMQR.value
&& transactionType != TransactionsType.MMQR_REFUND.value;
}
return true;
}
protected void printTransDetailSummary(PayDetail payDetail, List<PayDetail> list) { protected void printTransDetailSummary(PayDetail payDetail, List<PayDetail> list) {
printTransDetailSummary(payDetail, list, null);
}
protected void printTransDetailSummary(PayDetail payDetail, List<PayDetail> list, HostType hostType) {
if (list == null || list.isEmpty()) { if (list == null || list.isEmpty()) {
printErrorBlock("NO TRANSACTION FOUND"); printErrorBlock("NO TRANSACTION FOUND");
@ -788,6 +942,7 @@ public abstract class BaseXPrint {
for (PayDetail item : list) { for (PayDetail item : list) {
if (item == null) continue; if (item == null) continue;
if (!matchesSummaryHostType(item, hostType)) continue;
String currency = item.getCurrencyCode(); String currency = item.getCurrencyCode();
TempSummary s = currencyMap.get(currency); TempSummary s = currencyMap.get(currency);
@ -797,51 +952,13 @@ public abstract class BaseXPrint {
currencyMap.put(currency, s); currencyMap.put(currency, s);
} }
String transType = item.getTransType(); applyTempSummary(s, item);
long amount = item.getAmount(); }
switch (transType) { if (currencyMap.isEmpty()) {
printErrorBlock("NO TRANSACTION FOUND");
case "SALE": printer.appendPrnStr("\n", fontNormal, AlignEnum.LEFT,false);
s.saleCount++; return;
s.saleAmount += amount;
break;
case "VOID_SALE":
s.voidSaleCount++;
s.voidSaleAmount += amount;
break;
case "REFUND":
s.refundCount++;
s.refundAmount += amount;
break;
case "CASH_OUT":
s.cashOutCount++;
s.cashOutAmount += amount;
break;
case "QR_PAY":
s.qrPayCount++;
s.qrPayAmount += amount;
break;
case "QR_REFUND":
s.qrRefundCount++;
s.qrRefundAmount += amount;
break;
case "PREAUTH_COMP":
s.preAuthCompCount++;
s.preAuthCompAmount += amount;
break;
case "PREAUTH_COMP_VOID":
s.preAuthCompVoidCount++;
s.preAuthCompVoidAmount += amount;
break;
}
} }
boolean isQrDecimalEnabled = SystemParamsOperation.getInstance().isQrDecimalEnable(); boolean isQrDecimalEnabled = SystemParamsOperation.getInstance().isQrDecimalEnable();
@ -850,6 +967,7 @@ public abstract class BaseXPrint {
for (String currency : currencyMap.keySet()) { for (String currency : currencyMap.keySet()) {
TempSummary data = currencyMap.get(currency); TempSummary data = currencyMap.get(currency);
boolean isQrHost = hostType == HostType.QR;
printer.appendPrnStr( currencyCodeToText(currency) + " " +"Transactions", fontNormal, AlignEnum.LEFT, false); printer.appendPrnStr( currencyCodeToText(currency) + " " +"Transactions", fontNormal, AlignEnum.LEFT, false);
emptyLine(1); emptyLine(1);
@ -857,49 +975,80 @@ public abstract class BaseXPrint {
// printer.appendPrnStr("(COUNT)TRANS", "AMOUNT(" + currencyCodeToText(currency) + ")", fontNormal, false); // printer.appendPrnStr("(COUNT)TRANS", "AMOUNT(" + currencyCodeToText(currency) + ")", fontNormal, false);
print3ColumnsStringWithAlign("COUNT", "TRANS", "AMOUNT" + "(" + currencyCodeToText(currency) + ")", fontNormal, false); print3ColumnsStringWithAlign("COUNT", "TRANS", "AMOUNT" + "(" + currencyCodeToText(currency) + ")", fontNormal, false);
if (data.saleCount > 0) { if (isQrHost) {
print3ColumnsStringWithAlign("(" + data.saleCount + ")", if (data.qrPayCount > 0) {
"SALES", print3ColumnsStringWithAlign("(" + data.qrPayCount + ")",
PrintUtils.getInstance().getSeparatorNumberFormat(data.saleAmount, isDecimalEnabled), "QR PAY",
fontNormal, false); PrintUtils.getInstance().getSeparatorNumberFormat(data.qrPayAmount, isQrDecimalEnabled),
} fontNormal, false);
}
if (data.voidSaleCount > 0) { if (data.qrRefundCount > 0) {
print3ColumnsStringWithAlign("(" + data.voidSaleCount + ")", print3ColumnsStringWithAlign("(" + data.qrRefundCount + ")",
"VOID", "QR REFUND",
"- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.voidSaleAmount, isDecimalEnabled), "- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.qrRefundAmount, isQrDecimalEnabled),
fontNormal, false); fontNormal, false);
} }
} else {
if (data.saleCount > 0) {
print3ColumnsStringWithAlign("(" + data.saleCount + ")",
"SALES",
PrintUtils.getInstance().getSeparatorNumberFormat(data.saleAmount, isDecimalEnabled),
fontNormal, false);
}
if (data.cashOutCount > 0) { if (data.voidSaleCount > 0) {
print3ColumnsStringWithAlign("(" + data.cashOutCount + ")", print3ColumnsStringWithAlign("(" + data.voidSaleCount + ")",
"CASH ADV", "VOID",
PrintUtils.getInstance().getSeparatorNumberFormat(data.cashOutAmount, isDecimalEnabled), "- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.voidSaleAmount, isDecimalEnabled),
fontNormal, false); fontNormal, false);
} }
if (data.refundCount > 0) { if (data.cashOutCount > 0) {
print3ColumnsStringWithAlign("(" + data.refundCount + ")", print3ColumnsStringWithAlign("(" + data.cashOutCount + ")",
"REFUND", "CASH ADV",
"- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.refundAmount, isDecimalEnabled), PrintUtils.getInstance().getSeparatorNumberFormat(data.cashOutAmount, isDecimalEnabled),
fontNormal, false); fontNormal, false);
} }
if (data.preAuthCompCount > 0) { if (data.preAuthSaleCount > 0) {
print3ColumnsStringWithAlign("(" + data.preAuthCompCount + ")", print3ColumnsStringWithAlign("(" + data.preAuthSaleCount + ")",
"PREAUTH COMP", "PRE-AUTH",
PrintUtils.getInstance().getSeparatorNumberFormat(data.preAuthCompAmount, isDecimalEnabled), PrintUtils.getInstance().getSeparatorNumberFormat(data.preAuthSaleAmount, isDecimalEnabled),
fontNormal, false); fontNormal, false);
}
if (data.preAuthVoidCount > 0) {
print3ColumnsStringWithAlign("(" + data.preAuthVoidCount + ")",
"PREAUTH VOID",
"- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.preAuthVoidAmount, isDecimalEnabled),
fontNormal, false);
}
if (data.refundCount > 0) {
print3ColumnsStringWithAlign("(" + data.refundCount + ")",
"REFUND",
"- " + PrintUtils.getInstance().getSeparatorNumberFormat(data.refundAmount, isDecimalEnabled),
fontNormal, false);
}
if (data.preAuthCompCount > 0) {
print3ColumnsStringWithAlign("(" + data.preAuthCompCount + ")",
"PREAUTH COMP",
PrintUtils.getInstance().getSeparatorNumberFormat(data.preAuthCompAmount, isDecimalEnabled),
fontNormal, false);
}
} }
dotBreak(); dotBreak();
long totalAmount = long totalAmount = isQrHost
(data.saleAmount + data.cashOutAmount + data.preAuthCompAmount) ? data.qrPayAmount - data.qrRefundAmount
- (data.voidSaleAmount + data.refundAmount + data.preAuthCompVoidAmount); : (data.saleAmount + data.cashOutAmount + data.preAuthSaleAmount + data.preAuthCompAmount)
- (data.voidSaleAmount + data.preAuthVoidAmount + data.refundAmount + data.preAuthCompVoidAmount);
printer.appendPrnStr( "TOTAL"+ " " + currencyCodeToText(currency), printer.appendPrnStr( "TOTAL"+ " " + currencyCodeToText(currency),
PrintUtils.getInstance().getSeparatorNumberFormat(totalAmount, isDecimalEnabled), PrintUtils.getInstance().getSeparatorNumberFormat(totalAmount, isQrHost ? isQrDecimalEnabled : isDecimalEnabled),
fontNormal, false); fontNormal, false);
emptyLine(2); emptyLine(2);

View File

@ -456,7 +456,7 @@ public class PrintXImpl extends BaseXPrint implements PrintX {
printLogo(); printLogo();
printMerchantHeader(); printMerchantHeader();
printTranHeader("SUMMARY REPORT"); printTranHeader("SUMMARY REPORT");
printTransDetailSummary(payDetail, list); printTransDetailSummary(payDetail, list, hostType);
startPrintNex(); startPrintNex();
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();