4.0 KiB
4.0 KiB
Task H - PDF Generation and Approved Document Persistence
Files Added
src/features/foundation/pdf-generator/server/service.tssrc/app/api/crm/quotations/[id]/pdf-preview/route.tssrc/app/api/crm/quotations/[id]/pdf-download/route.tssrc/app/api/crm/quotations/[id]/approved-pdf/route.tsdrizzle/0007_luxuriant_malice.sql
Files Modified
package.jsonpackage-lock.jsonsrc/components/icons.tsxsrc/db/schema.tssrc/lib/auth/rbac.tssrc/features/crm/quotations/api/types.tssrc/features/crm/quotations/server/service.tssrc/features/crm/quotations/document/types.tssrc/features/crm/quotations/document/server/service.tssrc/features/foundation/approval/server/service.tssrc/app/dashboard/crm/quotations/[id]/page.tsxsrc/features/crm/quotations/components/quotation-detail.tsxsrc/features/crm/enquiries/components/enquiry-form-sheet.tsxsrc/features/crm/enquiries/schemas/enquiry.schema.tssrc/features/crm/quotations/schemas/quotation.schema.tsdocs/implementation/technical-debt.md
PDF Generator Added
- Added production server-side
pdfmegeneration insrc/features/foundation/pdf-generator/server/service.ts. - Installed:
@pdfme/common@pdfme/generator@pdfme/schemas
- Implemented:
generatePdfFromTemplate()generateQuotationPdf()generateQuotationPreviewPdf()generateApprovedQuotationPdf()getStoredApprovedQuotationPdf()
API Routes Added
GET /api/crm/quotations/[id]/pdf-previewGET /api/crm/quotations/[id]/pdf-downloadGET /api/crm/quotations/[id]/approved-pdfPOST /api/crm/quotations/[id]/approved-pdf
Behavior:
- preview returns inline PDF from current quotation state
- download returns attachment PDF from current quotation state
- approved-pdf POST generates, persists, audits, and returns the approved PDF
- approved-pdf GET streams the already stored approved artifact
UI Actions Added
Quotation detail now supports:
Preview PDFDownload PDFGenerate Approved PDFView Approved PDF
The detail page also now displays:
Approved AtApproved Template Version
Approved Snapshot Persistence
Added quotation persistence fields:
approvedAtapprovedPdfUrlapprovedSnapshotapprovedTemplateVersionId
Approved snapshot now stores:
- quotation id
- approved timestamp
- normalized document data
- template version id
- mapped template input
- generated timestamp
- generated by user id
Attachment Metadata Integration
After generating an approved PDF:
- a local file is written under
public/generated/quotations/<organizationId>/ - quotation attachment metadata is created or updated with:
fileNameoriginalFileNamefilePathfileSizefileType = application/pdfdescription = Approved quotation PDFuploadedByuploadedAt
Permission Added
crm.quotation.pdf.previewcrm.quotation.pdf.downloadcrm.quotation.pdf.generate_approved
Audit Integration
Required audit was added for approved PDF generation with:
entityType = crm_quotation_pdf_generate_approvedaction = generate_approved
Preview and download remain unaudited by design.
Remaining Risks
- Current
pdfmegeneration uses a font fallback normalization step because the provided templates referencecordia/cordiaBold, while direct TTC-based rendering did not behave reliably with table layout generation. - Approved PDF storage uses local filesystem placeholder output under
public/generated/..., not external object storage. - The environment used during implementation had no quotation rows available in the database, so full quotation-specific end-to-end smoke testing through a live record could not be completed here.
Task I Readiness
Task H leaves the repo ready for:
- auto-generate approved PDF after final approval
- object-storage abstraction
- signed download / retention policy
- immutable approved artifact lifecycle rules
- richer template version publish controls