diff --git a/app/api/invoices/intake/route.ts b/app/api/invoices/intake/route.ts index 0648122..bbcb102 100644 --- a/app/api/invoices/intake/route.ts +++ b/app/api/invoices/intake/route.ts @@ -149,6 +149,7 @@ export async function POST(req: Request) { const bookedYear = periodEnd.getUTCFullYear(); let invoiceRec; + const safeFileName = file.name.replace(/[^\w.\- ]+/g, "_").slice(-120); try { invoiceRec = await pb.collection("invoices").create({ invoice_no: parsed.invoice_no, @@ -165,6 +166,12 @@ export async function POST(req: Request) { currency: parsed.currency, vat_reg_no: parsed.vat_reg_no, source_file: file.name, + // The document the figures were READ FROM is attached to the invoice as part of + // the import. Previously it was stored only on the intake row, so every invoice + // opened on a "drop the PDF here to attach it" prompt — asking for the very file + // the person had just uploaded to create it. Every figure on the page is + // transcribed from this PDF, so it belongs beside them. + source_pdf: new File([bytes], safeFileName, { type: "application/pdf" }), subtotal: parsed.subtotal, escalation: parsed.escalation, vat: parsed.vat,