Skip to content

feat(reports): batch export daily invoices into single compiled PDF #1397

Closed

Description

@khaira777

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

  1. 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.
  2. Audit Sequence & Refund Integrity:
    • Bills are strictly sorted by sequential bill_number ascending.
    • 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.
  3. Pipeline Reuse:
  4. Security & Permissions:
    • Gated under reports.daily-sales.export / ROLE_ACCESS.owner (consistent with daily financial exports).

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.ts covering:
    • Sequence order and refund badge inclusion.
    • Cover page total matching the daily sales .xlsx calculation.
    • Cross-midnight business day boundary filtering.
    • Role-gating rejection.
  • Run npm run lint && npm test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendBackend (Express/SQLite)area:frontendFrontend (React/Next.js)enhancementNew feature or requesttype:featureNew capability or enhancement request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions