feat(exit): forgiven exit — open the exit barrier with no payment (barrier:create)
Build & push images / images (push) Successful in 3m23s
Build & push images / images (push) Successful in 3m23s
The owner (or any role the owner grants barrier:create) lets a car out for free.
Exit side only. Every use is signed, attributed, photographed and on the operator's
Z-report; the shift's cash/card/drawer are untouched by construction.
- shared: resource 'barrier' + permission 'barrier:create'; reason codes
exit.forgiven / exit.forgiven.noSession; LedgerPayload.forgoneMinor.
- pay-station: forgive() signs a $0 payment carrying the quoted fee as forgoneMinor
(no tender), refuses a ticket with module charge lines (a wash is not forgiven).
- exit-flow: reopenBarrier(..., { forgiven }) bypasses the walk-back check and stamps
the forgiven reason on the anomaly + vehicle_exit; forgiveExitNoSession() for a car
with no ticket (anomaly under forgiven:<id> + exit snapshot + pulse). Relay driving
shared in #pulseExit.
- route POST /api/barrier/forgive { identity?, note? }: barrier:create + open shift;
the reason is optional (an empty note is signed as '(no reason given)').
- shift-service: forgoneTotalMinor + forgoneCount on the report/summary/signed
shift_z_report (only when > 0), print line 'Dalje të falura (N)'.
- web: 'Forgive & open' in the pay/exit modal for an open transient that owes money;
'Forgive & open exit' on the booth header for the no-ticket case; forgone line on
the X-report, close confirm and history; en/sq. Prints nothing.
- tests: exit-flow, pay-station, shift-service, HTTP route (403 without the
permission, 409 no shift, empty note accepted, ledger sequence, report figures).
- wiki: decisions/forgiven-exit.md (decision + as-built), booth-exit-flow, shift,
index, log.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
boothExit,
|
||||
can,
|
||||
fetchSiteConfig,
|
||||
forgiveExit,
|
||||
lookupSession,
|
||||
openShift,
|
||||
paySession,
|
||||
@@ -61,6 +62,12 @@ export function BoothPayModal({ identity, onClose }: { identity: string; onClose
|
||||
const { user } = rootRoute.useRouteContext();
|
||||
const canVoid = can(user, "event:void");
|
||||
const [voiding, setVoiding] = useState(false); // reason prompt revealed
|
||||
// FORGIVEN exit (barrier:create; wiki/decisions/forgiven-exit.md): let the car out with
|
||||
// NO payment. The fee owed is signed as forgone on a $0 payment — on the shift report
|
||||
// as its own line, never as cash. Reason optional; nothing printed.
|
||||
const canForgivePerm = can(user, "barrier:create");
|
||||
const [forgiving, setForgiving] = useState(false); // reason prompt revealed
|
||||
const [forgiveNote, setForgiveNote] = useState("");
|
||||
// Plate-swap: set when boothExit returns swap_suspected. Holds the detail for the warning
|
||||
// panel; the operator must consciously "Override & release". See plate-reconciliation.md.
|
||||
const [swap, setSwap] = useState<{ plate: string; otherIdentity: string; otherEnteredAt: string | null } | null>(null);
|
||||
@@ -150,6 +157,31 @@ export function BoothPayModal({ identity, onClose }: { identity: string; onClose
|
||||
// session (a subscription is closed via its own flow; a paid ticket is a refund). The
|
||||
// server enforces all of this too; the UI just hides the action when it can't apply.
|
||||
const canCancel = !!(canVoid && shiftReady && s?.found && s.open && !isSubscription && !alreadyPaid);
|
||||
// Forgivable = an OPEN transient that owes money now (unpaid, or an overstay top-up).
|
||||
// A paid-within-grace car takes the plain re-open; a subscriber the assist path.
|
||||
const canForgive = !!(canForgivePerm && shiftReady && s?.found && s.open && !isSubscription && (!alreadyPaid || isOverstay));
|
||||
|
||||
async function handleForgiveExit() {
|
||||
const note = forgiveNote.trim(); // optional
|
||||
setError(null);
|
||||
setPhase("finishing");
|
||||
try {
|
||||
const r = await forgiveExit(identity, note);
|
||||
const amount = formatMoney(r.forgoneMinor ?? 0, r.currency ?? s?.currency ?? "");
|
||||
setResult(
|
||||
r.opened
|
||||
? t("pay.exitForgiven", { amount })
|
||||
: t("pay.exitForgivenNotOpened", { amount, reason: r.reason ?? t("booth.openManually") }),
|
||||
);
|
||||
void qc.invalidateQueries({ queryKey: qk.events });
|
||||
void qc.invalidateQueries({ queryKey: qk.occupancy });
|
||||
void qc.invalidateQueries({ queryKey: qk.activeSessions });
|
||||
setPhase("done");
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
setPhase("error");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleVoidTicket() {
|
||||
const reason = voidReason.trim();
|
||||
@@ -556,6 +588,26 @@ export function BoothPayModal({ identity, onClose }: { identity: string; onClose
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Forgiven-exit reason prompt (revealed by the "Forgive & open" button).
|
||||
Free text, OPTIONAL. Signs a $0 payment carrying the forgone fee, then
|
||||
the exit + barrier pulse. Nothing is printed. */}
|
||||
{forgiving && phase !== "done" && (
|
||||
<div className="rounded-term border border-term-red/50 bg-term-red/5 px-3 py-2">
|
||||
<div className="text-[0.6875rem] font-semibold uppercase tracking-wider text-term-red">
|
||||
{t("pay.forgiveTitle")}
|
||||
</div>
|
||||
<div className="mt-1 text-[0.75rem] text-term-text">
|
||||
{t("pay.forgiveHint", { amount: formatMoney(s?.amountMinor ?? 0, s?.currency ?? "") })}
|
||||
</div>
|
||||
<input
|
||||
className="input mt-2 w-full"
|
||||
value={forgiveNote}
|
||||
onChange={(e) => setForgiveNote(e.target.value)}
|
||||
placeholder={t("pay.forgiveReasonPlaceholder")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* PLATE-SWAP warning: the exiting plate is already inside under another
|
||||
ticket. A prominent, deliberate hold — the operator must consciously
|
||||
override to release. See wiki/concepts/plate-reconciliation.md. */}
|
||||
@@ -661,6 +713,16 @@ export function BoothPayModal({ identity, onClose }: { identity: string; onClose
|
||||
{t("pay.assistOpenReveal")}
|
||||
</button>
|
||||
)
|
||||
) : forgiving ? (
|
||||
// Forgiven-exit confirm (reason prompt is shown above).
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleForgiveExit}
|
||||
disabled={phase === "finishing"}
|
||||
className="btn btn-danger btn-lg"
|
||||
>
|
||||
{phase === "finishing" ? t("pay.forgiving") : t("pay.confirmForgive")}
|
||||
</button>
|
||||
) : voiding ? (
|
||||
// Cancel-ticket confirm (reason prompt is shown above).
|
||||
<button
|
||||
@@ -684,6 +746,17 @@ export function BoothPayModal({ identity, onClose }: { identity: string; onClose
|
||||
{t("pay.cancelTicket")}
|
||||
</button>
|
||||
)}
|
||||
{/* Forgive the fee and open the exit (barrier:create only). Reveals
|
||||
the reason prompt above. */}
|
||||
{canForgive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setForgiving(true)}
|
||||
className="btn btn-ghost btn-sm text-term-red"
|
||||
>
|
||||
{t("pay.forgiveExit")}
|
||||
</button>
|
||||
)}
|
||||
{swap ? (
|
||||
// Plate-swap held → the only forward action is a conscious
|
||||
// override (re-submit with override:true; payment already taken).
|
||||
|
||||
Reference in New Issue
Block a user