third commit
This commit is contained in:
@@ -78,12 +78,13 @@ class _CustomerCaptureSheetState
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
/// Saves with whatever was given. Both fields are optional: a bare number
|
||||
/// is still worth keeping, because it is what the WhatsApp bill is sent to.
|
||||
Future<void> _quickRegister() async {
|
||||
final name = _name.text.trim();
|
||||
if (name.length < 2) {
|
||||
setState(() => _error = 'Enter a name to save this customer');
|
||||
return;
|
||||
}
|
||||
final typed = _name.text.trim();
|
||||
final name = typed.isEmpty
|
||||
? 'Customer ${_digits.substring(_digits.length - 4)}'
|
||||
: typed;
|
||||
|
||||
setState(() {
|
||||
_saving = true;
|
||||
@@ -320,8 +321,11 @@ class _CustomerCaptureSheetState
|
||||
_message(
|
||||
Icons.dialpad_rounded,
|
||||
AppColors.textTertiary,
|
||||
'Key in a 10-digit mobile number. The lookup runs automatically.',
|
||||
'Key in a 10-digit mobile number — the lookup runs automatically. '
|
||||
'Both fields are optional.',
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_nameField(),
|
||||
if (recent.isNotEmpty) ...[
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
const Align(
|
||||
@@ -466,22 +470,11 @@ class _CustomerCaptureSheetState
|
||||
_message(
|
||||
Icons.person_search_rounded,
|
||||
AppColors.warning,
|
||||
'Not registered yet. Add a name to save them, or carry on '
|
||||
'without.',
|
||||
'New number. Add a name if you have it — the bill can be sent to '
|
||||
'this number on WhatsApp either way.',
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
TextField(
|
||||
controller: _name,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
enabled: !_saving,
|
||||
onSubmitted: (_) => _quickRegister(),
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(60)],
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Customer name',
|
||||
hintText: 'Full name',
|
||||
prefixIcon: Icon(Icons.person_outline_rounded),
|
||||
),
|
||||
),
|
||||
_nameField(),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
@@ -506,6 +499,19 @@ class _CustomerCaptureSheetState
|
||||
],
|
||||
);
|
||||
|
||||
Widget _nameField() => TextField(
|
||||
controller: _name,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
enabled: !_saving,
|
||||
onSubmitted: (_) => _quickRegister(),
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(60)],
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Customer name',
|
||||
hintText: 'Optional',
|
||||
prefixIcon: Icon(Icons.person_outline_rounded),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _miniStat(String value, String label) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
118
lib/presentation/modules/providers/printer_settings.dart
Normal file
118
lib/presentation/modules/providers/printer_settings.dart
Normal file
@@ -0,0 +1,118 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../data/local/app_database.dart';
|
||||
|
||||
/// Hardware preferences for this terminal.
|
||||
///
|
||||
/// Persisted in `app_meta` rather than held in widget state, so the choice
|
||||
/// survives a restart — a cashier should not have to reselect the printer
|
||||
/// every morning.
|
||||
class PrinterSettings {
|
||||
const PrinterSettings({
|
||||
this.printerUrl,
|
||||
this.printerName,
|
||||
this.autoPrint = false,
|
||||
this.openDrawer = true,
|
||||
});
|
||||
|
||||
/// Target passed to `directPrintPdf`. Null means "use the system default".
|
||||
final String? printerUrl;
|
||||
|
||||
/// Shown in Settings. Kept alongside the url because the url is opaque.
|
||||
final String? printerName;
|
||||
|
||||
/// Print silently the moment a sale completes.
|
||||
///
|
||||
/// Defaults to **off**: with no printer attached, auto-printing fails
|
||||
/// invisibly and looks like a bug.
|
||||
final bool autoPrint;
|
||||
|
||||
final bool openDrawer;
|
||||
|
||||
bool get hasPrinter => printerUrl != null;
|
||||
|
||||
PrinterSettings copyWith({
|
||||
String? printerUrl,
|
||||
String? printerName,
|
||||
bool clearPrinter = false,
|
||||
bool? autoPrint,
|
||||
bool? openDrawer,
|
||||
}) {
|
||||
return PrinterSettings(
|
||||
printerUrl: clearPrinter ? null : (printerUrl ?? this.printerUrl),
|
||||
printerName: clearPrinter ? null : (printerName ?? this.printerName),
|
||||
autoPrint: autoPrint ?? this.autoPrint,
|
||||
openDrawer: openDrawer ?? this.openDrawer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PrinterSettingsController extends StateNotifier<PrinterSettings> {
|
||||
PrinterSettingsController(this._ref) : super(const PrinterSettings()) {
|
||||
_load();
|
||||
}
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<void> _load() async {
|
||||
final store = _ref.read(localStoreProvider);
|
||||
if (!store.isReady) return;
|
||||
|
||||
final dao = store.catalogue;
|
||||
state = PrinterSettings(
|
||||
printerUrl: await dao.meta(MetaKeys.printerUrl),
|
||||
printerName: await dao.meta(MetaKeys.printerName),
|
||||
autoPrint: (await dao.meta(MetaKeys.autoPrint)) == '1',
|
||||
openDrawer: (await dao.meta(MetaKeys.openDrawer)) != '0',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> selectPrinter(Printer? printer) async {
|
||||
final dao = _ref.read(localStoreProvider).catalogue;
|
||||
|
||||
if (printer == null) {
|
||||
await dao.setMeta(MetaKeys.printerUrl, '');
|
||||
await dao.setMeta(MetaKeys.printerName, '');
|
||||
state = state.copyWith(clearPrinter: true, autoPrint: false);
|
||||
return;
|
||||
}
|
||||
|
||||
await dao.setMeta(MetaKeys.printerUrl, printer.url);
|
||||
await dao.setMeta(MetaKeys.printerName, printer.name);
|
||||
state = state.copyWith(
|
||||
printerUrl: printer.url,
|
||||
printerName: printer.name,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setAutoPrint(bool value) async {
|
||||
// Auto-print with nothing selected would fail silently on every sale.
|
||||
if (value && !state.hasPrinter) return;
|
||||
|
||||
await _ref
|
||||
.read(localStoreProvider)
|
||||
.catalogue
|
||||
.setMeta(MetaKeys.autoPrint, value ? '1' : '0');
|
||||
state = state.copyWith(autoPrint: value);
|
||||
}
|
||||
|
||||
Future<void> setOpenDrawer(bool value) async {
|
||||
await _ref
|
||||
.read(localStoreProvider)
|
||||
.catalogue
|
||||
.setMeta(MetaKeys.openDrawer, value ? '1' : '0');
|
||||
state = state.copyWith(openDrawer: value);
|
||||
}
|
||||
}
|
||||
|
||||
final printerSettingsProvider =
|
||||
StateNotifierProvider<PrinterSettingsController, PrinterSettings>(
|
||||
(ref) => PrinterSettingsController(ref),
|
||||
);
|
||||
|
||||
/// Printers the OS can currently see. Re-read whenever Settings is opened.
|
||||
final availablePrintersProvider = FutureProvider<List<Printer>>(
|
||||
(ref) => ref.watch(receiptServiceProvider).availablePrinters(),
|
||||
);
|
||||
@@ -8,6 +8,7 @@ import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/store_account.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
import '../providers/printer_settings.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
@@ -21,11 +22,8 @@ class SettingsView extends ConsumerStatefulWidget {
|
||||
|
||||
class _SettingsViewState extends ConsumerState<SettingsView> {
|
||||
bool _scannerSound = true;
|
||||
bool _autoPrint = true;
|
||||
bool _openDrawer = true;
|
||||
bool _roundOff = true;
|
||||
bool _autoLoyalty = true;
|
||||
bool _offline = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -138,36 +136,160 @@ class _SettingsViewState extends ConsumerState<SettingsView> {
|
||||
),
|
||||
);
|
||||
|
||||
Widget _hardwareCard() => PanelCard(
|
||||
title: 'Hardware & peripherals',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_toggle(
|
||||
'Scanner beep',
|
||||
'Audible confirmation on every scan',
|
||||
_scannerSound,
|
||||
(v) => setState(() => _scannerSound = v),
|
||||
Widget _hardwareCard() {
|
||||
final settings = ref.watch(printerSettingsProvider);
|
||||
final controller = ref.read(printerSettingsProvider.notifier);
|
||||
final printers = ref.watch(availablePrintersProvider);
|
||||
|
||||
return PanelCard(
|
||||
title: 'Printer & peripherals',
|
||||
subtitle: 'Install the printer in the operating system first — it then '
|
||||
'appears in this list.',
|
||||
action: TextButton.icon(
|
||||
onPressed: () => ref.invalidate(availablePrintersProvider),
|
||||
icon: const Icon(Icons.refresh_rounded, size: 16),
|
||||
label: const Text('Rescan'),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
printers.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppSpacing.lg),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
_toggle(
|
||||
'Print receipt automatically',
|
||||
'Sends to the default roll printer with no dialog',
|
||||
_autoPrint,
|
||||
(v) => setState(() => _autoPrint = v),
|
||||
error: (e, _) => Text(
|
||||
'Could not list printers: $e',
|
||||
style: const TextStyle(color: AppColors.danger, fontSize: 12.5),
|
||||
),
|
||||
_toggle(
|
||||
'Open cash drawer on cash sales',
|
||||
'Sends the ESC/POS kick pulse',
|
||||
_openDrawer,
|
||||
(v) => setState(() => _openDrawer = v),
|
||||
),
|
||||
const Divider(height: AppSpacing.xxl),
|
||||
_row('Receipt printer', 'EPSON TM-T82 (default)'),
|
||||
_row('Barcode scanner', 'Keyboard wedge · detected'),
|
||||
_row('Cash drawer', 'Connected via printer'),
|
||||
],
|
||||
),
|
||||
);
|
||||
data: (list) {
|
||||
if (list.isEmpty) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.warningSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: const Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.print_disabled_rounded,
|
||||
size: 18, color: AppColors.warning),
|
||||
SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'No printers found. Add the thermal printer in your '
|
||||
'operating system settings, then tap Rescan. Bills '
|
||||
'still print to screen in the meantime.',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: AppColors.warning,
|
||||
height: 1.45,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: list.any((p) => p.url == settings.printerUrl)
|
||||
? settings.printerUrl
|
||||
: null,
|
||||
isExpanded: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Receipt printer',
|
||||
prefixIcon: Icon(Icons.print_outlined),
|
||||
isDense: true,
|
||||
),
|
||||
hint: const Text('Print to screen only'),
|
||||
items: [
|
||||
for (final p in list)
|
||||
DropdownMenuItem(
|
||||
value: p.url,
|
||||
child: Text(
|
||||
p.isDefault ? '${p.name} (system default)' : p.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (url) => controller.selectPrinter(
|
||||
url == null
|
||||
? null
|
||||
: list.firstWhere((p) => p.url == url),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final ok = await ref
|
||||
.read(receiptServiceProvider)
|
||||
.printTestPage(
|
||||
printerUrl: settings.printerUrl);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(
|
||||
backgroundColor: ok
|
||||
? AppColors.success
|
||||
: AppColors.danger,
|
||||
content: Text(ok
|
||||
? 'Test slip sent to the printer.'
|
||||
: 'Could not reach the printer.'),
|
||||
));
|
||||
},
|
||||
icon: const Icon(Icons.receipt_long_rounded, size: 17),
|
||||
label: const Text('Print test slip'),
|
||||
),
|
||||
if (settings.hasPrinter)
|
||||
TextButton(
|
||||
onPressed: () => controller.selectPrinter(null),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.textSecondary,
|
||||
),
|
||||
child: const Text('Use screen only'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: AppSpacing.xxl),
|
||||
_toggle(
|
||||
'Scanner beep',
|
||||
'Audible confirmation on every scan',
|
||||
_scannerSound,
|
||||
(v) => setState(() => _scannerSound = v),
|
||||
),
|
||||
_toggle(
|
||||
'Print receipt automatically',
|
||||
settings.hasPrinter
|
||||
? 'Sends to the selected printer the moment a sale completes'
|
||||
: 'Select a printer above to enable this',
|
||||
settings.autoPrint,
|
||||
settings.hasPrinter ? controller.setAutoPrint : null,
|
||||
),
|
||||
_toggle(
|
||||
'Open cash drawer on cash sales',
|
||||
'Needs a raw ESC/POS link — see the notes in ReceiptService',
|
||||
settings.openDrawer,
|
||||
controller.setOpenDrawer,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _staffCard(StoreAccount? store, StaffUser? current) => PanelCard(
|
||||
title: 'Users & roles',
|
||||
@@ -212,13 +334,15 @@ class _SettingsViewState extends ConsumerState<SettingsView> {
|
||||
_row('Unsynced bills', '$outstanding'),
|
||||
_toggle(
|
||||
'Simulate offline',
|
||||
'Forces import and push to fail, so you can confirm nothing is '
|
||||
'Forces import and sync to fail, so you can confirm nothing is '
|
||||
'lost when the network drops',
|
||||
_offline,
|
||||
// Read straight from the provider — no local copy to drift.
|
||||
ref.watch(simulateOfflineProvider),
|
||||
(v) {
|
||||
setState(() => _offline = v);
|
||||
ref.read(remoteCatalogueProvider).simulateOffline = v;
|
||||
ref.read(remoteOrderSinkProvider).simulateOffline = v;
|
||||
ref.read(simulateOfflineProvider.notifier).state = v;
|
||||
// Clear any stale failure banner left by the previous setting.
|
||||
ref.read(catalogueImportProvider.notifier).reset();
|
||||
ref.read(orderSyncProvider.notifier).reset();
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -286,7 +410,7 @@ class _SettingsViewState extends ConsumerState<SettingsView> {
|
||||
String title,
|
||||
String subtitle,
|
||||
bool value,
|
||||
ValueChanged<bool> onChanged,
|
||||
ValueChanged<bool>? onChanged,
|
||||
) =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
||||
|
||||
@@ -74,11 +74,31 @@ class PaymentController extends StateNotifier<PaymentState> {
|
||||
return diff > 0 ? diff.asMoney : 0;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
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 && balanceDue > 0;
|
||||
return state.cashTendered >= balanceDue;
|
||||
}
|
||||
return balanceDue > 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
||||
void selectMethod(PaymentMethod method) {
|
||||
@@ -156,10 +176,10 @@ class PaymentController extends StateNotifier<PaymentState> {
|
||||
|
||||
state = state.copyWith(isProcessing: false, result: result);
|
||||
|
||||
// Fire and forget — printing must never block the next sale.
|
||||
final receipts = _ref.read(receiptServiceProvider);
|
||||
unawaited(receipts.printDirect(result.transaction));
|
||||
unawaited(receipts.openCashDrawer());
|
||||
// No auto-print: with no roll printer attached this silently failed and
|
||||
// looked like a bug. The receipt screen shows the bill on the terminal
|
||||
// and offers Print, WhatsApp and Share explicitly.
|
||||
unawaited(_ref.read(receiptServiceProvider).openCashDrawer());
|
||||
unawaited(_ref.read(soundServiceProvider).saleComplete());
|
||||
|
||||
// Stock changed, so the grid must refresh; the new order changes the
|
||||
|
||||
@@ -125,7 +125,7 @@ class _PaymentScreenState extends ConsumerState<PaymentScreen> {
|
||||
);
|
||||
},
|
||||
),
|
||||
bottomNavigationBar: _bottomBar(cart.grandTotal, state, cart.isEmpty),
|
||||
bottomNavigationBar: _bottomBar(controller, state, cart.grandTotal),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -557,7 +557,15 @@ class _PaymentScreenState extends ConsumerState<PaymentScreen> {
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ Bottom bar
|
||||
Widget _bottomBar(double total, PaymentState state, bool cartEmpty) {
|
||||
Widget _bottomBar(
|
||||
PaymentController controller,
|
||||
PaymentState state,
|
||||
double total,
|
||||
) {
|
||||
// A cash sale cannot complete until the cashier says what was handed over.
|
||||
final canComplete = controller.canConfirm;
|
||||
final reason = controller.blockedReason;
|
||||
|
||||
return SafeArea(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
@@ -599,13 +607,45 @@ class _PaymentScreenState extends ConsumerState<PaymentScreen> {
|
||||
],
|
||||
),
|
||||
).animate().shake(duration: 300.ms, hz: 3),
|
||||
if (reason != null && state.error == null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline_rounded,
|
||||
size: 15, color: AppColors.textTertiary),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
reason,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (state.activeMethod.needsChange)
|
||||
TextButton(
|
||||
onPressed: () => _setCash(controller.balanceDue),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 30),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
),
|
||||
),
|
||||
child: const Text('Exact',
|
||||
style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
PrimaryButton(
|
||||
label: 'Complete Sale',
|
||||
icon: Icons.check_circle_outline_rounded,
|
||||
large: true,
|
||||
tone: ButtonTone.success,
|
||||
busy: state.isProcessing,
|
||||
onPressed: cartEmpty ? null : _confirm,
|
||||
onPressed: canComplete ? _confirm : null,
|
||||
trailing: Text(
|
||||
Formatters.money(total),
|
||||
style: AppTypography.money(19, color: Colors.white),
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
import '../../customer/widgets/customer_capture_sheet.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import 'cart_line_tile.dart';
|
||||
import 'discount_sheet.dart';
|
||||
@@ -404,7 +405,16 @@ class _Actions extends ConsumerWidget {
|
||||
child: PrimaryButton(
|
||||
label: 'CHARGE',
|
||||
large: true,
|
||||
onPressed: enabled ? () => context.push(AppRoutes.payment) : null,
|
||||
onPressed: enabled
|
||||
? () async {
|
||||
// Ask once per bill, before payment. Skipping is one tap and
|
||||
// leaves the sale as walk-in.
|
||||
if (ref.read(cartControllerProvider).customer == null) {
|
||||
await showCustomerCaptureSheet(context);
|
||||
}
|
||||
if (context.mounted) context.push(AppRoutes.payment);
|
||||
}
|
||||
: null,
|
||||
trailing: enabled
|
||||
? Text(
|
||||
Formatters.money(cart.grandTotal),
|
||||
|
||||
@@ -19,9 +19,16 @@ class CustomerBar extends ConsumerWidget {
|
||||
);
|
||||
|
||||
return Container(
|
||||
height: AppSizes.customerBarHeight,
|
||||
// A hard height clipped the subtitle once it wrapped. Minimum height
|
||||
// keeps the strip its usual size but lets it grow if it must.
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: AppSizes.customerBarHeight,
|
||||
),
|
||||
color: AppColors.surface,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xxl),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
child: Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
@@ -63,11 +70,17 @@ class CustomerBar extends ConsumerWidget {
|
||||
Text(
|
||||
'${Formatters.mobile(customer.mobile)} · '
|
||||
'${customer.loyaltyPoints} pts',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: context.text.bodySmall,
|
||||
)
|
||||
else
|
||||
Text('No loyalty tracking for this sale',
|
||||
style: context.text.bodySmall),
|
||||
Text(
|
||||
'No loyalty tracking for this sale',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: context.text.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -24,11 +24,27 @@ class PageHeader extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final compact = layout.sidebarIsDrawer;
|
||||
|
||||
// Measured from the header's own box, not the window. The window can be
|
||||
// wide while this column is narrow — the sidebar and the docked bill both
|
||||
// take from it — which is how the status chrome ended up overflowing.
|
||||
return LayoutBuilder(
|
||||
builder: (context, box) {
|
||||
final showStatus = box.maxWidth >= 720;
|
||||
return _bar(context, ref, compact, showStatus);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bar(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
bool compact,
|
||||
bool showStatus,
|
||||
) {
|
||||
final module = ref.watch(activeModuleProvider);
|
||||
final now = ref.watch(clockProvider).value ?? DateTime.now();
|
||||
final compact = layout.sidebarIsDrawer;
|
||||
// Status chrome is the first thing dropped when width gets tight.
|
||||
final showStatus = MediaQuery.sizeOf(context).width >= 1180;
|
||||
|
||||
return Container(
|
||||
constraints: const BoxConstraints(minHeight: AppSizes.headerHeight),
|
||||
@@ -76,7 +92,7 @@ class PageHeader extends ConsumerWidget {
|
||||
const Spacer(),
|
||||
|
||||
if (showStatus) ...[
|
||||
const _LivePill(),
|
||||
_LivePill(offline: ref.watch(simulateOfflineProvider)),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Text(
|
||||
Formatters.time(now),
|
||||
@@ -139,7 +155,9 @@ class _Breadcrumb extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _LivePill extends StatefulWidget {
|
||||
const _LivePill();
|
||||
const _LivePill({required this.offline});
|
||||
|
||||
final bool offline;
|
||||
|
||||
@override
|
||||
State<_LivePill> createState() => _LivePillState();
|
||||
@@ -160,40 +178,48 @@ class _LivePillState extends State<_LivePill>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs + 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FadeTransition(
|
||||
opacity: _c,
|
||||
child: Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.success,
|
||||
shape: BoxShape.circle,
|
||||
final offline = widget.offline;
|
||||
final tone = offline ? AppColors.warning : AppColors.success;
|
||||
final surface =
|
||||
offline ? AppColors.warningSurface : AppColors.successSurface;
|
||||
|
||||
return Tooltip(
|
||||
message: offline
|
||||
? 'Simulate offline is ON in Settings — imports and syncs are being '
|
||||
'failed deliberately.'
|
||||
: 'Terminal is operating normally.',
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs + 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: surface,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FadeTransition(
|
||||
opacity: _c,
|
||||
child: Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: BoxDecoration(color: tone, shape: BoxShape.circle),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs + 2),
|
||||
const Text(
|
||||
'LIVE',
|
||||
style: TextStyle(
|
||||
color: AppColors.success,
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.8,
|
||||
const SizedBox(width: AppSpacing.xs + 2),
|
||||
Text(
|
||||
offline ? 'OFFLINE (SIM)' : 'LIVE',
|
||||
style: TextStyle(
|
||||
color: tone,
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.8,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,80 +62,114 @@ class _ProductCardState extends State<ProductCard> {
|
||||
: AppColors.shadowSm,
|
||||
),
|
||||
child: Stack(children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Opacity(
|
||||
opacity: disabled ? 0.4 : 1,
|
||||
child: Text(p.emoji,
|
||||
style: const TextStyle(fontSize: 40)),
|
||||
// The grid gives tiles a width derived from the viewport, so
|
||||
// on narrow screens they can be far shorter than the content's
|
||||
// natural height. Everything is sized from the box we actually
|
||||
// get rather than from fixed constants.
|
||||
LayoutBuilder(
|
||||
builder: (context, box) {
|
||||
final h = box.maxHeight;
|
||||
final tight = h < 170;
|
||||
|
||||
final emoji = (h * 0.22).clamp(20.0, 38.0);
|
||||
final nameSize = tight ? 12.0 : 13.5;
|
||||
final priceSize = tight ? 14.0 : 16.0;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(
|
||||
tight ? AppSpacing.sm : AppSpacing.md,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
p.name,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.25,
|
||||
color: disabled
|
||||
? AppColors.textTertiary
|
||||
: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs + 2),
|
||||
// Scales down rather than overflowing on small tiles.
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
Formatters.money(p.price),
|
||||
style: AppTypography.money(17,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Opacity(
|
||||
opacity: disabled ? 0.4 : 1,
|
||||
child: Text(
|
||||
p.emoji,
|
||||
style: TextStyle(fontSize: emoji),
|
||||
),
|
||||
),
|
||||
SizedBox(height: tight ? 2 : AppSpacing.sm),
|
||||
|
||||
// Flexible so a long name gives way instead of
|
||||
// pushing the price and stock line out of the tile.
|
||||
Flexible(
|
||||
child: Text(
|
||||
p.name,
|
||||
maxLines: tight ? 1 : 2,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: nameSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.2,
|
||||
color: disabled
|
||||
? AppColors.textTertiary
|
||||
: AppColors.primary),
|
||||
),
|
||||
if (p.hasDiscount) ...[
|
||||
const SizedBox(width: AppSpacing.xs + 2),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 1.5),
|
||||
child: Text(
|
||||
Formatters.money(p.mrp!),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
decoration: TextDecoration.lineThrough,
|
||||
),
|
||||
: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: tight ? 2 : AppSpacing.xs),
|
||||
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
Formatters.money(p.price),
|
||||
style: AppTypography.money(
|
||||
priceSize,
|
||||
color: disabled
|
||||
? AppColors.textTertiary
|
||||
: AppColors.primary,
|
||||
),
|
||||
),
|
||||
if (p.hasDiscount && !tight) ...[
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 1.5),
|
||||
child: Text(
|
||||
Formatters.money(p.mrp!),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AppColors.textTertiary,
|
||||
decoration:
|
||||
TextDecoration.lineThrough,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Dropped first when the tile is too short for it.
|
||||
if (h >= 140) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
disabled
|
||||
? 'Out of stock'
|
||||
: '${p.stock.toStringAsFixed(0)} in stock',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: disabled
|
||||
? AppColors.danger
|
||||
: (p.isLowStock
|
||||
? AppColors.warning
|
||||
: AppColors.textTertiary),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
disabled
|
||||
? 'Out of stock'
|
||||
: '${p.stock.toStringAsFixed(0)} in stock',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: disabled
|
||||
? AppColors.danger
|
||||
: (p.isLowStock
|
||||
? AppColors.warning
|
||||
: AppColors.textTertiary),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
if (p.hasDiscount && !disabled)
|
||||
|
||||
@@ -61,7 +61,10 @@ class ProductGrid extends ConsumerWidget {
|
||||
maxCrossAxisExtent: tileExtent,
|
||||
mainAxisSpacing: AppSpacing.md,
|
||||
crossAxisSpacing: AppSpacing.md,
|
||||
childAspectRatio: AppSizes.productCardAspect,
|
||||
// A fixed height, not a ratio. With childAspectRatio the tile grew
|
||||
// taller as the column got wider, leaving a large empty band under
|
||||
// every card on a full-screen window.
|
||||
mainAxisExtent: 186,
|
||||
),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, i) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../modules/providers/printer_settings.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../widgets/receipt_preview.dart';
|
||||
|
||||
@@ -37,6 +38,30 @@ class _ReceiptScreenState extends ConsumerState<ReceiptScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Auto-print is opt-in and only fires when a printer was actually
|
||||
// selected, so it can never fail invisibly on a terminal with none.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
final settings = ref.read(printerSettingsProvider);
|
||||
if (!settings.autoPrint || !settings.hasPrinter) return;
|
||||
|
||||
final ok = await ref.read(receiptServiceProvider).printDirect(
|
||||
widget.transaction,
|
||||
printerUrl: settings.printerUrl,
|
||||
);
|
||||
if (!ok && mounted) {
|
||||
_cancelAutoReturn();
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(const SnackBar(
|
||||
backgroundColor: AppColors.danger,
|
||||
content: Text(
|
||||
'Printer did not respond — use Print to send it again.',
|
||||
),
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (t) {
|
||||
if (!mounted) return;
|
||||
setState(() => _seconds--);
|
||||
@@ -182,31 +207,85 @@ class _ReceiptScreenState extends ConsumerState<ReceiptScreen> {
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Reprint',
|
||||
icon: Icons.print_outlined,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
_cancelAutoReturn();
|
||||
ref.read(receiptServiceProvider).printWithDialog(txn);
|
||||
},
|
||||
// Wrap, so three actions never overflow a narrow terminal.
|
||||
Wrap(
|
||||
spacing: AppSpacing.md,
|
||||
runSpacing: AppSpacing.md,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: PrimaryButton(
|
||||
label: 'Print',
|
||||
icon: Icons.print_outlined,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () async {
|
||||
_cancelAutoReturn();
|
||||
final settings = ref.read(printerSettingsProvider);
|
||||
final service = ref.read(receiptServiceProvider);
|
||||
|
||||
// Straight to the roll when one is configured; otherwise
|
||||
// the system preview, which works with no hardware.
|
||||
final printed = settings.hasPrinter &&
|
||||
await service.printDirect(
|
||||
txn,
|
||||
printerUrl: settings.printerUrl,
|
||||
);
|
||||
if (!printed) await service.printPreview(txn);
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 170,
|
||||
child: PrimaryButton(
|
||||
label: 'WhatsApp',
|
||||
icon: Icons.chat_rounded,
|
||||
tone: txn.customer == null
|
||||
? ButtonTone.neutral
|
||||
: ButtonTone.ghost,
|
||||
onPressed: txn.customer == null
|
||||
? null
|
||||
: () async {
|
||||
_cancelAutoReturn();
|
||||
final sent = await ref
|
||||
.read(receiptServiceProvider)
|
||||
.sendToWhatsApp(txn);
|
||||
if (!context.mounted || sent) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(const SnackBar(
|
||||
content: Text(
|
||||
'Could not open WhatsApp on this device.',
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 170,
|
||||
child: PrimaryButton(
|
||||
label: 'Share PDF',
|
||||
icon: Icons.ios_share_rounded,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
_cancelAutoReturn();
|
||||
ref.read(receiptServiceProvider).sharePdf(txn);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (txn.customer == null)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: AppSpacing.sm),
|
||||
child: Text(
|
||||
'No mobile number captured, so WhatsApp is unavailable for '
|
||||
'this bill.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Share',
|
||||
icon: Icons.ios_share_rounded,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
_cancelAutoReturn();
|
||||
ref.read(receiptServiceProvider).share(txn);
|
||||
},
|
||||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
PrimaryButton(
|
||||
label: _seconds > 0
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
|
||||
/// Paper-like preview of what the thermal printer produced.
|
||||
@@ -13,10 +14,33 @@ class ReceiptPreview extends StatelessWidget {
|
||||
|
||||
final SaleTransaction transaction;
|
||||
|
||||
/// Groups the bill by GST rate, mirroring how the printed invoice lists it.
|
||||
List<_PreviewSlab> _slabs(SaleTransaction txn) {
|
||||
final cart = txn.cart;
|
||||
final factor = cart.subtotal <= 0 ? 1.0 : cart.netAmount / cart.subtotal;
|
||||
|
||||
final grouped = <double, List<CartLine>>{};
|
||||
for (final line in cart.lines) {
|
||||
grouped.putIfAbsent(line.product.gstRate, () => []).add(line);
|
||||
}
|
||||
|
||||
final rates = grouped.keys.toList()..sort();
|
||||
return [
|
||||
for (var i = 0; i < rates.length; i++)
|
||||
_PreviewSlab(i + 1, rates[i], grouped[rates[i]]!, factor),
|
||||
];
|
||||
}
|
||||
|
||||
double _gross(SaleTransaction txn) => txn.cart.lines
|
||||
.fold(0.0, (s, l) => s + (l.product.mrp ?? l.product.price) * l.quantity);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final txn = transaction;
|
||||
final cart = txn.cart;
|
||||
final slabs = _slabs(txn);
|
||||
final gross = _gross(txn);
|
||||
final discount = gross - cart.netAmount;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -29,14 +53,15 @@ class ReceiptPreview extends StatelessWidget {
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xxl,
|
||||
vertical: AppSpacing.xl,
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: AppTypography.mono(11.5, color: AppColors.textPrimary),
|
||||
style: AppTypography.mono(10, color: AppColors.textPrimary),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// ------------------------------------------------ header
|
||||
Center(
|
||||
child: Column(children: [
|
||||
Text(
|
||||
@@ -44,117 +69,251 @@ class ReceiptPreview extends StatelessWidget {
|
||||
style: AppTypography.mono(15)
|
||||
.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(AppConstants.storeLegalName,
|
||||
style: AppTypography.mono(8.5)),
|
||||
const SizedBox(height: 2),
|
||||
Text(AppConstants.storeAddress,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTypography.mono(9.5)),
|
||||
Text('GSTIN: ${AppConstants.storeGstin}',
|
||||
style: AppTypography.mono(9.5)),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text('TAX INVOICE',
|
||||
style: AppTypography.mono(11.5)
|
||||
.copyWith(fontWeight: FontWeight.w700)),
|
||||
style: AppTypography.mono(8.5)),
|
||||
Text('Customer care : ${AppConstants.storePhone}',
|
||||
style: AppTypography.mono(8.5)),
|
||||
Text('CIN No : ${AppConstants.storeCin}',
|
||||
style: AppTypography.mono(8.5)),
|
||||
Text('GSTIN : ${AppConstants.storeGstin}',
|
||||
style: AppTypography.mono(8.5)),
|
||||
Text('FSSAI Lic No : ${AppConstants.storeFssai}',
|
||||
style: AppTypography.mono(8.5)),
|
||||
]),
|
||||
),
|
||||
|
||||
const _Dashes(),
|
||||
_row('Invoice', txn.invoiceNumber),
|
||||
_row('Date', Formatters.receiptStamp(txn.createdAt)),
|
||||
_row('Cashier', txn.cashierName),
|
||||
_row('Customer', txn.customer?.name ?? 'Walk-in'),
|
||||
|
||||
const _Dashes(),
|
||||
Row(children: [
|
||||
Expanded(flex: 5, child: _bold('Item')),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: _bold('Qty', align: TextAlign.center),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: _bold('Amount', align: TextAlign.right),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
|
||||
...cart.lines.map((line) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2.5),
|
||||
child: Row(children: [
|
||||
Expanded(flex: 5, child: Text(line.product.name)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
line.quantity % 1 == 0
|
||||
? line.quantity.toStringAsFixed(0)
|
||||
: line.quantity.toStringAsFixed(2),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
line.payable.toStringAsFixed(2),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
]),
|
||||
)),
|
||||
|
||||
const _Dashes(),
|
||||
_row('Subtotal', cart.subtotal.toStringAsFixed(2)),
|
||||
if (cart.billDiscountTotal > 0)
|
||||
_row('Discount',
|
||||
'-${cart.billDiscountTotal.toStringAsFixed(2)}'),
|
||||
if (cart.loyaltyRedemptionValue > 0)
|
||||
_row('Points redeemed',
|
||||
'-${cart.loyaltyRedemptionValue.toStringAsFixed(2)}'),
|
||||
_row('CGST', cart.cgst.toStringAsFixed(2)),
|
||||
_row('SGST', cart.sgst.toStringAsFixed(2)),
|
||||
if (cart.roundOff != 0)
|
||||
_row('Round off', cart.roundOff.toStringAsFixed(2)),
|
||||
|
||||
const _Dashes(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('TOTAL',
|
||||
style: AppTypography.mono(15).copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColors.textPrimary,
|
||||
)),
|
||||
Text(
|
||||
Formatters.money(txn.total),
|
||||
style: AppTypography.mono(15).copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
if (discount > 0) ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Center(
|
||||
child: Text(
|
||||
'You have saved Rs.${discount.toStringAsFixed(2)}',
|
||||
style: AppTypography.mono(11).copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const _Dashes(),
|
||||
...txn.payments.map((p) =>
|
||||
_row(p.method.label, p.amount.toStringAsFixed(2))),
|
||||
if (txn.changeDue > 0)
|
||||
_row('Change', txn.changeDue.toStringAsFixed(2)),
|
||||
Center(
|
||||
child: Column(children: [
|
||||
Text('TAX INVOICE',
|
||||
style: AppTypography.mono(11)
|
||||
.copyWith(fontWeight: FontWeight.w700)),
|
||||
Text('xxxxxx Original for Recipient xxxxxx',
|
||||
style: AppTypography.mono(8)),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
|
||||
if (txn.customer != null) ...[
|
||||
const _Dashes(),
|
||||
_row('Points earned', '+${txn.pointsEarned}'),
|
||||
_row('Membership', txn.customer!.tier.label),
|
||||
// -------------------------------------------------- meta
|
||||
_plain('Place of Supply & State Code: '
|
||||
'${AppConstants.stateCode} ${AppConstants.stateName}'),
|
||||
_plain('Customer Type: '
|
||||
'${txn.customer == null ? 'URD' : 'REG'}'),
|
||||
_row('Date:${Formatters.receiptStamp(txn.createdAt)}',
|
||||
'Bill No:${txn.invoiceNumber.split('-').last}'),
|
||||
_row(
|
||||
'Store:${AppConstants.storeCode} '
|
||||
'Cashier:${txn.cashierName}',
|
||||
'Pos:${AppConstants.posNumber}',
|
||||
),
|
||||
if (txn.customer != null)
|
||||
_plain('Customer: ${txn.customer!.name} '
|
||||
'${txn.customer!.mobile}'),
|
||||
|
||||
const _Dashes(),
|
||||
|
||||
// ------------------------------------------------- items
|
||||
Row(children: [
|
||||
Expanded(flex: 12, child: _bold('HSN')),
|
||||
Expanded(flex: 34, child: _bold('Item Description')),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _bold('Net Price', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 8, child: _bold('Qty', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 18,
|
||||
child: _bold('Value', align: TextAlign.right)),
|
||||
]),
|
||||
const SizedBox(height: 3),
|
||||
|
||||
for (final slab in slabs) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 5, bottom: 2),
|
||||
child: Text(
|
||||
'${slab.index}) CGST @ ${slab.halfPercent} '
|
||||
'SGST @ ${slab.halfPercent}',
|
||||
style: AppTypography.mono(9).copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final line in slab.lines)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1.5),
|
||||
child: Row(children: [
|
||||
Expanded(
|
||||
flex: 12,
|
||||
child: _cell(line.product.hsnCode ?? '-')),
|
||||
Expanded(
|
||||
flex: 34,
|
||||
child:
|
||||
_cell(line.product.name.toUpperCase())),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _cell(
|
||||
line.product.price.toStringAsFixed(2),
|
||||
align: TextAlign.right),
|
||||
),
|
||||
Expanded(
|
||||
flex: 8,
|
||||
child: _cell(_qty(line.quantity),
|
||||
align: TextAlign.right),
|
||||
),
|
||||
Expanded(
|
||||
flex: 18,
|
||||
child: _cell(line.payable.toStringAsFixed(2),
|
||||
align: TextAlign.right),
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
|
||||
const _Dashes(),
|
||||
|
||||
// ------------------------------------------------ totals
|
||||
_row('Items:${cart.lineCount}',
|
||||
'Qty:${_qty(cart.totalQuantity)} '
|
||||
'${cart.netAmount.toStringAsFixed(2)}'),
|
||||
const SizedBox(height: 3),
|
||||
_amount('Gross Sales Value', gross),
|
||||
if (discount > 0) _amount('Total Discount', discount),
|
||||
_amount(
|
||||
'Net Sales Value (Inclusive of GST)', cart.netAmount),
|
||||
if (cart.roundOff != 0)
|
||||
_amount('Round Off', cart.roundOff),
|
||||
_amount('Total Amount Paid', txn.total, bold: true),
|
||||
for (final p in txn.payments)
|
||||
_amount(p.method.label.toUpperCase(), p.amount),
|
||||
if (txn.changeDue > 0)
|
||||
_amount('Change Returned', txn.changeDue),
|
||||
Text('(AMOUNT INCLUSIVE OF APPLICABLE TAXES)',
|
||||
style: AppTypography.mono(8)),
|
||||
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
|
||||
// ------------------------------------------- gst breakup
|
||||
Center(
|
||||
child: Text('------GST Breakup Details------ Amount (INR)',
|
||||
style: AppTypography.mono(8.5)),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(children: [
|
||||
Expanded(flex: 10, child: _bold('GST')),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _bold('Taxable', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _bold('CGST', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _bold('SGST', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 14,
|
||||
child: _bold('CESS', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _bold('Total', align: TextAlign.right)),
|
||||
]),
|
||||
const SizedBox(height: 2),
|
||||
for (final s in slabs)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1),
|
||||
child: Row(children: [
|
||||
Expanded(flex: 10, child: _cell('${s.index}')),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _cell(s.taxable.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _cell(s.cgst.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _cell(s.sgst.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 14,
|
||||
child: _cell('0.00', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _cell(s.total.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
]),
|
||||
),
|
||||
const _Dashes(),
|
||||
Row(children: [
|
||||
Expanded(flex: 10, child: _bold('Total')),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _bold(
|
||||
slabs
|
||||
.fold(0.0, (a, s) => a + s.taxable)
|
||||
.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _bold(
|
||||
slabs
|
||||
.fold(0.0, (a, s) => a + s.cgst)
|
||||
.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 16,
|
||||
child: _bold(
|
||||
slabs
|
||||
.fold(0.0, (a, s) => a + s.sgst)
|
||||
.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 14,
|
||||
child: _bold('0.00', align: TextAlign.right)),
|
||||
Expanded(
|
||||
flex: 20,
|
||||
child: _bold(
|
||||
slabs
|
||||
.fold(0.0, (a, s) => a + s.total)
|
||||
.toStringAsFixed(2),
|
||||
align: TextAlign.right)),
|
||||
]),
|
||||
|
||||
const _Dashes(),
|
||||
_plain('TaxInvoice# ${txn.invoiceNumber}'),
|
||||
if (txn.customer != null)
|
||||
_plain('Loyalty Pts: earned ${txn.pointsEarned} '
|
||||
'Bal: ${txn.customer!.loyaltyPoints - txn.pointsRedeemed + txn.pointsEarned}'),
|
||||
_plain('Terms & Conditions Apply'),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Center(
|
||||
child: Column(children: [
|
||||
_FakeBarcode(value: txn.invoiceNumber),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text('Thank you for shopping with us!',
|
||||
style: AppTypography.mono(11)
|
||||
Text('* Thank You for Shopping with us *',
|
||||
style: AppTypography.mono(10)
|
||||
.copyWith(fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 2),
|
||||
Text('Powered by Nearle POS',
|
||||
style: AppTypography.mono(9)),
|
||||
style: AppTypography.mono(8)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
@@ -167,22 +326,97 @@ class ReceiptPreview extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1.5),
|
||||
String _qty(double q) =>
|
||||
q % 1 == 0 ? q.toStringAsFixed(0) : q.toStringAsFixed(3);
|
||||
|
||||
Widget _plain(String text) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 0.8),
|
||||
child: Text(text, style: AppTypography.mono(9)),
|
||||
);
|
||||
|
||||
Widget _row(String left, String right) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 0.8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [Text(label), Text(value)],
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTypography.mono(9)),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(right, style: AppTypography.mono(9)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _amount(String label, double value, {bool bold = false}) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTypography.mono(9.5).copyWith(
|
||||
fontWeight: bold ? FontWeight.w700 : FontWeight.w400,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
value.toStringAsFixed(2),
|
||||
style: AppTypography.mono(9.5).copyWith(
|
||||
fontWeight: bold ? FontWeight.w700 : FontWeight.w400,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _bold(String text, {TextAlign align = TextAlign.left}) => Text(
|
||||
text,
|
||||
textAlign: align,
|
||||
style: AppTypography.mono(11.5).copyWith(
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
style: AppTypography.mono(8.5).copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cell(String text, {TextAlign align = TextAlign.left}) => Text(
|
||||
text,
|
||||
textAlign: align,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTypography.mono(8.5),
|
||||
);
|
||||
}
|
||||
|
||||
/// One GST rate's slice of the bill, for the preview.
|
||||
class _PreviewSlab {
|
||||
const _PreviewSlab(this.index, this.rate, this.lines, this.factor);
|
||||
|
||||
final int index;
|
||||
final double rate;
|
||||
final List<CartLine> lines;
|
||||
final double factor;
|
||||
|
||||
String get halfPercent => '${(rate * 100 / 2).toStringAsFixed(2)}%';
|
||||
|
||||
double get total => lines.fold(0.0, (s, l) => s + l.payable * factor);
|
||||
|
||||
double get taxAmount => lines.fold(0.0, (s, l) => s + l.taxAmount * factor);
|
||||
|
||||
double get taxable => total - taxAmount;
|
||||
|
||||
double get cgst => taxAmount / 2;
|
||||
|
||||
double get sgst => taxAmount - cgst;
|
||||
}
|
||||
|
||||
class _Dashes extends StatelessWidget {
|
||||
|
||||
@@ -80,6 +80,9 @@ class CatalogueImportController extends StateNotifier<ImportState> {
|
||||
state = ImportFailed(event.error ?? 'Import failed.');
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Drops a stale success or failure banner.
|
||||
void reset() => state = const ImportIdle();
|
||||
}
|
||||
|
||||
final catalogueImportProvider =
|
||||
|
||||
Reference in New Issue
Block a user