Phase 7: close, file, PDFs and prints
ci / frontend (push) Successful in 40s
ci / server (push) Successful in 10m56s
ci / image (push) Successful in 48s
ci / e2e (push) Successful in 2m44s

Clerical close and file: the VISUAL observed state beside the close confirm, a 409 with a second confirm when the
feed still shows work orders open, filing with a signature and the HMAC seal, the data book built on the server
and stored on the seal in the filing transaction, admin reopen keeping the broken seal with its data book.

Server PDFs with reportlab, pypdf and pypdfium2: the manufacturing data book page for page after the old build
(cover, index, drawings with VOID stamps, traceability and heat map rasters, weld maps and welding records, Q.C.
inspections, Q.C. and test documents, MTRs, record history), the job traveler with work order QR codes, the ITP
PDF filed automatically at sign-off, every print kind with the PRINTED COPY stamp, the controlled-copy stamp
signed with the seal key, PDF metadata, the traceability CSV with the formula guard, and the append-only
print_log with an audit row for every print and export (migration 0008).

Frontend: the close and file panel, the print menu and its entry points, the printed copies list on the History
tab, the ITP PDF buttons. Tests: server (close, file, reopen, seal, the builders, prints, CSV, stamps), frontend,
and the Playwright close and print scenarios. Docs updated; SECURITY closes M2, S6, S7 and S8.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-17 23:49:14 -06:00
co-authored by Claude Fable 5.1
parent 00531cb329
commit 904437153d
59 changed files with 8226 additions and 136 deletions
+112 -8
View File
@@ -2,7 +2,7 @@ import QRCode from "qrcode";
import { useEffect, useRef, useState, type FormEvent } from "react";
import { assetsApi } from "../api/assets";
import { packetsApi } from "../api/packets";
import type { BomLine, Guarded, LogRow, PacketDoc, PacketRead, QcHistoryRow, WorkOrder } from "../api/types";
import type { BomLine, Guarded, LogRow, PacketDoc, PacketRead, PrintRow, QcHistoryRow, WorkOrder } from "../api/types";
import type { ReasonOptions } from "../components/ReasonSheet";
import { Sheet } from "../components/Sheet";
import { errorText, fmtTime } from "../lib/format";
@@ -11,6 +11,7 @@ import { useLoad } from "../lib/useLoad";
import { MtrViewer } from "../warehouse/MtrViewer";
import { PullTable, ShortChip, type Write } from "../warehouse/PullTable";
import { ShortSheet } from "../warehouse/ShortSheet";
import { assetOfUrl, kioskCode, openPrint, printLineText } from "./closeUtil";
export type Mutate = (
fn: (g: Guarded) => Promise<PacketRead | null | undefined>,
@@ -209,6 +210,19 @@ export function MaterialsTab({
<button type="button" className="lnk small" onClick={() => setViewFor(b.item)}>
MTR
</button>
{!p.removed ? (
<>
{" "}
<button
type="button"
className="btn sm ghost"
title={`Print the MTR of item ${b.item}`}
onClick={() => openPrint(p.id, "doc", { asset: b.mtr_asset_id ?? undefined })}
>
Print
</button>
</>
) : null}
</>
) : null}
</td>
@@ -279,11 +293,28 @@ function Qr({ text }: { text: string }) {
);
}
/** The work orders, and one QR code per work order key. */
/** The work orders, the kiosk QR code of each (as the old ticketsTab), and the traveler print. */
export function WorkOrdersTab({ p }: { p: PacketRead }) {
if (!p.work_orders.length) return <div className="empty">No work orders on this packet.</div>;
return (
<div className="stack">
<div className="callout flush">
<div className="acts center">
<span className="grow">
Scan a code at the labor kiosk to clock on in Visual. Codes are rebuilt from the packet (WO · lot · split · sub · seq), same as the printed overlay.
</span>
{!p.removed ? (
<>
<button className="btn" type="button" onClick={() => openPrint(p.id, "traveler")}>
Print traveler
</button>
<a className="btn ghost" href={packetsApi.pdfUrl(p.id, "traveler")} target="_blank" rel="noopener">
Traveler (PDF)
</a>
</>
) : null}
</div>
</div>
<div className="tw">
<table>
<thead>
@@ -316,13 +347,21 @@ export function WorkOrdersTab({ p }: { p: PacketRead }) {
</div>
<div className="qrs">
{p.work_orders.map((w) => {
const k = woKey(w);
const code = kioskCode(w);
return (
<div key={w.id ?? k} className="qr">
<Qr text={k} />
<div key={w.id ?? woKey(w)} className="qr">
<Qr text={code} />
<div>
<div className="wo">{w.wo_base}</div>
<div className="mono small">{k}</div>
<div className="small">
Lot <b className="mono">{w.lot}</b> · Seq <b className="mono">{show(w.seq)}</b> {w.op ?? ""}
</div>
<div className="small">
Target <b className="mono">{show(w.target_hrs)} h</b> · Qty <b className="mono">{show(w.qty)}</b>
</div>
<div className="mono small" data-testid="kiosk-code">
{code}
</div>
</div>
</div>
);
@@ -420,7 +459,21 @@ function AddDocSheet({ p, sub, write, onDone, onCancel }: { p: PacketRead; sub:
);
}
function DocRow({ d, old, canRemove, busy, onOut }: { d: PacketDoc; old: boolean; canRemove: boolean; busy: boolean; onOut: () => void }) {
function DocRow({
d,
old,
canRemove,
busy,
onOut,
onPrint,
}: {
d: PacketDoc;
old: boolean;
canRemove: boolean;
busy: boolean;
onOut: () => void;
onPrint?: (() => void) | undefined;
}) {
const label = d.kind_label || docKindLabel(d.kind);
const meta = [d.file_name || null, `added by ${d.added_by?.display_name ?? "-"} ${fmtTime(d.added_at)}`, d.note || null].filter((x): x is string => !!x);
return (
@@ -440,6 +493,11 @@ function DocRow({ d, old, canRemove, busy, onOut }: { d: PacketDoc; old: boolean
<button className="btn sm" type="button" onClick={() => openBlob(d.url)}>
View
</button>
{!old && onPrint ? (
<button className="btn sm" type="button" onClick={onPrint}>
Print
</button>
) : null}
{!old && canRemove ? (
<button className="btn sm ghost" type="button" disabled={busy} onClick={onOut}>
Take out of data book
@@ -511,7 +569,17 @@ export function DocumentsTab({
</div>
<div className="qcdocs">
{live.length ? (
live.map((d) => <DocRow key={d.id} d={d} old={false} canRemove={canRemove} busy={busy} onOut={() => void takeOut(d)} />)
live.map((d) => (
<DocRow
key={d.id}
d={d}
old={false}
canRemove={canRemove}
busy={busy}
onOut={() => void takeOut(d)}
onPrint={p.removed ? undefined : () => openPrint(p.id, "doc", { asset: d.asset_id })}
/>
))
) : (
<div className="empty slim">No documents added to this packet yet.{canAdd ? " Use Add document." : " Q.C. or Clerical add them."}</div>
)}
@@ -551,6 +619,11 @@ export function DocumentsTab({
<button className="btn sm" type="button" onClick={() => openBlob(d.url)}>
View
</button>
{!p.removed ? (
<button className="btn sm" type="button" onClick={() => openPrint(p.id, "doc", { asset: d.asset_id ?? assetOfUrl(d.url) })}>
Print
</button>
) : null}
</div>
</div>
))
@@ -582,10 +655,41 @@ export function HistoryTab({ p }: { p: PacketRead }) {
) : (
<div className="empty slim">Nothing recorded yet.</div>
)}
<PrintsList p={p} />
</div>
);
}
/** GET /prints: the printed copies and exports of this packet, newest first. */
function PrintsList({ p }: { p: PacketRead }) {
const [load] = useLoad((s) => packetsApi.prints(p.id, s), `${p.id}:${p.version}`);
return (
<section className="sec" aria-label="Printed copies and exports">
<div className="sec-h">
<h2>Printed copies and exports</h2>
{load.state === "ok" ? <span className="ct">{load.data.length}</span> : null}
</div>
{load.state === "loading" ? (
<div className="empty slim">Loading</div>
) : load.state === "error" ? (
<div className="callout warn">{load.message}</div>
) : load.data.length ? (
<ul className="prints">
{load.data.map((r) => (
<PrintLine key={r.id} r={r} />
))}
</ul>
) : (
<div className="empty slim">Nothing printed yet.</div>
)}
</section>
);
}
function PrintLine({ r }: { r: PrintRow }) {
return <li className="small">{printLineText(r)}</li>;
}
/** One row per closed Q.C. inspection, oldest first. */
function QcInspections({ rows }: { rows: QcHistoryRow[] }) {
if (!rows.length) return null;