totalCashSurplus property
Decimal
get
totalCashSurplus
Total cash surplus (change) across all successful cash legs.
For each successful leg that has a PaymentLeg.cashTendered value,
calculates max(0, cashTendered - amount) and sums the results.
Returns Decimal.zero when there are no cash legs or no surplus.
Implementation
Decimal get totalCashSurplus {
return paymentLegs
.where((leg) => leg.isSuccess && leg.cashTendered != null)
.fold(Decimal.zero, (sum, leg) {
final surplus = leg.cashTendered! - leg.amount;
return sum + (surplus > Decimal.zero ? surplus : Decimal.zero);
});
}