Update TransactionSummaryFragment.java

This commit is contained in:
moon 2026-04-01 13:49:47 +06:30
parent 18eda34bff
commit cb96ccb7ca

View File

@ -226,10 +226,15 @@ public class TransactionSummaryFragment extends DataBindingFragment {
} }
} }
private SettleData processTransactionData(List<PayDetail> payDetailList, SimpleDateFormat formatter, private SettleData processTransactionData(List<PayDetail> payDetailList,
Date yesterday, Date start, Date end) { SimpleDateFormat formatter,
Date yesterday,
Date start,
Date end) {
try { try {
// Create a local helper class for readable mutability // IMPORTANT: clear old data
filteredLists.clear();
class Counter { class Counter {
int count = 0; int count = 0;
long amount = 0L; long amount = 0L;
@ -252,37 +257,32 @@ public class TransactionSummaryFragment extends DataBindingFragment {
Counter preAuthCompVoid = new Counter(); Counter preAuthCompVoid = new Counter();
Counter refund = new Counter(); Counter refund = new Counter();
// Use ONE consistent format
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm", Locale.getDefault()); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm", Locale.getDefault());
for (PayDetail pay : payDetailList) { for (PayDetail pay : payDetailList) {
try { try {
Date transDate = formatter.parse(pay.getTransDate()); // Combine date + time correctly
if ((transDate.after(start) || transDate.equals(start)) &&
(transDate.before(end) || transDate.equals(end))) {
filteredLists.add(pay);
}
} catch (ParseException e) {
LogUtil.e(TAG, "Error parsing transaction date: " + e.getMessage());
}
}
LogUtil.d(TAG, "Filtered transactions count: " + filteredLists.size());
// Process filtered transactions
for (PayDetail pay : filteredLists) {
try {
Date currentDate = sdf.parse(pay.transDate + " " + pay.transTime); Date currentDate = sdf.parse(pay.transDate + " " + pay.transTime);
if ((currentDate.after(start) || currentDate.equals(start)) && if (currentDate == null) continue;
(currentDate.before(end) || currentDate.equals(end))) {
// Correct inclusive range check
if (!currentDate.before(start) && !currentDate.after(end)) {
// Keep filtered list for printing
filteredLists.add(pay);
if (sharedViewModel.hostType.getValue() == HostType.QR) { if (sharedViewModel.hostType.getValue() == HostType.QR) {
if (pay.getTransactionType() == TransactionsType.MMQR.value && pay.getQrTransStatus() == 1) { if (pay.getTransactionType() == TransactionsType.MMQR.value && pay.getQrTransStatus() == 1) {
wave.inc(pay.amount); wave.inc(pay.amount);
} else if (pay.getTransactionType() == TransactionsType.MMQR_REFUND.value && pay.getQrTransStatus() == 1) { } else if (pay.getTransactionType() == TransactionsType.MMQR_REFUND.value && pay.getQrTransStatus() == 1) {
waveRefund.inc(pay.amount); waveRefund.inc(pay.amount);
} }
} else if (sharedViewModel.hostType.getValue() == HostType.MPU) { } else if (sharedViewModel.hostType.getValue() == HostType.MPU) {
if (pay.getTransactionType() == TransactionsType.VOID.value) { if (pay.getTransactionType() == TransactionsType.VOID.value) {
voidTran.inc(pay.amount); voidTran.inc(pay.amount);
} else if (pay.getTransactionType() == TransactionsType.SALE.value) { } else if (pay.getTransactionType() == TransactionsType.SALE.value) {
@ -302,11 +302,14 @@ public class TransactionSummaryFragment extends DataBindingFragment {
} }
} }
} }
} catch (ParseException e) { } catch (ParseException e) {
LogUtil.e(TAG, "Error parsing transaction datetime: " + e.getMessage()); LogUtil.e(TAG, "Error parsing transaction datetime: " + e.getMessage());
} }
} }
LogUtil.d(TAG, "Filtered transactions count: " + filteredLists.size());
return new SettleData( return new SettleData(
sale.count, sale.amount, sale.count, sale.amount,
wave.count, wave.amount, wave.count, wave.amount,
@ -319,6 +322,7 @@ public class TransactionSummaryFragment extends DataBindingFragment {
refund.count, refund.amount, refund.count, refund.amount,
waveRefund.count, waveRefund.amount waveRefund.count, waveRefund.amount
); );
} catch (Exception e) { } catch (Exception e) {
LogUtil.e(TAG, "Error processing transaction data: " + e.getMessage()); LogUtil.e(TAG, "Error processing transaction data: " + e.getMessage());
return null; return null;