Skip to content

Invoice Audit Trail PDF Export #420

Description

@Kingsman-99

Description

For financial compliance, organizations need a tamper-evident PDF document that records every state change, payment event, and user action on an invoice from creation to closure. This issue generates a formal audit trail PDF for any invoice on demand, including a chronological event table, transaction hashes with links, actor identities, timestamps, and an optional digital signature field for the creator. The PDF must be generated server-side to prevent client-side manipulation.

Technical Context

Create app/api/invoices/[id]/audit-pdf/route.ts as a server-side PDF generation endpoint using @react-pdf/renderer or pdfkit. The endpoint collects all AuditLog entries for the invoice (status changes, payment confirmations, co-creator actions, comment additions), sorts them chronologically, and renders them as a table. Each entry includes: timestamp, actor, action, previousValue, newValue, txHash (if applicable). Add a page header with the invoice ID, creator name, creation date, and platform logo. Append a SHA-256 hash of the event table data as a verification footer. Expose the download button on app/invoice/[id]/page.tsx in an "Audit" dropdown. The PDF must be generated with a consistent Content-Disposition: attachment header to trigger browser download.

Acceptance Criteria

  • The generated PDF contains all audit log entries for the invoice in chronological order with no entries missing
  • Each entry row shows the correct actor name, action description, before/after values, and timestamp in UTC ISO-8601 format
  • Transaction hashes in the PDF are formatted as clickable links pointing to the user's preferred explorer (resolved server-side from settings)
  • The SHA-256 verification hash in the footer matches the hash of the event table data computable independently from the raw audit log
  • The download endpoint responds within 5 seconds for invoices with up to 500 audit entries and returns a valid PDF MIME type
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions