feat(exit): forgiven exit — open the exit barrier with no payment (barrier:create)
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:
2026-10-09 08:14:36 +02:00
parent 5d247a5729
commit a761398301
21 changed files with 710 additions and 26 deletions
+73
View File
@@ -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).
+33 -1
View File
@@ -1,7 +1,7 @@
import { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { can, fetchEvents, fetchOccupancy, fetchSiteConfig, issueEntryTicket, type LedgerEvent, type Occupancy } from "./api.js";
import { can, fetchEvents, fetchOccupancy, fetchSiteConfig, forgiveExit, issueEntryTicket, type LedgerEvent, type Occupancy } from "./api.js";
import { rootRoute } from "./router.js";
import { qk } from "./lib/query.js";
import { useLiveStore } from "./lib/live-store.js";
@@ -216,6 +216,27 @@ function LaneIndicators() {
if (window.confirm(t("booth.issueEntryConfirm"))) issue.mutate();
}
// FORGIVEN exit for a car with NO ticket (barrier:create; wiki/decisions/forgiven-exit.md):
// signed anomaly + exit snapshot + pulse, no money, nothing printed. Reason optional
// (Cancel in the prompt aborts; an empty answer proceeds).
const canForgive = can(user, "barrier:create") && shiftOpen && isMine;
const forgive = useMutation({
mutationFn: (note: string) => forgiveExit(null, note),
onSuccess: (r) => {
setMsg({ ok: r.opened, text: r.opened ? t("booth.forgiveExitOk") : t("booth.forgiveExitNotOpened", { reason: r.reason ?? "" }) });
void qc.invalidateQueries({ queryKey: qk.events });
setTimeout(() => setMsg(null), 5000);
},
onError: (e) => {
setMsg({ ok: false, text: (e as Error).message });
setTimeout(() => setMsg(null), 5000);
},
});
function onForgiveNoTicket() {
const note = window.prompt(t("booth.forgiveExitPrompt"));
if (note !== null) forgive.mutate(note.trim());
}
return (
<div className="flex items-center gap-2">
<BarrierLight
@@ -228,6 +249,17 @@ function LaneIndicators() {
bypassCamera={site?.bypassPresenceCamera ?? false}
/>
<BarrierLight label={t("booth.laneExit")} busy={lanes?.exit ?? false} radar={radar?.exit ?? false} />
{canForgive && (
<button
type="button"
onClick={onForgiveNoTicket}
disabled={forgive.isPending}
className="btn btn-ghost btn-sm text-term-red"
title={t("booth.forgiveExitTitle")}
>
{t("booth.forgiveExit")}
</button>
)}
{msg && (
<span className={`text-[0.6875rem] ${msg.ok ? "text-term-green" : "text-term-red"}`}>{msg.text}</span>
)}
+7
View File
@@ -174,6 +174,13 @@ function CloseShiftConfirm({
part is broken out below it; subscription SALES is not (it's the remainder). */}
<span />
<ConfirmFigure label={t("shift.srcSubWindow")} value={fmt(x.subscriptionWindowMinor)} sub />
{/* Forgiven exits — fees waived with no payment; NOT in cash/card. Only when any. */}
{(x.forgoneCount ?? 0) > 0 && (
<>
<ConfirmFigure label={t("shift.srcForgone", { count: x.forgoneCount })} value={fmt(x.forgoneTotalMinor ?? 0)} />
<span />
</>
)}
</>
)}
</div>
+18
View File
@@ -92,6 +92,8 @@ function useCurrentShifts(): { current: CurrentShift[]; tills: TillId[]; workabl
subscriptionSalesMinor: x.subscriptionSalesMinor,
subscriptionWindowMinor: x.subscriptionWindowMinor,
chargesByModuleMinor: x.chargesByModuleMinor,
forgoneTotalMinor: x.forgoneTotalMinor,
forgoneCount: x.forgoneCount,
openingFloatMinor: x.openingFloatMinor,
cashAddedMinor: x.cashAddedMinor,
cashRemovedMinor: x.cashRemovedMinor,
@@ -409,6 +411,10 @@ function ShiftActivityLog({
<Figure label={t("shifts.srcSubscriptions")} value={money(shift.subscriptionTotalMinor, cur)} />
{/* Abonime is the subscription TOTAL; only the out-of-window part is broken out. */}
<Figure label={t("shifts.srcSubWindow")} value={money(shift.subscriptionWindowMinor, cur)} sub />
{/* Forgiven exits — fees waived with no payment; NOT in cash/card. Only when any. */}
{(shift.forgoneCount ?? 0) > 0 && (
<Figure label={t("shifts.srcForgone", { count: shift.forgoneCount })} value={money(shift.forgoneTotalMinor ?? 0, cur)} />
)}
<ChargeFigures charges={shift.chargesByModuleMinor} cur={cur} />
<Figure label={t("shifts.openingFloat")} value={money(shift.openingFloatMinor, cur)} />
<Figure label={t("shifts.cashTaken")} value={money(shift.cashTotalMinor, cur)} />
@@ -471,6 +477,10 @@ function EndShiftModal({ shift, onClose, onDone }: { shift: ShiftSummary; onClos
{/* Abonime is the subscription TOTAL; only the out-of-window part is broken out. */}
<span />
<Figure label={t("shift.srcSubWindow")} value={money(report.subscriptionWindowMinor, report.currency)} sub />
{/* Forgiven exits — fees waived with no payment; NOT in cash/card. Only when any. */}
{(report.forgoneCount ?? 0) > 0 && (
<Figure label={t("shift.srcForgone", { count: report.forgoneCount })} value={money(report.forgoneTotalMinor ?? 0, report.currency)} />
)}
</div>
<div className="mt-1 grid grid-cols-2 gap-x-6 gap-y-0.5 border-t border-term-border pt-1">
<Figure label={t("shift.cash")} value={money(report.cashTotalMinor, report.currency)} />
@@ -498,6 +508,10 @@ function EndShiftModal({ shift, onClose, onDone }: { shift: ShiftSummary; onClos
{/* Abonime is the subscription TOTAL; only the out-of-window part is broken out. */}
<span />
<Figure label={t("shift.srcSubWindow")} value={money(shift.subscriptionWindowMinor, cur)} sub />
{/* Forgiven exits — fees waived with no payment; NOT in cash/card. Only when any. */}
{(shift.forgoneCount ?? 0) > 0 && (
<Figure label={t("shift.srcForgone", { count: shift.forgoneCount })} value={money(shift.forgoneTotalMinor ?? 0, cur)} />
)}
</div>
<div className="mt-2 grid grid-cols-2 gap-x-6 gap-y-0.5 border-t border-term-border pt-2">
<Figure label={t("shift.cash")} value={money(shift.cashTotalMinor, cur)} />
@@ -540,6 +554,10 @@ function TakingsModal({ till, onClose }: { till: TillId; onClose: () => void })
{/* Abonime is the subscription TOTAL; only the out-of-window part is broken out. */}
<span />
<Figure label={t("shift.srcSubWindow")} value={money(x.subscriptionWindowMinor, x.currency)} sub />
{/* Forgiven exits — fees waived with no payment; NOT in cash/card. Only when any. */}
{(x.forgoneCount ?? 0) > 0 && (
<Figure label={t("shift.srcForgone", { count: x.forgoneCount })} value={money(x.forgoneTotalMinor ?? 0, x.currency)} />
)}
</div>
<div className="mt-1 grid grid-cols-2 gap-x-6 gap-y-0.5 border-t border-term-border pt-1">
<Figure label={t("shift.cash")} value={money(x.cashTotalMinor, x.currency)} />
+14
View File
@@ -1102,6 +1102,10 @@ export interface ShiftSourceSplit {
/** Module money that rode this till's tickets (a booth-paid wash), by module id.
* Inside cash+card, OUTSIDE the ticket bucket. Absent on pre-2026-09 reports. */
chargesByModuleMinor?: Partial<Record<string, number>>;
/** Forgiven exits (wiki/decisions/forgiven-exit.md): fees an operator waived, and how
* many. $0 payments — NOT inside cash/card. Absent on pre-2026-10 reports. */
forgoneTotalMinor?: number;
forgoneCount?: number;
}
export interface ShiftReport extends ShiftSourceSplit {
@@ -1448,6 +1452,16 @@ export function reopenBarrier(identity: string): Promise<{ ok: true; opened: boo
return apiFetch("/api/barrier/reopen", { method: "POST", body: JSON.stringify({ identity }) });
}
/** FORGIVEN exit (barrier:create): open the exit with NO payment. With a ticket the fee
* owed is signed as forgone on a $0 payment; with `identity` null the car has no
* session (anomaly + snapshot + pulse). `note` is the mandatory reason. Prints nothing. */
export function forgiveExit(
identity: string | null,
note: string,
): Promise<{ ok: true; opened: boolean; reason?: string; forgoneMinor?: number; currency?: string }> {
return apiFetch("/api/barrier/forgive", { method: "POST", body: JSON.stringify({ ...(identity ? { identity } : {}), note }) });
}
/** Take payment for a session → signed payment event. `overrideMinor` sets an
* operator amount (lost ticket / dispute). */
export function paySession(
+17
View File
@@ -317,6 +317,11 @@ export const en: Catalog = {
issueEntryTitle: "Issue an entry ticket & open the barrier (physical button broken)",
issueEntryConfirm: "A vehicle is at the entry. Issue an entry ticket and open the barrier?",
issueEntryOk: "Entry ticket {{ticket}} issued.",
forgiveExit: "Forgive & open exit",
forgiveExitTitle: "Open the exit barrier for a car with NO ticket — no money, signed and flagged",
forgiveExitPrompt: "Reason for opening the exit with no ticket (optional — OK to leave empty):",
forgiveExitOk: "Exit opened — forgiven, no payment.",
forgiveExitNotOpened: "Recorded, but the barrier did not open: {{reason}}",
exitedGrace: "exited · grace",
exitedGraceLeft: "exited · {{time}}",
exitedGraceTitle: "Paid and exited — barrier not confirmed; waiting out the grace period.",
@@ -419,6 +424,8 @@ export const en: Catalog = {
"exit.open.failed": "Exit recorded, but the barrier did not open — open manually",
"exit.freeGrace": "Free entry-grace (no charge)",
"exit.manualOpen": "Manual barrier open (human intervention)",
"exit.forgiven": "Forgiven exit by {{operator}} — fee of {{forgone}} {{currency}} waived: {{note}}",
"exit.forgiven.noSession": "Forgiven exit by {{operator}} — no ticket / no session: {{note}}",
"exit.plateSwapSuspected": "Possible ticket swap — plate {{plate}} is already inside under ticket {{otherIdentity}}",
"exit.plateSwapOverride": "Operator {{operator}} released a suspected ticket-swap exit (plate {{plate}}, also open under {{otherIdentity}})",
"sub.refused.notFound": "Subscription refused — not found",
@@ -991,6 +998,7 @@ export const en: Catalog = {
srcSubscriptions: "Subscriptions:",
srcOnTicket: "{{module}} (on ticket):",
srcSubWindow: "out-of-window",
srcForgone: "Forgiven exits ({{count}}):",
drawerSection: "— Drawer —",
openingFloat: "Opening cash:",
cashTaken: "Daily takings:",
@@ -1039,6 +1047,7 @@ export const en: Catalog = {
srcTickets: "Tickets",
srcSubscriptions: "Subscriptions",
srcSubWindow: "out-of-window",
srcForgone: "Forgiven exits ({{count}})",
expectedDrawer: "Expected drawer",
filterFrom: "From",
filterTo: "To",
@@ -1246,6 +1255,14 @@ export const en: Catalog = {
confirmCancelTicket: "Confirm cancellation",
cancelling: "cancelling…",
ticketCancelled: "Ticket cancelled.",
forgiveExit: "Forgive & open",
forgiveTitle: "Forgive this exit",
forgiveHint: "Lets the car out with NO payment. The fee owed ({{amount}}) is recorded as forgone on your shift report — never as cash. A reason is optional; nothing is printed.",
forgiveReasonPlaceholder: "Reason for forgiving (optional)…",
confirmForgive: "Confirm — open exit, no payment",
forgiving: "opening…",
exitForgiven: "Exit forgiven — {{amount}} waived, barrier opened.",
exitForgivenNotOpened: "Exit forgiven — {{amount}} waived, but the barrier did not open: {{reason}}",
noSnapshots: "no snapshots",
loadingSnapshots: "loading snapshots…",
snapEntry: "entry",
+17
View File
@@ -319,6 +319,11 @@ export const sq = {
issueEntryTitle: "Lësho një biletë hyrjeje & hap barrierën (butoni fizik i prishur)",
issueEntryConfirm: "Një automjet është te hyrja. Të lëshohet një biletë hyrjeje dhe të hapet barriera?",
issueEntryOk: "Bileta e hyrjes {{ticket}} u lëshua.",
forgiveExit: "Fal & hap daljen",
forgiveExitTitle: "Hap barrierën e daljes për një automjet PA biletë — pa para, e nënshkruar dhe e shënuar",
forgiveExitPrompt: "Arsyeja e hapjes së daljes pa biletë (opsionale — mund të lihet bosh):",
forgiveExitOk: "Dalja u hap — e falur, pa pagesë.",
forgiveExitNotOpened: "U regjistrua, por barriera nuk u hap: {{reason}}",
exitedGrace: "doli · në afat",
exitedGraceLeft: "doli · {{time}}",
exitedGraceTitle: "Paguar dhe dalur — barriera nuk u konfirmua; po pret afatin kohor.",
@@ -422,6 +427,8 @@ export const sq = {
"exit.open.failed": "Dalja u regjistrua, por barriera nuk u hap — hape manualisht",
"exit.freeGrace": "Periudhë pa pagesë në hyrje (pa tarifë)",
"exit.manualOpen": "Hapje manuale e barrierës (ndërhyrje njerëzore)",
"exit.forgiven": "Dalje e falur nga {{operator}} — tarifa {{forgone}} {{currency}} u fal: {{note}}",
"exit.forgiven.noSession": "Dalje e falur nga {{operator}} — pa biletë / pa seancë: {{note}}",
"exit.plateSwapSuspected": "Mundësi ndërrimi biletash — targa {{plate}} është tashmë brenda me biletën {{otherIdentity}}",
"exit.plateSwapOverride": "Operatori {{operator}} lëshoi një dalje me dyshim ndërrimi biletash (targa {{plate}}, edhe e hapur me {{otherIdentity}})",
"sub.refused.notFound": "Abonimi u refuzua — nuk u gjet",
@@ -1004,6 +1011,7 @@ export const sq = {
srcSubscriptions: "Abonime:",
srcOnTicket: "{{module}} (në biletë):",
srcSubWindow: "jashtë orarit",
srcForgone: "Dalje të falura ({{count}}):",
drawerSection: "— Arka —",
openingFloat: "Arka fillestare:",
cashTaken: "Xhiro ditore:",
@@ -1052,6 +1060,7 @@ export const sq = {
srcTickets: "Bileta",
srcSubscriptions: "Abonime",
srcSubWindow: "jashtë orarit",
srcForgone: "Dalje të falura ({{count}})",
expectedDrawer: "Gjëndje arke",
// Filter (admin only).
filterFrom: "Nga",
@@ -1262,6 +1271,14 @@ export const sq = {
confirmCancelTicket: "Konfirmo anulimin",
cancelling: "duke anuluar…",
ticketCancelled: "Bileta u anulua.",
forgiveExit: "Fal & hap",
forgiveTitle: "Fal këtë dalje",
forgiveHint: "E lë automjetin të dalë PA pagesë. Shuma e detyruar ({{amount}}) regjistrohet si e falur në raportin e turnit — kurrë si para. Arsyeja është opsionale; nuk printohet asgjë.",
forgiveReasonPlaceholder: "Arsyeja e faljes (opsionale)…",
confirmForgive: "Konfirmo — hap daljen, pa pagesë",
forgiving: "duke hapur…",
exitForgiven: "Dalja u fal — {{amount}} u fal, barriera u hap.",
exitForgivenNotOpened: "Dalja u fal — {{amount}} u fal, por barriera nuk u hap: {{reason}}",
// snapshots
noSnapshots: "asnjë foto",
loadingSnapshots: "duke ngarkuar fotot…",