feat(invoices): remove client-facing PDF generation

Phase 1 / commit 11 of 14 — invoices are client-facing documents, and
per the new "no CRM-generated client-facing PDFs" rule (see the design
spec), the in-app pdfme rendering is removed entirely.

Future invoice rendering will use the deferred AcroForm-fill admin-
template feature: admin uploads a PDF template with named form fields,
CRM fills them with invoice data via pdf-lib. Same pattern as the
in-app EOI pathway. Tracked in BACKLOG.md.

Deleted:
  - src/lib/services/invoices.ts:generateInvoicePdf (60 LOC)
  - src/lib/pdf/templates/invoice-template.ts (entire pdfme template)
  - src/app/api/v1/invoices/[id]/generate-pdf/route.ts
  - src/components/invoices/invoice-pdf-preview.tsx (regenerate UI)
  - "PDF Preview" tab on invoice detail page
  - 5 now-unused imports in invoices.ts (files, ports, buildStoragePath,
    getStorageBackend, env)

sendInvoice() retained: still queues the send-invoice email job, still
flips status to "sent", still emits the socket event. The PDF-attach
step is gone — downstream consumers either render externally or wait
for the AcroForm-fill feature. The `pdfFileId` column on invoices stays
so existing rows don't break, just never gets written by this code path.

1319/1319 vitest green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 21:04:49 +02:00
parent b7e010ff80
commit ed2424cc68
5 changed files with 6 additions and 335 deletions

View File

@@ -1,124 +0,0 @@
import type { Template } from '@pdfme/common';
import { formatCurrency } from '@/lib/utils/currency';
export const invoiceTemplate: Template = {
basePdf: 'BLANK_PDF' as unknown as string,
schemas: [
[
// Header fields
{
name: 'portName',
type: 'text',
position: { x: 20, y: 15 },
width: 100,
height: 10,
fontSize: 16,
},
{
name: 'invoiceTitle',
type: 'text',
position: { x: 140, y: 15 },
width: 50,
height: 10,
fontSize: 16,
},
{
name: 'invoiceNumber',
type: 'text',
position: { x: 140, y: 27 },
width: 50,
height: 6,
fontSize: 10,
},
{
name: 'invoiceDate',
type: 'text',
position: { x: 140, y: 35 },
width: 50,
height: 6,
fontSize: 10,
},
{
name: 'dueDate',
type: 'text',
position: { x: 140, y: 43 },
width: 50,
height: 6,
fontSize: 10,
},
// Client info
{
name: 'clientInfo',
type: 'text',
position: { x: 20, y: 55 },
width: 100,
height: 20,
fontSize: 10,
},
// Line items as text block
{
name: 'lineItems',
type: 'text',
position: { x: 20, y: 85 },
width: 170,
height: 120,
fontSize: 9,
},
// Totals
{
name: 'totals',
type: 'text',
position: { x: 110, y: 215 },
width: 80,
height: 30,
fontSize: 10,
},
// Notes
{
name: 'notes',
type: 'text',
position: { x: 20, y: 250 },
width: 170,
height: 20,
fontSize: 8,
},
],
],
};
export function buildInvoiceInputs(
invoice: Record<string, unknown>,
lineItems: Record<string, unknown>[],
port: Record<string, unknown>,
): Record<string, string> {
const currency = (invoice.currency as string) ?? 'USD';
const itemLines = lineItems
.map(
(li, i) =>
`${i + 1}. ${li.description} | Qty: ${li.quantity} | Unit: ${formatCurrency(Number(li.unitPrice), currency)} | Total: ${formatCurrency(Number(li.total), currency)}`,
)
.join('\n');
let totalsText = `Subtotal: ${formatCurrency(Number(invoice.subtotal), currency)}`;
if (Number(invoice.discountAmount) > 0) {
totalsText += `\nDiscount (${invoice.discountPct}%): -${formatCurrency(Number(invoice.discountAmount), currency)}`;
}
if (Number(invoice.feeAmount) > 0) {
totalsText += `\nFee (${invoice.feePct}%): +${formatCurrency(Number(invoice.feeAmount), currency)}`;
}
totalsText += `\n─────────────\nTOTAL: ${formatCurrency(Number(invoice.total), currency)}`;
return {
portName: (port?.name as string) ?? 'Port Nimara',
invoiceTitle: 'INVOICE',
invoiceNumber: invoice.invoiceNumber as string,
invoiceDate: `Date: ${new Date(invoice.createdAt as string | Date).toLocaleDateString('en-GB')}`,
dueDate: `Due: ${invoice.dueDate}`,
clientInfo:
`${invoice.clientName}\n${invoice.billingEmail ?? ''}\n${invoice.billingAddress ?? ''}`.trim(),
lineItems: itemLines || 'No line items',
totals: totalsText,
notes: invoice.notes ? `Notes: ${invoice.notes}` : '',
};
}