perubahan denomuretor on pos sale

This commit is contained in:
2026-04-04 23:44:16 +07:00
parent 517ed3bea3
commit d912b1f63a
20 changed files with 350 additions and 142 deletions

View File

@@ -41,6 +41,7 @@ class MultiPaymentWidget extends ConsumerStatefulWidget {
final bool hideAddButton;
final bool disableDropdown;
final bool showCashDenomination;
final num? totalDueAmount;
final VoidCallback? onPaymentListChanged;
final List<PaymentsTransaction>? initialTransactions;
@@ -53,6 +54,7 @@ class MultiPaymentWidget extends ConsumerStatefulWidget {
this.hideAddButton = false,
this.disableDropdown = false,
this.showCashDenomination = false,
this.totalDueAmount,
this.onPaymentListChanged,
this.initialTransactions,
});
@@ -135,6 +137,39 @@ class MultiPaymentWidgetState extends ConsumerState<MultiPaymentWidget> {
_isSyncing = false;
}
@override
void didUpdateWidget(MultiPaymentWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.totalDueAmount != oldWidget.totalDueAmount && widget.totalDueAmount != null && widget.totalDueAmount! > 0) {
if (_paymentEntries.length == 1) {
if (widget.totalDueAmount! % 1 == 0) {
_paymentEntries[0].amountController.text = widget.totalDueAmount!.toInt().toString();
} else {
_paymentEntries[0].amountController.text = widget.totalDueAmount!.toStringAsFixed(2);
}
_calculateTotalsFromPayments();
} else if (_paymentEntries.length > 1) {
// Adjust the last entry
double otherTotals = 0;
for (int i = 0; i < _paymentEntries.length - 1; i++) {
otherTotals += double.tryParse(_paymentEntries[i].amountController.text) ?? 0;
}
double remaining = widget.totalDueAmount!.toDouble() - otherTotals;
if (remaining > 0) {
if (remaining % 1 == 0) {
_paymentEntries.last.amountController.text = remaining.toInt().toString();
} else {
_paymentEntries.last.amountController.text = remaining.toStringAsFixed(2);
}
} else {
_paymentEntries.last.amountController.text = '0';
}
_calculateTotalsFromPayments();
}
}
}
// Listener for all payment amount fields
void _calculateTotalsFromPayments() {
if (_isSyncing) return;
@@ -290,6 +325,25 @@ class MultiPaymentWidgetState extends ConsumerState<MultiPaymentWidget> {
: (value) {
setState(() {
payment.type = value;
if (widget.totalDueAmount != null && widget.totalDueAmount! > 0) {
double otherTotals = 0;
for (var p in _paymentEntries) {
if (p != payment) {
otherTotals += double.tryParse(p.amountController.text) ?? 0;
}
}
double remaining = widget.totalDueAmount!.toDouble() - otherTotals;
if (remaining > 0) {
if (remaining % 1 == 0) {
payment.amountController.text = remaining.toInt().toString();
} else {
payment.amountController.text = remaining.toStringAsFixed(2);
}
} else {
payment.amountController.text = '0';
}
_calculateTotalsFromPayments();
}
});
},
validator: (value) {