feat(expense-export): parent-company react-pdf + pdfkit brand header
Phase 1 / commit 10 of 14 — migrates the pdfme-based parent-company
expense export to react-pdf and adds a shared brand header to the
pdfkit-based streaming expense PDF so both surfaces match the rest of
the internal-only PDF family.
parent-company-expense.tsx:
Summary KV grid (entry count, subtotal, fee, total) + entries table
with right-aligned EUR amounts and a totals row. Footnote rendered
when the EUR rate lookup falls through to the 1:1 USD:EUR fallback.
expense-export.tsx (renamed .ts -> .tsx):
- exportParentCompany now renders the react-pdf template via
resolvePortLogo() + renderPdf()
- dropped the inline pdfme template object (was the last pdfme caller
in this file)
- return type widened from Uint8Array to Buffer; caller already wraps
in Buffer.from() so no API change downstream
expense-pdf.service.ts (the pdfkit streaming engine — unchanged):
- addHeader() now draws a dark slate band matching the brand-kit
header band, with the port logo letterboxed on the left and the
document title right-aligned. Falls back to text port-name if the
logo image is missing or can't be decoded by pdfkit
- port + logo resolved once per export via Promise.all
- subheader stays beneath the band in muted grey, same as before
- streaming behavior + receipt embedding + sharp compression
untouched — the only change is the visual treatment of the header
Old pdfme inline template deleted along with the generatePdf import.
After this commit, the only remaining pdfme imports are in:
invoice-template.ts, tiptap-to-pdfme.ts, eoi-standard-inapp.ts, and
document-templates.ts (lines 516-522). All four are removed in
commits 11-12.
1319/1319 vitest green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
41
tests/unit/parent-company-export.test.tsx
Normal file
41
tests/unit/parent-company-export.test.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { renderPdf } from '@/lib/pdf/render';
|
||||
import { ParentCompanyExpensePdf } from '@/lib/pdf/templates/parent-company-expense';
|
||||
|
||||
describe('parent-company expense template', () => {
|
||||
it('renders with multiple rows + totals', async () => {
|
||||
const bytes = await renderPdf(
|
||||
<ParentCompanyExpensePdf
|
||||
portName="Port Test"
|
||||
logoBuffer={null}
|
||||
rows={[
|
||||
{ date: '2026-04-01', establishment: 'Shell', category: 'Fuel', amountEur: 200 },
|
||||
{ date: '2026-04-03', establishment: 'BP', category: 'Fuel', amountEur: 150 },
|
||||
{ date: '2026-04-05', establishment: 'Marina café', category: 'Misc', amountEur: 12.5 },
|
||||
]}
|
||||
subtotal={362.5}
|
||||
managementFee={18.13}
|
||||
total={380.63}
|
||||
dateFrom="2026-04-01"
|
||||
dateTo="2026-04-30"
|
||||
/>,
|
||||
);
|
||||
expect(bytes.subarray(0, 5).toString('utf8')).toBe('%PDF-');
|
||||
}, 30_000);
|
||||
|
||||
it('renders the rate-unavailable footnote', async () => {
|
||||
const bytes = await renderPdf(
|
||||
<ParentCompanyExpensePdf
|
||||
portName="Port Test"
|
||||
logoBuffer={null}
|
||||
rows={[]}
|
||||
subtotal={0}
|
||||
managementFee={0}
|
||||
total={0}
|
||||
rateAvailable={false}
|
||||
/>,
|
||||
);
|
||||
expect(bytes.subarray(0, 5).toString('utf8')).toBe('%PDF-');
|
||||
}, 30_000);
|
||||
});
|
||||
Reference in New Issue
Block a user