added product import and billing integration
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../data/sync/sync_engine.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../../domain/usecases/checkout_sale.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
@@ -80,29 +79,27 @@ class PaymentController extends StateNotifier<PaymentState> {
|
||||
|
||||
/// Whether Complete Sale should be enabled.
|
||||
///
|
||||
/// Cash is the strict case: the drawer cannot be reconciled and no change can
|
||||
/// be calculated unless the cashier states what was handed over. Card, UPI
|
||||
/// and wallet settle on the external terminal, so they need no amount here.
|
||||
/// Every method now requires the cashier to state what was actually
|
||||
/// received before the sale can complete — a tap on Exact for the common
|
||||
/// case, or a typed amount for a partial tender. `cashTendered` is the
|
||||
/// amount entered for whichever method is currently active, not literally
|
||||
/// cash; the name stayed to keep this change out of the rest of the app.
|
||||
bool get canConfirm {
|
||||
if (_billTotal <= 0) return false;
|
||||
|
||||
// Staged splits already cover the bill.
|
||||
if (balanceDue <= 0.01) return true;
|
||||
|
||||
if (state.activeMethod.needsChange) {
|
||||
return state.cashTendered >= balanceDue;
|
||||
}
|
||||
return true;
|
||||
return state.cashTendered >= balanceDue;
|
||||
}
|
||||
|
||||
/// Why the button is disabled, for display next to it.
|
||||
String? get blockedReason {
|
||||
if (_billTotal <= 0) return 'Add at least one item before charging.';
|
||||
if (canConfirm) return null;
|
||||
if (state.activeMethod.needsChange) {
|
||||
return 'Enter the cash received, or tap Exact.';
|
||||
}
|
||||
return null;
|
||||
return state.activeMethod.needsChange
|
||||
? 'Enter the cash received, or tap Exact.'
|
||||
: 'Enter the amount received, or tap Exact.';
|
||||
}
|
||||
|
||||
void selectMethod(PaymentMethod method) {
|
||||
@@ -212,10 +209,11 @@ class PaymentController extends StateNotifier<PaymentState> {
|
||||
_ref.invalidate(visibleProductsProvider);
|
||||
_ref.read(orderVersionProvider.notifier).state++;
|
||||
|
||||
// The bill is safely on disk; getting it to the back office is the
|
||||
// engine's problem now. Deliberately not awaited — the cashier must
|
||||
// reach the receipt screen at network speed of zero.
|
||||
_ref.read(syncEngineProvider).nudge(SyncTrigger.saleCommitted);
|
||||
// Deliberately NOT nudging the sync engine here. The bill sits on this
|
||||
// terminal, unsynced, until the receipt screen's cancellation window
|
||||
// closes — either it is pressed past early with New Sale, or the
|
||||
// window runs out — or the sale is voided if the cashier cancels
|
||||
// instead. See ReceiptScreen.
|
||||
|
||||
return result;
|
||||
} on CheckoutFailure catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user