Skip to content

I-020 — Service-Invoice register: previewer 404 (GCP/Workspace) + date format

Symptoms

  1. 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.
  2. The XLSX Invoice Date column shows the raw ISO date (2026-06-07) instead of the app convention MMM DD, YYYY, unlike every other register export.

Root cause

  1. The register mints the short link with documentId: r.recordId (RecordsApp.tsx). For GCP rows, r.recordId is the billing month (e.g. 202606), not a File-Archive doc id — so the viewer's /api/v/[id]/pdf did getReceipt("202606") → not found. Separately, that endpoint's archive-doc branch 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' recordId IS a real doc id, so getReceipt finds 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.)
  2. The Service Invoices (and Receipts) register exporter used accessor: (r) => r.date || '' (raw ISO) instead of formatCsvDate(r.date).

Fix (commit below)

  1. pages/api/v/[id]/pdf.ts (archive-doc branch): 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 clearer Document not found.
  2. RecordsApp.tsx register mint: derive the real File-Archive doc id from the /api/accounting/receipts/<docId> fileUrl (falling back to recordId), so GCP rows mint against their real gcp_invoice doc id instead of the billing month.
  3. RecordsApp.tsx Service-Invoice + Receipt register exporters: Invoice/Receipt Date now uses formatCsvDate (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).