Repository navigation
feat(reports): batch export daily invoices into single compiled PDF #1397
Description
Problem
In Spain and several other jurisdictions (EU, Latin America), store owners are legally required to archive copies of all issued customer invoices and simplified invoices (facturas simplificadas / sales tickets) to justify taxable income for the tax authority (e.g. Agencia Tributaria).
In high-volume cafés and restaurants issuing 80–100+ tickets daily, operators currently have to print every individual customer ticket onto physical thermal paper rolls at day-end and file them in physical binders. This wastes paper rolls, takes substantial manual time, and thermal ink fades over time.
Proposed Solution
Add an "Invoices (PDF)" export action on Dashboard > Reports (inside the Daily Sales export section next to the date picker and existing .xlsx/.csv exports) that compiles all customer invoices for the selected business day into a single, beautifully formatted multi-page PDF document.
Key Design & Architectural Decisions
- Document Structure & Layout:
- Page 1 (Summary Cover Page): Store Legal Name, Tax ID / NIF / CIF, Address, Business Date, Total Invoices Count, Total Gross Sales, Net Base, and VAT Summary Table by rate (e.g., Base Imponible, IVA 10%, IVA 21%).
- Page 2 Onwards (Multi-Invoice Flow): Clean, bordered accounting invoice cards flowing ~2–3 per A4 page, protected with CSS
page-break-inside: avoid;so no individual invoice is awkwardly split across page margins.
- Audit Sequence & Refund Integrity:
- Bills are strictly sorted by sequential
bill_numberascending. - Fully and partially refunded bills are explicitly included (not skipped) with clear
[REFUNDED]badges and refund transaction details to guarantee a 100% continuous invoice sequence with no missing numbers for auditors.
- Bills are strictly sorted by sequential
- Pipeline Reuse:
- Reuses the native Chromium
saveHtmlAsPdfElectron IPC and@pageCSS print pipeline introduced in feat(reports): PDF export for X, Z and daily sales reports #1334 / PR feat(reports): PDF export for X, Z, daily sales #1393. - Fallback to browser print popup (
window.print()) in web/cloud mode.
- Reuses the native Chromium
- Security & Permissions:
- Gated under
reports.daily-sales.export/ROLE_ACCESS.owner(consistent with daily financial exports).
- Gated under
Acceptance Criteria
- Clicking "Invoices (PDF)" for a selected date generates a single compiled PDF (
invoices-YYYY-MM-DD.pdf). - Page 1 contains a complete tax summary cover page matching the daily sales metrics.
- Invoices are sequential with no missing numbers, and refunded tickets display visible status badges.
- CSS
page-break-inside: avoid;ensures individual invoice cards never break across page margins. - Respects store currency formatting, locale, and active tax pack labeling (e.g. NIF/CIF).
- Non-owner / unauthorized users are rejected with
403 Forbidden.
Verification
- Add integration test in
tests/daily-invoices-export.test.tscovering:- Sequence order and refund badge inclusion.
- Cover page total matching the daily sales
.xlsxcalculation. - Cross-midnight business day boundary filtering.
- Role-gating rejection.
- Run
npm run lint && npm test.
Activity