added local db

This commit is contained in:
2026-07-29 13:06:39 +05:30
parent d72522e737
commit d9886880cc
38 changed files with 2895 additions and 2261 deletions

View File

@@ -7,9 +7,9 @@ import '../../../core/theme/app_colors.dart';
import '../../../core/theme/app_dimens.dart';
import '../../../core/utils/formatters.dart';
import '../../../core/widgets/primary_button.dart';
import '../../../domain/entities/sync_event.dart';
import '../../auth/providers/auth_controller.dart';
import '../../pos/providers/cart_controller.dart';
import '../../../domain/repositories/sync_repository.dart';
import '../providers/sync_controller.dart';
/// End-of-shift flow.
@@ -33,7 +33,7 @@ class _SignOutDialog extends ConsumerStatefulWidget {
}
class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
SyncEvent? _result;
SyncOutcome? _result;
void _finish() {
ref.read(cartControllerProvider.notifier).reset();
@@ -43,12 +43,12 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
}
Future<void> _pushThenFinish() async {
final event = await ref.read(reportPushProvider.notifier).pushToday();
final outcome = await ref.read(orderSyncProvider.notifier).run();
if (!mounted) return;
setState(() => _result = event);
setState(() => _result = outcome);
if (event.status == SyncStatus.synced) {
if (outcome.isSuccess) {
await Future<void>.delayed(const Duration(milliseconds: 700));
if (mounted) _finish();
}
@@ -56,10 +56,11 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
@override
Widget build(BuildContext context) {
final report = ref.watch(shiftReportProvider);
final report = ref.watch(todayReportProvider).value;
final pending = ref.watch(unsyncedCountProvider).value ?? 0;
final cart = ref.watch(cartControllerProvider);
final pushing = ref.watch(reportPushProvider);
final failed = _result?.status == SyncStatus.failed;
final pushing = ref.watch(orderSyncProvider) is SyncRunning;
final failed = _result != null && !_result!.isSuccess;
return AlertDialog(
title: const Text('End shift'),
@@ -70,7 +71,8 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
AppSpacing.sm,
),
content: SizedBox(
width: 420,
// Never wider than the viewport allows.
width: (MediaQuery.sizeOf(context).width - 96).clamp(280.0, 420.0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -85,17 +87,17 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
'and will be cleared. Park it first if you need it.',
),
if (report.isEmpty)
if (pending == 0)
const _Banner(
icon: Icons.info_outline_rounded,
color: AppColors.textSecondary,
background: AppColors.surfaceAlt,
message: 'No sales were recorded today, so there is nothing '
'to push.',
icon: Icons.check_circle_outline_rounded,
color: AppColors.success,
background: AppColors.successSurface,
message: 'Every bill has already been uploaded. Nothing is '
'waiting on this terminal.',
)
else ...[
const Text(
"Today's takings",
'Waiting to upload',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
@@ -103,12 +105,14 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
),
),
const SizedBox(height: AppSpacing.sm),
_row('Bills', '${report.billCount}'),
_row('Items sold', report.itemCount.toStringAsFixed(0)),
_row('Gross sales', Formatters.money(report.grossSales)),
_row('GST collected', Formatters.money(report.taxCollected)),
_row('Average basket',
Formatters.money(report.averageBasket)),
_row('Bills pending sync', '$pending'),
if (report != null) ...[
_row('Bills today', '${report.billCount}'),
_row('Items sold', report.itemCount.toStringAsFixed(0)),
_row('Gross sales', Formatters.money(report.grossSales)),
_row('GST collected',
Formatters.money(report.taxCollected)),
],
],
if (failed) ...[
@@ -118,7 +122,7 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
color: AppColors.danger,
background: AppColors.dangerSurface,
message: _result?.error ??
'The push failed. The report is still saved on this '
'Upload failed. Every bill is still stored on this '
'terminal and can be retried from Events.',
),
],
@@ -149,14 +153,14 @@ class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
foregroundColor: AppColors.textSecondary,
),
child: Text(
report.isEmpty ? 'Sign out' : 'Sign out without pushing',
pending == 0 ? 'Sign out' : 'Sign out without syncing',
),
),
if (!report.isEmpty)
if (pending > 0)
SizedBox(
width: 190,
child: PrimaryButton(
label: failed ? 'Retry push' : 'Push & sign out',
label: failed ? 'Retry sync' : 'Sync & sign out',
icon: Icons.cloud_upload_rounded,
busy: pushing,
onPressed: _pushThenFinish,