feat(carwash): Car Wash v1 + per-till shifts + site-level pay-at + till access by module permission
Car Wash — the pilot venue module (wiki/decisions/venue-modules.md): - Master data (categories × services price matrix) at /setup/carwash; the desk at /wash (ticket lookup → order; open queue oldest-first: Done / Paid cash / Paid card / Void; Finished list). Orders freeze names + price; their life is signed (carwash_order, carwash_payment). Migration 0027. - Where money is taken is a SITE setting (carwash_config.pay_at, migration 0028, signed config_change on a flip) — no per-order radio; a stale client is refused (409). - Core seams: PayStation charge providers (a booth-paid wash rides the parking payment as chargeLines) + applyValidation() shared with the merchant route. A bay-paid, done wash signs the $0 parking payment so the exit reader releases the car. - "Parking discount" modes for the wash: free while the wash runs (+ tolerance) and wash price off the fee (floored at 0), resolved at done and anchored at the order's intake (the entry-anchored version comped a 74-day stay); typed-amount and percent hidden for the wash. Long durations render y/d/h/m. Tills — a shift belongs to a till, not the site (wiki/concepts/shift.md §Tills): - TillId booth|carwash; every money event names its till (absent = booth, so the chain re-folds identically). ShiftService is per till: single-open, folds, X/Z-reports, vouchers, carry-forward. A bay payment needs the carwash shift. - Working a till needs that till's module permission (manifest tillPermission; 403 till_forbidden); /api/shift/tills lists only the role's tills. - Web: ShiftButton per till (header = booth, wash desk = carwash); shift hub lists every open shift with till badges + filter; drawer hub switches tills. Modules: landing per module (index route resolves booth → module landing → shifts → profile); guards bounce to "/", /booth needs session:read. Tests: carwash e2e suite (settings, intake, booth/bay paths, modes, void, gate, pay-at policy, till permissions), 6 per-till shift tests; suite green (1 pre-existing flaky backup test under the parallel run). Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
This commit is contained in:
+58
-22
@@ -16,7 +16,7 @@ import { getDesktopCsrfToken, setDesktopCsrfToken } from "./lib/desktop-csrf.js"
|
||||
import { logFailedRequest } from "./lib/logger.js";
|
||||
import { apiUrl, platformFetch } from "./lib/origin.js";
|
||||
import { inTauri } from "./lib/tauri-env.js";
|
||||
import type { AppLogRecord, ModuleId, ValidationLine, ValidationMode } from "@parking/shared";
|
||||
import type { AppLogRecord, ChargeLine, ModuleId, TillId, ValidationLine, ValidationMode } from "@parking/shared";
|
||||
|
||||
const CSRF_COOKIE = "parking_csrf";
|
||||
const CSRF_HEADER = "X-CSRF-Token";
|
||||
@@ -1062,18 +1062,30 @@ export function deleteSubscription(id: string): Promise<void> {
|
||||
}
|
||||
|
||||
// --- Shifts ---------------------------------------------------------------
|
||||
// A shift is opened ON A TILL (booth | carwash …): one open shift per till, each with
|
||||
// its own drawer and Z-report. Every call below takes the till, defaulting to the
|
||||
// booth. See wiki/concepts/shift.md "Tills".
|
||||
|
||||
export interface ShiftStatus {
|
||||
/** The requesting (logged-in) operator. */
|
||||
operator: string;
|
||||
/** The SINGLE site-wide open shift (startedAt + whose), or null if none open. */
|
||||
export type { TillId };
|
||||
|
||||
/** One till's shift state (at most one shift open per till). */
|
||||
export interface TillShiftStatus {
|
||||
till: TillId;
|
||||
/** The till's open shift (startedAt + whose), or null if none open. */
|
||||
open: { startedAt: string; operator: string | null } | null;
|
||||
/** True iff the open shift belongs to the requesting operator (can close it). */
|
||||
isMine: boolean;
|
||||
/** Live physical drawer balance (cash payments + cash movements). */
|
||||
/** Live physical drawer balance of this till (cash payments + cash movements). */
|
||||
drawerMinor: number;
|
||||
currency: string | null;
|
||||
}
|
||||
|
||||
export interface ShiftStatus extends TillShiftStatus {
|
||||
/** The requesting (logged-in) operator. */
|
||||
operator: string;
|
||||
/** Every till addressable at this site (the booth + effective modules' tills). */
|
||||
tills: TillId[];
|
||||
}
|
||||
/** Takings split by SOURCE — transient tickets vs subscriber money (monthly sales +
|
||||
* out-of-window charges). Cash+card combined; the per-tender totals stay separate for
|
||||
* the drawer. Shared by the X-report, the close Z-report, and the history summary. */
|
||||
@@ -1085,6 +1097,7 @@ export interface ShiftSourceSplit {
|
||||
}
|
||||
|
||||
export interface ShiftReport extends ShiftSourceSplit {
|
||||
till: TillId;
|
||||
operator: string;
|
||||
startedAt: string;
|
||||
endedAt: string;
|
||||
@@ -1100,20 +1113,27 @@ export interface ShiftReport extends ShiftSourceSplit {
|
||||
printed: boolean;
|
||||
}
|
||||
|
||||
export function fetchShift(): Promise<ShiftStatus> {
|
||||
return apiFetch("/api/shift/current");
|
||||
const tillQs = (till?: TillId) => (till && till !== "booth" ? `?till=${till}` : "");
|
||||
|
||||
export function fetchShift(till: TillId = "booth"): Promise<ShiftStatus> {
|
||||
return apiFetch(`/api/shift/current${tillQs(till)}`);
|
||||
}
|
||||
export function openShift(): Promise<{ startedAt: string; openingFloatMinor: number }> {
|
||||
return apiFetch("/api/shift/open", { method: "POST" });
|
||||
/** Every till's shift state in one read (the shift hub lists each open shift). */
|
||||
export function fetchShiftTills(): Promise<{ operator: string; tills: TillShiftStatus[] }> {
|
||||
return apiFetch("/api/shift/tills");
|
||||
}
|
||||
export function closeShift(): Promise<ShiftReport> {
|
||||
return apiFetch("/api/shift/close", { method: "POST" });
|
||||
export function openShift(till: TillId = "booth"): Promise<{ startedAt: string; till: TillId; openingFloatMinor: number }> {
|
||||
return apiFetch("/api/shift/open", { method: "POST", body: JSON.stringify({ till }) });
|
||||
}
|
||||
export function closeShift(till: TillId = "booth"): Promise<ShiftReport> {
|
||||
return apiFetch("/api/shift/close", { method: "POST", body: JSON.stringify({ till }) });
|
||||
}
|
||||
|
||||
/** Mid-shift X-report: the open shift's takings + drawer "so far" (read-only — no
|
||||
* event is appended). Same figures the Z-report will print at close. `asOf` is the
|
||||
* snapshot instant. */
|
||||
export interface XReport extends ShiftSourceSplit {
|
||||
till: TillId;
|
||||
operator: string;
|
||||
startedAt: string;
|
||||
endedAt: string; // = asOf
|
||||
@@ -1129,8 +1149,8 @@ export interface XReport extends ShiftSourceSplit {
|
||||
}
|
||||
|
||||
/** Fetch the mid-shift X-report; resolves to null when no shift is open (204). */
|
||||
export async function fetchShiftReport(): Promise<XReport | null> {
|
||||
return (await apiFetch<XReport | undefined>("/api/shift/report")) ?? null;
|
||||
export async function fetchShiftReport(till: TillId = "booth"): Promise<XReport | null> {
|
||||
return (await apiFetch<XReport | undefined>(`/api/shift/report${tillQs(till)}`)) ?? null;
|
||||
}
|
||||
|
||||
// --- Drawer cash movements (operator records, admin reviews) ---------------------
|
||||
@@ -1144,6 +1164,8 @@ export type MovementStatus = "pending" | "authorized" | "denied";
|
||||
export interface DrawerMovement {
|
||||
id: string;
|
||||
type: "cash_in" | "cash_out";
|
||||
/** Which drawer the cash moved in/out of. */
|
||||
till: TillId;
|
||||
/** Positive magnitude; direction is the type. */
|
||||
amountMinor: number;
|
||||
currency: string | null;
|
||||
@@ -1165,8 +1187,11 @@ export function recordDrawerMovement(args: {
|
||||
amountMinor: number;
|
||||
reason: string;
|
||||
currency?: string;
|
||||
/** Which drawer (default: the booth). */
|
||||
till?: TillId;
|
||||
}): Promise<{
|
||||
type: "cash_in" | "cash_out";
|
||||
till: TillId;
|
||||
amountMinor: number;
|
||||
voucherNo: string;
|
||||
balanceMinor: number;
|
||||
@@ -1177,18 +1202,21 @@ export function recordDrawerMovement(args: {
|
||||
|
||||
/** List drawer movements + review status. Operators get their OWN; a reviewer gets all
|
||||
* and may filter by status (the pending review queue). */
|
||||
export function fetchDrawerMovements(status?: MovementStatus): Promise<{
|
||||
export function fetchDrawerMovements(status?: MovementStatus, till?: TillId): Promise<{
|
||||
movements: DrawerMovement[];
|
||||
scope: "all" | "self";
|
||||
}> {
|
||||
const qs = status ? `?status=${encodeURIComponent(status)}` : "";
|
||||
return apiFetch(`/api/drawer/movements${qs}`);
|
||||
const qs = new URLSearchParams();
|
||||
if (status) qs.set("status", status);
|
||||
if (till) qs.set("till", till);
|
||||
const q = qs.toString();
|
||||
return apiFetch(`/api/drawer/movements${q ? `?${q}` : ""}`);
|
||||
}
|
||||
|
||||
/** The physical drawer balance NOW (cash payments + vouchers over the whole chain —
|
||||
* the amount that carries across shifts). */
|
||||
export function fetchDrawerBalance(): Promise<{ balanceMinor: number; currency: string | null }> {
|
||||
return apiFetch("/api/drawer/balance");
|
||||
/** A till's physical drawer balance NOW (cash payments + vouchers over the whole chain
|
||||
* — the amount that carries across that till's shifts). */
|
||||
export function fetchDrawerBalance(till: TillId = "booth"): Promise<{ till: TillId; balanceMinor: number; currency: string | null }> {
|
||||
return apiFetch(`/api/drawer/balance${tillQs(till)}`);
|
||||
}
|
||||
|
||||
/** Admin AUTHORIZES or DENIES a recorded movement (a flag — never a cash reversal). */
|
||||
@@ -1204,6 +1232,8 @@ export function reviewDrawerMovement(args: {
|
||||
export interface ShiftSummary extends ShiftSourceSplit {
|
||||
id: string;
|
||||
index: number;
|
||||
/** The till this shift reconciled. */
|
||||
till: TillId;
|
||||
operator: string;
|
||||
startedAt: string;
|
||||
endedAt: string;
|
||||
@@ -1221,16 +1251,19 @@ export interface ShiftSummary extends ShiftSourceSplit {
|
||||
* own shifts only (filter args ignored); admins (shift:cash) get all, optionally
|
||||
* filtered by operator + a from/to window over the shift start. `scope` echoes
|
||||
* which the server applied, so the UI can show/hide the filter. */
|
||||
export function fetchShifts(params: { operator?: string; from?: string; to?: string } = {}): Promise<{
|
||||
export function fetchShifts(params: { operator?: string; from?: string; to?: string; till?: TillId } = {}): Promise<{
|
||||
shifts: ShiftSummary[];
|
||||
scope: "all" | "self";
|
||||
/** Admin scope only: every operator that has a shift — feeds the filter dropdown. */
|
||||
operators?: string[];
|
||||
/** Every till addressable at this site — more than one → show the till filter/badges. */
|
||||
tills: TillId[];
|
||||
}> {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.operator) qs.set("operator", params.operator);
|
||||
if (params.from) qs.set("from", params.from);
|
||||
if (params.to) qs.set("to", params.to);
|
||||
if (params.till) qs.set("till", params.till);
|
||||
const q = qs.toString();
|
||||
return apiFetch(`/api/shifts${q ? `?${q}` : ""}`);
|
||||
}
|
||||
@@ -1359,6 +1392,9 @@ export interface SessionLookup {
|
||||
grossMinor: number | null;
|
||||
discountMinor: number | null;
|
||||
validationLines: ValidationLine[];
|
||||
/** Module charges folded into `amountMinor` (e.g. a car wash paid at the booth). */
|
||||
chargeLines: ChargeLine[];
|
||||
chargesMinor: number | null;
|
||||
}
|
||||
|
||||
/** Look up a ticket/session for the booth modal (entry/exit, paid, amount owed). */
|
||||
|
||||
Reference in New Issue
Block a user