6.8 KiB
6.8 KiB
Task E: Quotation Production Module
1. Files Added
src/app/api/crm/quotations/route.tssrc/app/api/crm/quotations/[id]/route.tssrc/app/api/crm/quotations/[id]/items/route.tssrc/app/api/crm/quotations/[id]/items/[itemId]/route.tssrc/app/api/crm/quotations/[id]/customers/route.tssrc/app/api/crm/quotations/[id]/topics/route.tssrc/app/api/crm/quotations/[id]/followups/route.tssrc/app/api/crm/quotations/[id]/attachments/route.tssrc/app/api/crm/quotations/[id]/revisions/route.tssrc/features/crm/quotations/api/types.tssrc/features/crm/quotations/api/service.tssrc/features/crm/quotations/api/queries.tssrc/features/crm/quotations/api/mutations.tssrc/features/crm/quotations/schemas/quotation.schema.tssrc/features/crm/quotations/server/service.tssrc/features/crm/quotations/components/quotation-status-badge.tsxsrc/features/crm/quotations/components/quotation-form-sheet.tsxsrc/features/crm/quotations/components/quotation-cell-action.tsxsrc/features/crm/quotations/components/quotation-columns.tsxsrc/features/crm/quotations/components/quotations-table.tsxsrc/features/crm/quotations/components/quotation-listing.tsxsrc/features/crm/quotations/components/quotation-detail.tsxdrizzle/0004_worthless_ender_wiggin.sqldrizzle/meta/0004_snapshot.json
2. Files Modified
src/app/dashboard/crm/quotations/page.tsxsrc/app/dashboard/crm/quotations/[id]/page.tsxsrc/app/dashboard/crm/enquiries/[id]/page.tsxsrc/app/dashboard/crm/customers/[id]/page.tsxsrc/features/crm/enquiries/components/enquiry-detail.tsxsrc/features/crm/customers/components/customer-detail.tsxsrc/db/schema.tssrc/db/seeds/foundation.seed.tssrc/lib/auth/rbac.tssrc/lib/searchparams.tsdrizzle/meta/_journal.json
3. Schema Added
crm_quotations- organization-scoped quotation master with document code, customer/contact/enquiry linkage, pricing header, status, revision metadata, and soft-delete columns
crm_quotation_items- server-calculated line items under quotation
crm_quotation_customers- related parties such as owner, consultant, contractor, and billing
crm_quotation_topics- quotation document sections such as scope, exclusions, and payment
crm_quotation_topic_items- topic bullet items stored under each section
crm_quotation_followups- post-send follow-up timeline under quotation
crm_quotation_attachments- metadata-only attachment registry for future file-storage integration
4. API Routes Added
GET /api/crm/quotationsPOST /api/crm/quotationsGET /api/crm/quotations/[id]PATCH /api/crm/quotations/[id]DELETE /api/crm/quotations/[id]GET /api/crm/quotations/[id]/itemsPOST /api/crm/quotations/[id]/itemsPATCH /api/crm/quotations/[id]/items/[itemId]DELETE /api/crm/quotations/[id]/items/[itemId]GET /api/crm/quotations/[id]/customersPOST /api/crm/quotations/[id]/customersPATCH /api/crm/quotations/[id]/customersDELETE /api/crm/quotations/[id]/customersGET /api/crm/quotations/[id]/topicsPOST /api/crm/quotations/[id]/topicsPATCH /api/crm/quotations/[id]/topicsDELETE /api/crm/quotations/[id]/topicsGET /api/crm/quotations/[id]/followupsPOST /api/crm/quotations/[id]/followupsPATCH /api/crm/quotations/[id]/followupsDELETE /api/crm/quotations/[id]/followupsGET /api/crm/quotations/[id]/attachmentsPOST /api/crm/quotations/[id]/attachmentsPATCH /api/crm/quotations/[id]/attachmentsDELETE /api/crm/quotations/[id]/attachmentsGET /api/crm/quotations/[id]/revisionsPOST /api/crm/quotations/[id]/revisions
5. UI Routes Completed
/dashboard/crm/quotations- production list with React Query, nuqs filters, create button, edit/view/delete actions
- filters: search, status, quotation type, branch, customer, enquiry, hot project
/dashboard/crm/quotations/[id]- detail page with tabs: Overview, Items, Customers, Topics, Follow-ups, Attachments, Activity, Approval Placeholder, Document Preview Placeholder
- revision chain card with create-revision action
/dashboard/crm/enquiries/[id]- related quotations tab now shows real quotation links for the enquiry
/dashboard/crm/customers/[id]- related documents tab now shows both enquiries and quotations for the customer
6. Permissions Used
crm.quotation.readcrm.quotation.createcrm.quotation.updatecrm.quotation.deletecrm.quotation.item.managecrm.quotation.customer.managecrm.quotation.topic.managecrm.quotation.followup.managecrm.quotation.attachment.managecrm.quotation.revision.create
Admin defaults include the full quotation permission set. Regular users inherit read access only unless their membership permissions are extended.
7. Audit Integration
- quotation create/update/delete writes audit entries with
entityType = crm_quotation - item create/update/delete writes audit entries with
entityType = crm_quotation_item - related customer create/update/delete writes audit entries with
entityType = crm_quotation_customer - topic create/update/delete writes audit entries with
entityType = crm_quotation_topic - follow-up create/update/delete writes audit entries with
entityType = crm_quotation_followup - attachment metadata create/update/delete writes audit entries with
entityType = crm_quotation_attachment - quotation detail activity tab now surfaces all quotation-side audit mutations together
8. Document Sequence And Totals
- quotation create uses
generateNextDocumentCode({ documentType: 'quotation' }) - revisions also consume the same document sequence and keep
parentQuotationIdlinkage - item totals are calculated on the server
- quotation subtotal, tax, and total are refreshed from current line items after item mutations
9. Enquiry And Customer Integration
- quotation create/update validates customer, contact, enquiry, branch, and salesman membership against the active organization
- selecting an enquiry in the quotation form auto-fills customer/contact/project context where available
- enquiry detail now links to real quotations instead of the old Task D placeholder
- customer detail now links to both related enquiries and related quotations
10. Remaining Risks
- quotation item
taxRateis stored per line, but current aggregate total refresh still uses quotation-header tax for the final quote summary rather than a mixed per-line tax rollup - attachment handling is metadata-only; there is still no binary upload/storage pipeline
- revision creation copies header, items, customers, and topics, but does not snapshot follow-ups or attachments
- there are still no database foreign keys between quotation tables and the linked CRM entities; organization scoping is enforced in application logic
11. Verification
npx tsc --noEmitnpm run gen