Skip to content

Migrate Invoice PDF to pdf-compiler#931

Open
JustSamuel wants to merge 1 commit into
developfrom
feat/issue-926-migrate-invoice-pdf
Open

Migrate Invoice PDF to pdf-compiler#931
JustSamuel wants to merge 1 commit into
developfrom
feat/issue-926-migrate-invoice-pdf

Conversation

@JustSamuel
Copy link
Copy Markdown
Contributor

@JustSamuel JustSamuel commented May 21, 2026

Description

First of seven PDF migrations under #926. Replaces the LaTeX invoice service with an HTML one that goes through pdf-compiler instead of pdf-generator-client, and lands the F6c design as the new invoice layout.

Visual change

The PDF now renders as the two-page F6c design: a Factuur cover with the recipient, totals headline, BTW spec table and BAC letterhead, plus a line items page with one row per sub_transaction_row (ascending by row id). Cached invoices regenerate on next access because the new parameter shape produces different hashes, so getOrCreatePdf falls through to createPdf for any invoice with a stale PDF on disk.

The "Attn. " line ("t.a.v." in Dutch) renders between the addressee and the street when invoice.attention is set. The dev seed leaves attention empty so the smoke render looks identical to before, but invoices created via the API can have it set and will now show it.

Spillover for long invoices

Invoices with many distinct products spill onto multiple line item pages. The template puts spacer rows inside the items table thead and tfoot, so every continuation page gets ~80px above and ~60px below the rows instead of items butting up against the page edge. Chromium ignores @page :first and :nth() on continuation pages, so the spacers have to live inside the table for them to auto-repeat.

Tested at 30, 60 and 120 distinct line items.

Removed

  • src/service/pdf/invoice-pdf-service.ts (the LaTeX service)
  • test/unit/service/invoice-pdf-service.ts (replaced with an HTML test)
  • emptyIdentity and subTransactionRowToProduct from src/helpers/pdf.ts (no other callers; the PDF_VAT_* constants and UNUSED_PARAM stay for the six remaining LaTeX PDFs)

Not removed yet

pdf-generator-client is still in package.json since six other PDFs use it. Removing it is the final PR in the series, per PLAN-invoice-pdf-migration.md section 3.

Related issues/external references

#926

Types of changes

  • New feature
  • Style

PR Checklist

  • Test Coverage: New functionality has test coverage and all tests pass (pnpm test: 2275 passed, 27 skipped, 0 failed)
  • Documentation: New code has TypeDoc comments
  • Database Changes: N/A

Additional Notes

Smoke tested end-to-end against a running backend with the abc.docker-registry.gewis.nl/eou/pdf-compiler:latest container running locally. The rendered PDF matches the F6c reference output.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

SudoSOS Coverage Report

Commit: 78ed1b7
Base: develop@59018b0

Type Base This PR
Total Statements Coverage  92.86%  92.92% (+0.06%)
Total Branches Coverage  87.62%  87.5% (-0.12%)
Total Functions Coverage  93.93%  93.93% (+0%)
Total Lines Coverage  92.86%  92.92% (+0.06%)
Details (changed files)
FileStatementsBranchesFunctionsLines
src/entity/invoices/invoice.ts 100% 100% 91.66% 100%
src/files/templates/bac-letterhead.ts 100% 100% 100% 100%
src/helpers/pdf.ts 95.89% 88.23% 85.71% 95.89%
src/html/invoice.html.ts 100% 78.57% 100% 100%
src/service/pdf/invoice-html-pdf-service.ts 100% 50% 100% 100%

The full per-file breakdown is omitted to stay under GitHub's 65,536-character comment limit. Download the coverage artifact from this workflow run for the complete report, or view it on Coveralls.

