third commit

This commit is contained in:
2026-07-31 17:06:52 +05:30
parent d9886880cc
commit 9891a69a5f
32 changed files with 2083 additions and 557 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:uuid/uuid.dart';
import '../../core/utils/formatters.dart';
@@ -99,14 +101,37 @@ class SyncRepositoryImpl implements SyncRepository {
required String cashierName,
}) async {
final today = DateTime.now();
final orders = await _store.orders.forBusinessDate(today);
return ShiftReport.fromTransactions(
transactions: orders,
// Bills still held locally.
final live = ShiftReport.fromTransactions(
transactions: await _store.orders.forBusinessDate(today),
businessDate: today,
terminalId: terminalId,
cashierName: cashierName,
);
// Bills already uploaded and deleted survive only as archived totals.
final row = await _store.orders.dayArchive(today);
if (row == null) return live;
final payments = (jsonDecode(row['payments_json']! as String)
as Map<String, Object?>)
.map(
(k, v) => MapEntry(
PaymentMethod.values.byName(k),
(v! as num).toDouble(),
),
);
final archived = ShiftReport.fromArchive(
row: row,
payments: payments,
businessDate: today,
terminalId: terminalId,
cashierName: cashierName,
);
return archived + live;
}
@override
@@ -152,10 +177,13 @@ class SyncRepositoryImpl implements SyncRepository {
pending.map(_orderToPayload).toList(),
);
onProgress?.call(0.85, 'Marking bills as synced');
onProgress?.call(0.85, 'Clearing uploaded bills from this terminal');
// Only what the server confirmed is flipped to 1.
await _store.orders.markSynced(accepted);
// Only what the server confirmed is archived and removed. Anything it
// did not acknowledge stays on disk.
final acceptedOrders =
pending.where((o) => accepted.contains(o.id)).toList();
await _store.orders.archiveAndDelete(acceptedOrders);
await _store.refreshUnsyncedCount();
final rejected = ids.where((id) => !accepted.contains(id)).toList();