Upload shopper registrations, and charge GST to the lines that earned it
Two defects that share a shape: a figure landing on the wrong record.
Bill-level discounts were apportioned across every line by a single
factor, so "20% off Beverages" pulled tax out of the atta line as well.
The bill total was right either way, which is what made it easy to ship
— only the slab split on a filed return was wrong. Targeted campaigns
now reduce the lines they name, and bill-wide reductions still spread
pro rata, so the arithmetic is unchanged wherever it was already right.
Shoppers registered at a till only ever reached the back office as three
fields riding along on a bill. Somebody who signed up and bought nothing
existed on one terminal and nowhere else, and two tills registering the
same mobile each minted their own row. Customers are now an outbox of
their own on pos/{store}/{terminal}/customer, and the id is a UUIDv5
over the normalised mobile number — so a hundred terminals agree on who
a shopper is without talking to each other.
Registrations go up before bills, and a failure there cannot strand a
day's takings. No loyalty figures are sent: they belong to the bill
stream, which is idempotent and knows about every counter.
Two things found while building it. Numbers were keyed on raw digits, so
a cashier typing +91 forked a shopper as effectively as a random id
would. And the sale path wrote the customer with ConflictAlgorithm
.replace, which is a DELETE and an INSERT — every column absent from the
row reverts to its schema default, so the new sync flag would have been
cleared by the shopper's next purchase.
Schema v8. Existing customers are queued rather than assumed sent: the
terminal cannot tell an imported row from a locally registered one, and
only one of those mistakes loses somebody.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,7 @@ class LocalStore {
|
||||
DateTime? _lastImportAt;
|
||||
String? _catalogueRevision;
|
||||
int _unsyncedOrders = 0;
|
||||
int _unsyncedCustomers = 0;
|
||||
|
||||
bool _ready = false;
|
||||
|
||||
@@ -92,6 +93,7 @@ class LocalStore {
|
||||
_catalogueRevision = await catalogue.meta(MetaKeys.catalogueRevision);
|
||||
terminal = await identityStore.load();
|
||||
_unsyncedOrders = await orders.unsyncedCount();
|
||||
_unsyncedCustomers = await catalogue.unsyncedCustomerCount();
|
||||
|
||||
_syncEvents
|
||||
..clear()
|
||||
@@ -239,11 +241,20 @@ class LocalStore {
|
||||
Future<void> putCustomer(Customer c) async {
|
||||
await catalogue.upsertCustomer(c);
|
||||
_customers[c.id] = c;
|
||||
await refreshUnsyncedCustomerCount();
|
||||
}
|
||||
|
||||
/// Mirrors a customer already written to disk into the memory cache.
|
||||
void cacheCustomer(Customer c) => _customers[c.id] = c;
|
||||
|
||||
/// Shoppers registered here and not yet uploaded.
|
||||
int get unsyncedCustomers => _unsyncedCustomers;
|
||||
|
||||
Future<int> refreshUnsyncedCustomerCount() async {
|
||||
_unsyncedCustomers = await catalogue.unsyncedCustomerCount();
|
||||
return _unsyncedCustomers;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- Orders
|
||||
/// Refreshes the cached unsynced tally after a write or a sync.
|
||||
Future<int> refreshUnsyncedCount() async {
|
||||
|
||||
Reference in New Issue
Block a user