@JustSamuel JustSamuel marked this pull request as ready for review May 21, 2026 16:04
Copilot AI review requested due to automatic review settings May 21, 2026 16:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Invoice PDF generation from the legacy LaTeX/pdf-generator-client flow to an HTML template compiled through pdf-compiler, introducing the new “F6c” invoice layout as part of the broader PDF migration tracker (#926).

Changes:

  • Replaced the removed InvoicePdfService (LaTeX) with InvoiceHtmlPdfService (HTML → pdf-compiler).
  • Added a new HTML invoice template (src/html/invoice.html.ts) and centralized BAC letterhead/payment details.
  • Updated unit tests and removed unused legacy PDF helper functions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/unit/service/invoice-html-pdf-service.ts Updates/extends tests to cover HTML-based invoice PDF parameter generation and HTML anchors.
src/service/pdf/invoice-pdf-service.ts Removes the legacy LaTeX/pdf-generator-client invoice PDF service.
src/service/pdf/invoice-html-pdf-service.ts Adds new HTML-to-PDF invoice service that computes totals, VAT breakdown, line items, and due date.
src/html/invoice.html.ts Introduces the new two-page “F6c” invoice HTML template rendered to PDF via pdf-compiler.
src/helpers/pdf.ts Removes now-unused legacy helpers (emptyIdentity, subTransactionRowToProduct) tied to the old invoice PDF implementation.
src/files/templates/bac-letterhead.ts Adds a single source of truth for BAC letterhead/payment details used by the invoice template/service.
src/entity/invoices/invoice.ts Switches the invoice entity to use InvoiceHtmlPdfService by default.
Comments suppressed due to low confidence (2)

test/unit/service/invoice-html-pdf-service.ts:266

  • This test restores uploadPdfStub inside the test body, but afterEach also restores the same stub. Restoring stubs mid-test makes teardown order-dependent and can lead to double-restore issues or accidental invocation of real implementations. Prefer keeping the stub in place and configuring its behavior for this test (or create a separate sandbox/service instance for tests that need the real method).
    test/unit/service/invoice-html-pdf-service.ts:336
  • These tests call compileHtmlStub.restore() even though afterEach always restores the stub, and createRaw() does not call compileHtml() anyway. This extra restore is unnecessary and makes the test setup/teardown harder to reason about (and can become brittle if the stubbing strategy changes). Consider removing the manual restores and/or only stubbing compileHtml in tests that actually exercise PDF compilation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/service/pdf/invoice-html-pdf-service.ts Outdated
Comment thread src/html/invoice.html.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread src/service/pdf/invoice-html-pdf-service.ts Outdated
Comment thread src/html/invoice.html.ts
@JustSamuel JustSamuel force-pushed the feat/issue-926-migrate-invoice-pdf branch 2 times, most recently from acc26bb to 26cad08 Compare May 24, 2026 08:20
@JustSamuel JustSamuel requested a review from RubenLWF June 2, 2026 14:27
Replace InvoicePdfService (LaTeX via pdf-generator-client) with
InvoiceHtmlPdfService (HTML via @gewis/pdf-compiler-ts). The new service
extends HtmlPdfService, so getOrCreatePdf and the storage flow stay
unchanged; getParameters now contains the per-row aggregation that
previously lived only in the dev harness.

The visual design is F6c, the variant picked during the design
exploration: a two-page layout with a Factuur cover and a Line items
spec page. Existing cached InvoicePdf rows regenerate on next access
because the new parameter shape produces different hashes.

emptyIdentity and subTransactionRowToProduct are removed from
src/helpers/pdf.ts since only the deleted invoice service used them.
The PDF_VAT_* constants and UNUSED_PARAM stay until the remaining six
LaTeX PDFs migrate.

Part of #926.
@JustSamuel JustSamuel force-pushed the feat/issue-926-migrate-invoice-pdf branch from 26cad08 to 78ed1b7 Compare June 3, 2026 05:33
Comment thread src/files/templates/bac-letterhead.ts
@JustSamuel JustSamuel requested a review from RubenLWF June 3, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants