I-020 — Service-Invoice register: previewer 404 (GCP/Workspace) + date format¶
Symptoms¶
- In the exported Register of Service Invoices XLSX, clicking an invoice-number
hyperlink opens the no-login viewer, but the previewer shows:
{ "error": "Document not found or not a Drive PDF." }— mostly GCP and Workspace invoices, plus some manually-uploaded ones (owner-confirmed): the manual ones that fail are the legacy GCS-stored uploads; newer Drive-backed manual uploads preview fine. - The XLSX Invoice Date column shows the raw ISO date (
2026-06-07) instead of the app conventionMMM DD, YYYY, unlike every other register export.
Root cause¶
- The register mints the short link with
documentId: r.recordId(RecordsApp.tsx). For GCP rows,r.recordIdis the billing month (e.g.202606), not a File-Archive doc id — so the viewer's/api/v/[id]/pdfdidgetReceipt("202606")→ not found. Separately, that endpoint'sarchive-docbranch only streamed Drive bytes (storagePath.startsWith('drive:')) and 404'd ("not a Drive PDF") on any legacy GCS-stored doc (Workspace AND some manual uploads). Manual uploads'recordIdIS a real doc id, sogetReceiptfinds them — but the GCS-stored ones still hit the "not a Drive PDF" path; only the Drive-backed manual uploads previewed. (Hence "some work, some don't" for manual.) - The Service Invoices (and Receipts) register exporter used
accessor: (r) => r.date || ''(raw ISO) instead offormatCsvDate(r.date).
Fix (commit below)¶
pages/api/v/[id]/pdf.ts(archive-docbranch): handle BOTH Drive and legacy GCS docs — GCS objects are fetched via a short-lived inline signed URL and streamed back same-origin (mirrors the receipts streaming endpoint); a missing doc now returns a clearerDocument not found.RecordsApp.tsxregister mint: derive the real File-Archive doc id from the/api/accounting/receipts/<docId>fileUrl (falling back torecordId), so GCP rows mint against their realgcp_invoicedoc id instead of the billing month.RecordsApp.tsxService-Invoice + Receipt register exporters: Invoice/Receipt Date now usesformatCsvDate(MMM DD, YYYY).
Decision log¶
2026-06-29 — ✅ Read AGENTS.md before working this ticket. Source: Records (Infrastructure) · https://claude.ai/code/session_018RDB37kCqfouHdygVXTAtD
Owner reported the previewer 404 + the date misalignment; clarified the 404 is "mostly GCP and Workspace, manual ones fine" — which pinned the GCP wrong-doc-id half (the GCS half mirrors I-017). Verified with the project-pinned tsc — clean. Runtime confirmation is owner-on-deploy (re-export, click a GCP/Workspace invoice link).