removed files

This commit is contained in:
2026-08-28 11:03:56 +05:30
parent bf4dc4e888
commit 9f64b42f8a
13 changed files with 291 additions and 76 deletions

View File

@@ -122,6 +122,52 @@ export function orderQuantity(row: { quantity?: number; itemcount?: number }): n
return row.quantity || row.itemcount || 0;
}
/**
* A till clock running a few minutes off is ordinary and not worth correcting.
* Beyond this, a `billedat` in the future is a timezone fault, not drift.
*/
const CLOCK_TOLERANCE_MS = 5 * 60_000;
/**
* When the sale was actually rung, as a real instant.
*
* `billedat` cannot be trusted as sent. Most terminals stamp it with LOCAL
* wall-clock time and then label it `Z`, so a sale rung at 17:17 IST arrives as
* `2026-08-27T17:17:39Z` — five and a half hours in the future. Measured across
* location 1185: 19 of 20 bills had `billedat` ahead of `receivedat`, which is
* impossible, since a bill cannot be rung after the server received it. One
* terminal (`TB0B5`) sends correct UTC, so the fleet cannot be corrected
* wholesale either.
*
* `receivedat` is stamped by Fiesta and is therefore sound, and it gives a
* test that needs no knowledge of which terminal is which: if `billedat` is
* later than `receivedat` by more than clock drift, the digits are local time
* wearing a `Z`, and reading them back in the viewer's zone recovers the
* instant. The console and the shops it serves are in the same zone, so
* `getTimezoneOffset` is the offset that was dropped.
*
* The correction is applied only when it actually resolves the impossibility;
* a bill that is still in the future afterwards is something else, and guessing
* further would be inventing data. Everything else passes through untouched —
* which means this quietly stops correcting the day the POS team stamps UTC.
*/
export function billedAtMs(bill: { billedat?: string; receivedat?: string }): number | null {
if (!bill.billedat) return null;
const billed = new Date(bill.billedat).getTime();
if (Number.isNaN(billed)) return null;
if (!bill.receivedat) return billed;
const received = new Date(bill.receivedat).getTime();
if (Number.isNaN(received)) return billed;
if (billed <= received + CLOCK_TOLERANCE_MS) return billed;
// `getTimezoneOffset` is (UTC − local) in minutes: −330 for IST. Adding it
// turns wall-clock-read-as-UTC back into the instant it stood for.
const corrected = billed + new Date(billed).getTimezoneOffset() * 60_000;
return corrected <= received + CLOCK_TOLERANCE_MS ? corrected : billed;
}
/**
* How far behind a counter bill was when it reached us.
*
@@ -129,15 +175,21 @@ export function orderQuantity(row: { quantity?: number; itemcount?: number }): n
* gap means the till was offline and caught up later, and it is worth showing
* on the row: a day's takings that all arrived at 6pm did not happen at 6pm.
*
* Measured against `billedAtMs`, not the raw stamp. Read raw, every skewed bill
* produced a NEGATIVE lag — which fell under the threshold and returned null,
* so this reported "synced on time" for all twenty bills at location 1185 and
* would have gone on doing so through a real outage. Silent wrong is worse
* than blank.
*
* Returns null when the gap is under a minute (normal) or when either stamp is
* missing — a bill with no `receivedat` predates the field, and calling that
* "0 seconds late" would be a claim the data does not support.
*/
export function syncLagMs(bill: { billedat?: string; receivedat?: string }): number | null {
if (!bill.billedat || !bill.receivedat) return null;
const billed = new Date(bill.billedat).getTime();
const billed = billedAtMs(bill);
const received = new Date(bill.receivedat).getTime();
if (Number.isNaN(billed) || Number.isNaN(received)) return null;
if (billed === null || Number.isNaN(received)) return null;
const lag = received - billed;
return lag >= 60_000 ? lag : null;
}