Commit Graph

105 Commits

Author SHA1 Message Date
kevin-asprec
a59a246fdc fix(05-06): add Collection and Remittance CASL subjects, update routes
- Add Collection and Remittance to AppSubjects union type
- Grant OFFICE_STAFF manage:Collection and manage:Remittance
- Grant COLLECTOR create/read:Collection and create/read:Remittance
- Update all 8 collection/remittance route handlers from Subscriber to
  their dedicated CASL subjects (Collection or Remittance)
- Update JSDoc comments in route files to reflect new subject names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:28:07 +08:00
kevin-asprec
a0ea504af3 docs(05-07): correct Phase 2 VERIFICATION.md to reflect fixed state
- Status: gaps_found -> passed (5/5 must-haves verified)
- Truth #3: FAILED -> VERIFIED (fixed post-verification)
- BILL-03: BLOCKED -> SATISFIED (invoices now created as SENT)
- Key link billing-service.ts -> Invoice(status=SENT): NOT WIRED -> WIRED
- Anti-pattern marked as resolved
- Added re-verification note: 2026-03-05

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:26:54 +08:00
kevin-asprec
b462120d5e fix(05-06): add 6 missing models to tenant scoping
- Add expense, expenseCategory, inventoryItem, stockMovement, vendor,
  ticketComment to TENANT_SCOPED_MODELS (22 -> 28 models)
- Add complete $extends query blocks for each model with all 14 operations
  (findMany, findFirst, findUnique, create, update, delete, etc.)
- Closes P0 tenant isolation gap where these models bypassed app-layer scoping

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:25:55 +08:00
kevin-asprec
f0d2725dc2 feat(05-07): add inventory/expense and portal ticket E2E workflows
- Workflow 4: inventory receiving with balanced JE (DR 1200 / CR 2010)
- Workflow 4: expense recording with auto-post JE (DR 5040 / CR 1010)
- Workflow 4: trial balance verification after inventory/expense txns
- Workflow 5: portal ticket creation via createPortalTicket service
- Workflow 5: staff queue visibility and shadow user verification
- 21 total E2E tests (up from 16), all passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:25:28 +08:00
kevin-asprec
9fdca2ccf7 docs(05): create gap closure plans for milestone audit findings
Phase 05: 2 gap closure plans in 1 wave
- 05-06: P0 tenant scoping fix (6 models) + CASL subject correction
- 05-07: E2E test coverage gaps + Phase 2 verification correction
- Both plans are parallel (Wave 1, no dependencies)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 18:15:44 +08:00
kevin-asprec
e70501e8bc docs(05): complete Visibility and Client Portal phase
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:57:08 +08:00
kevin-asprec
f5d20711b0 docs(05-04): complete API RBAC Integration Tests plan
Tasks completed: 1/1
- API RBAC integration test suite (43 tests)

SUMMARY: .planning/phases/05-visibility-and-client-portal/05-04-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:45:56 +08:00
kevin-asprec
430c8ee7f8 test(05-04): add comprehensive API RBAC integration tests
- 43 tests covering authentication (401), authorization (403), and tenant isolation
- withPermission HOF returns 401 for unauthenticated, 403 for unauthorized
- withPortalAuth returns 401/403 for non-portal users
- All 5 roles (ADMIN, OFFICE_STAFF, COLLECTOR, TECHNICIAN, CLIENT) tested against all subjects
- COLLECTOR cannot access billing/reports/subscriber management writes
- TECHNICIAN cannot access payment/invoice/report endpoints
- CLIENT can only read own data, create tickets
- Two-tenant isolation: subscribers, invoices, payments invisible across tenants
- Cross-tenant ID lookup returns null (no data leakage)
- INFRA-03 satisfied

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:44:19 +08:00
kevin-asprec
276bc08ef4 docs(05-05): complete End-to-End Workflow Tests plan
Tasks completed: 2/2
- Task 1: Billing workflow end-to-end test
- Task 2: Collection and ticket workflow end-to-end tests

SUMMARY: .planning/phases/05-visibility-and-client-portal/05-05-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:43:36 +08:00
kevin-asprec
24824271a2 feat(05-05): collection/remittance and ticket/job-order e2e tests
- Collection workflow: field collection -> FIFO allocation -> remittance -> verification -> balanced JEs
- Ticket workflow: create -> job order -> IN_PROGRESS -> COMPLETED -> auto-resolve -> close
- Dashboard reflects collection activity (collectionsToday, unverifiedRemittances)
- Trial balance balanced after every workflow
- 16 tests total across 3 critical business processes (INFRA-04)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:42:13 +08:00
kevin-asprec
abf9ee0eae feat(05-05): billing workflow end-to-end test
- Subscriber registration -> invoice generation -> payment recording
- Full payment marks invoice PAID with correct JE (DR Cash, CR AR)
- Partial payment marks invoice PARTIAL with balanced JE
- Trial balance verified balanced after all transactions
- Dashboard reflects billing activity (revenue + subscriber metrics)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:41:07 +08:00
kevin-asprec
82c8dc39d1 docs(05-03): complete Portal Ticket Submission and Payment Scaffold plan
Tasks completed: 2/2
- Task 1: TicketComment model and portal ticket service
- Task 2: Portal ticket API routes, payment scaffold, and tests

SUMMARY: .planning/phases/05-visibility-and-client-portal/05-03-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:36:59 +08:00
kevin-asprec
3f44f5c953 feat(05-03): portal ticket API routes, payment scaffold, and tests
- GET/POST /api/portal/tickets for listing and creating tickets
- GET /api/portal/tickets/[id] for ticket detail with conversation
- GET/POST /api/portal/tickets/[id]/comments for conversation threads
- GET /api/portal/payments/coming-soon returns outstanding balance and payment instructions
- 6 integration tests: SUBSCRIBER source, staff visibility, isolation, comments, closed rejection, thread ordering

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:35:25 +08:00
kevin-asprec
2d5b9ca2aa feat(05-03): TicketComment model and portal ticket service
- Add TicketComment model for conversation threads (append-only)
- Add paymentInstructions field to TenantSettings
- Add ticketComments relation to User model
- Create portal-ticket-service with ensurePortalUser shadow User pattern
- Implements createPortalTicket, listPortalTickets, getPortalTicket, addTicketComment
- Portal ticket creation delegates to existing createTicket with source=SUBSCRIBER

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:33:13 +08:00
kevin-asprec
ab1e94480e docs(05-02): complete Subscriber Portal Auth and API plan
Tasks completed: 2/2
- Portal authentication via subscriber account number
- PortalService, API routes, and integration tests (5 tests)

SUMMARY: .planning/phases/05-visibility-and-client-portal/05-02-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:28:03 +08:00
kevin-asprec
7222dbeafe feat(05-02): portal service, API routes, and integration tests
- Create PortalService with getPortalAccount, getPortalInvoices, getPortalPayments
- All queries scoped to single subscriberId (no cross-subscriber access)
- Create withPortalAuth middleware (validates subscriberId in session)
- Add GET /api/portal/account (subscriber profile + plan details)
- Add GET /api/portal/invoices (paginated, includes line items)
- Add GET /api/portal/payments (paginated payment history)
- Add 5 integration tests: account details, pagination, isolation, line items

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:25:18 +08:00
kevin-asprec
7de961f6c7 docs(05-01): complete Dashboard Metrics API plan
Tasks completed: 2/2
- DashboardService with 6 metric aggregation methods
- GET /api/dashboard endpoint and 6 integration tests

SUMMARY: .planning/phases/05-visibility-and-client-portal/05-01-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:24:50 +08:00
kevin-asprec
5b1b4ee0e1 feat(05-01): add Dashboard API route and integration tests
- GET /api/dashboard with read Report permission (ADMIN, OFFICE_STAFF)
- Optional startDate/endDate query params for cash flow date range
- 6 integration tests verifying all metric methods against seeded data
- Tests cover revenue, overdue, subscriber status, cash flow, collectors
- Comprehensive cleanup order for dashboard test data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:23:16 +08:00
kevin-asprec
539564dbd4 feat(05-02): portal authentication via subscriber account number
- Add passwordHash field to Subscriber model (nullable for existing subscribers)
- Add portal-credentials NextAuth provider (accountNumber + password + tenantId)
- Persist subscriberId in JWT token and session for portal user identification
- Extend next-auth types with optional subscriberId on Session, User, and JWT
- Exclude /portal/login and /api/portal/auth from middleware auth requirement

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:22:52 +08:00
kevin-asprec
7fabb77ee4 feat(05-01): add DashboardService with metric aggregation
- getRevenueMetrics: today + month revenue from COMPLETED payments
- getOverdueMetrics: overdue subscriber count + outstanding total
- getSubscriberMetrics: active/suspended/cancelled status breakdown
- getCashFlowSummary: money in vs out from POSTED JE lines
- getCollectorSummary: today's collections + unverified remittances
- getDashboardSummary: aggregator calling all five methods in parallel

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:21:34 +08:00
kevin-asprec
ea58620c7d docs(05): create phase plan
Phase 05: Visibility and Client Portal
- 5 plans in 3 waves
- 2 parallel (wave 1), 1 sequential (wave 2), 2 parallel (wave 3)
- Ready for execution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:14:54 +08:00
kevin-asprec
5276f3bbf4 docs(05): capture phase context
Phase 05: Visibility and Client Portal
- Implementation decisions documented
- Phase boundary established

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 17:01:38 +08:00
kevin-asprec
517454b329 docs(04): complete Inventory, Expenses, and Financial Reports phase
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 15:57:57 +08:00
kevin-asprec
0316bb211f fix(04-05): add missing financial-report-service.ts to git
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 15:13:26 +08:00
kevin-asprec
df3e36b7a2 docs(04-04): complete Expense Reports and Audit Trail plan
Tasks completed: 2/2
- ExpenseReportService and AuditTrailService with API routes
- 9 passing integration tests

SUMMARY: .planning/phases/04-inventory-expenses-and-financial-reports/04-04-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 15:11:49 +08:00
kevin-asprec
787b22e6a1 test(04-04): expense report and audit trail tests -- 9 passing
- Expense by category: correct totals, excludes DRAFT/VOIDED
- Expense by vendor: correct totals, No Vendor bucket
- Expense summary: combined view with grand total
- Date range filtering works
- JE audit trail: createdBy, source, referenceType for expense JE
- Audit trail for entity: original + void reversal entries
- Cross-source audit: Payment JE referenceType correctly returned

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 14:52:44 +08:00
kevin-asprec
6bc24a3fb4 feat(04-04): ExpenseReportService, AuditTrailService, and API routes
- ExpenseReportService: getExpensesByCategory, getExpensesByVendor, getExpenseSummary
- AuditTrailService: getJournalEntryAudit, getAuditTrailForEntity (ACCT-08)
- GET /api/reports/expenses -- expense summary by category
- GET /api/reports/expenses/by-vendor -- expense summary by vendor
- GET /api/accounting/journal-entries/[id]/audit -- JE audit trail

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 14:44:13 +08:00
kevin-asprec
e3a177f194 docs(04-02): complete asset management plan — Phase 4 complete
Tasks completed: 2/2
- AssetService with assign, return, dispose, history
- 11 integration tests all passing

SUMMARY: .planning/phases/04-inventory-expenses-and-financial-reports/04-02-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 14:34:09 +08:00
kevin-asprec
0f733627bd test(04-02): asset service tests — 11 cases covering full lifecycle
- Assign to subscriber/technician creates correct ISSUED movements
- Return from subscriber/technician creates RETURNED with condition
- Rejects reassignment without return, rejects batch items
- Admin disposal creates write-off JE (DR 5030, CR 1200)
- Non-admin disposal rejected, field disposal rejected
- History returns chronological timeline with resolved names
- Full lifecycle: RECEIVED->ISSUED->RETURNED->ISSUED->RETURNED->DISPOSED

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:59:51 +08:00
kevin-asprec
eb29d6e3be feat(04-02): AssetService with assign, return, dispose, and history APIs
- AssetService: assignToSubscriber, assignToTechnician, returnAsset, disposeAsset, getAssetHistory
- getCurrentLocation helper derives location from latest movement
- Disposal validates ADMIN role and creates write-off JE (DR 5030, CR 1200)
- API routes: POST assign, POST return, POST dispose, GET history
- Location history resolves subscriber/technician/warehouse names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:20:10 +08:00
kevin-asprec
6dd1fe827c docs(04-05): complete financial reports plan
Tasks completed: 2/2
- Financial report API routes (trial balance, income statement, balance sheet, drill-down)
- Comprehensive tests (16 passing — all 3 reports verified)

SUMMARY: .planning/phases/04-inventory-expenses-and-financial-reports/04-05-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 13:00:04 +08:00
kevin-asprec
1dd423ca43 test(04-05): comprehensive financial report tests — 16 passing, all 3 reports verified
- Trial Balance: debits = credits (isBalanced), per-account balances, asOfDate filter
- Income Statement: revenue/expense sections, net income = 600, header exclusion, date range
- Balance Sheet: A = L + E (isBalanced), cash = 600, net income in equity, date filter
- Drill-down: running balance, entry metadata (entryNumber, referenceType)
- Edge cases: empty tenant balanced, leaf-only accounts across all reports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 12:35:50 +08:00
kevin-asprec
5366e8c1ad feat(04-05): financial report API routes — trial balance, income statement, balance sheet, drill-down
- GET /api/reports/trial-balance with optional asOfDate filter
- GET /api/reports/income-statement with required startDate/endDate
- GET /api/reports/balance-sheet with required asOfDate
- GET /api/reports/accounts/[id]/entries drill-down with optional date range
- All routes use withPermission("read", "Report") for ADMIN access
- FinancialReportService already existed with all 4 methods

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 12:31:33 +08:00
kevin-asprec
cc8314f854 docs(04-03): complete expense tracking plan
Tasks completed: 2/2
- Task 1: Schema + COA additions + expense category seeding
- Task 2: VendorService, ExpenseService, API routes, migration, 15 tests

SUMMARY: .planning/phases/04-inventory-expenses-and-financial-reports/04-03-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:53:50 +08:00
kevin-asprec
b7bbc50b2b feat(04-03): VendorService, ExpenseService, API routes, migration, and 15 passing tests
- VendorService: CRUD with unique name validation per tenant
- ExpenseService: create, approve, post, void with full JE integration
- Auto-generated EXP-NNNN expense numbers per tenant
- JE posting: DR category expense account, CR cash (1010) or bank (1020)
- Optional approval workflow: requireApproval flag controls DRAFT-only vs immediate post
- Void reverses JE via JournalEntryService.reverseEntry
- Custom category creation with COA account validation
- System categories protected from deletion
- API routes: expenses CRUD, approve, categories CRUD, vendors CRUD
- Migration: add_expense_vendor_models applied via db push + resolve
- 15 integration tests covering all expense lifecycle scenarios

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:52:07 +08:00
kevin-asprec
fe4d22f440 feat(04-03): Vendor, ExpenseCategory, Expense schema + category seeding + COA additions
- Add ExpenseStatus and ExpensePaymentMethod enums
- Add Vendor model (@@unique([tenantId, name]))
- Add ExpenseCategory model with accountCode linking to COA
- Add Expense model with approval workflow and JE reference
- Add User relations: createdExpenses, approvedExpenses
- Add COA accounts 5080 Fuel/Transportation, 5085 Rent Expense (31 total)
- Seed 9 default expense categories in createTenant transaction
- Add Vendor subject to CASL types, Expense/Vendor permissions for OFFICE_STAFF

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:38:03 +08:00
kevin-asprec
daf5bddf0b docs(04-01): complete inventory event-ledger plan
Tasks completed: 2/2
- Task 1: Schema — InventoryItem, StockMovement models and enums
- Task 2: InventoryService, API routes, migration, and tests (13 passing)

SUMMARY: .planning/phases/04-inventory-expenses-and-financial-reports/04-01-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:33:18 +08:00
kevin-asprec
a742f701e7 feat(04-01): InventoryService, API routes, migration, and 13 passing tests
- InventoryService: registerItem, recordMovement, getStockLevels, getItemMovements, listItems
- RECEIVED movements auto-post JE (DR 1200 Equipment Inventory, CR 2010 AP)
- Stock levels derived from movement aggregation (no mutable quantity column)
- All 5 movement types validated with type-specific rules
- API routes: POST/GET items, GET item detail, POST/GET movements, GET stock-levels
- CASL: OFFICE_STAFF gets manage Inventory permission
- Migration applied: add_inventory_models (4 enums, 2 tables)
- 13 tests: registration, all movement types, stock derivation, JE posting, history

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:31:44 +08:00
kevin-asprec
3712600c4e feat(04-01): InventoryItem and StockMovement schema with enums
- Add ItemTrackingType (SERIALIZED/BATCH), ItemCondition, MovementType, LocationType enums
- Add InventoryItem model with dual tracking (serialized by serial number, batch by quantity)
- Add StockMovement model as immutable movement ledger (no updatedAt)
- Add recordedMovements relation on User model
- Indexes on tenantId, itemType, trackingType, inventoryItemId, movementType

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:17:28 +08:00
kevin-asprec
b5f2f3946b docs(04): create phase plan — Inventory, Expenses, and Financial Reports
Phase 04: 5 plans in 2 waves
- Wave 1: 04-01 (inventory event-ledger), 04-03 (expense tracking), 04-05 (financial reports) — parallel
- Wave 2: 04-02 (asset management), 04-04 (expense reports + audit trail) — sequential
- Ready for execution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 10:00:55 +08:00
kevin-asprec
d8bf8d52ac docs(04): capture phase context
Phase 04: Inventory, Expenses, and Financial Reports
- Implementation decisions documented
- Phase boundary established

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 09:50:43 +08:00
kevin-asprec
2fa5cdb9b5 docs(03): complete Operational Modules phase
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 08:44:53 +08:00
kevin-asprec
f49bbf32b5 docs(03-05): complete technician management plan — Phase 3 complete
Tasks completed: 2/2
- Task 1: TechnicianProfile/JobTypeRate schema, migration, tenant scoping
- Task 2: Technician service, compensation service, 6 APIs, 27 integration tests

SUMMARY: .planning/phases/03-operational-modules/03-05-SUMMARY.md
2026-03-05 08:19:11 +08:00
kevin-asprec
fba2ba4bf9 feat(03-05): technician service, compensation service, APIs, and 27 passing tests
- technician-service.ts: createTechnicianProfile, updateTechnicianProfile, getTechnicianProfile, getTechnicianProfileByUserId, listTechnicians
- compensation-service.ts: getCompensationSummary (all 3 models), getTechnicianCompensationDetail (job-by-job)
- 6 API routes: GET/POST /api/technicians, GET/PUT /api/technicians/[id], GET /api/technicians/[id]/compensation, GET/POST /api/job-type-rates, PUT /api/job-type-rates/[id], GET /api/reports/compensation
- Added TechnicianProfile and JobTypeRate to CASL AppSubjects; OFFICE_STAFF read access
- 27 integration tests: all 3 models, missing rate defaults to 0, only COMPLETED count, date range filter, summary+detail reports, cross-tenant isolation — all green
2026-03-05 08:17:03 +08:00
kevin-asprec
230b0ec683 feat(03-05): TechnicianProfile/JobTypeRate schema, migration, tenant scoping
- Added CompensationModel enum (PER_JOB, SALARY, HYBRID)
- Added TechnicianProfile model with userId FK, skills[], zoneId?, compensationModel, monthlySalary?, isActive, @@unique([tenantId,userId])
- Added JobTypeRate model with jobType, rate, isActive, @@unique([tenantId,jobType])
- Added reverse relations: User.technicianProfiles[], Zone.technicianProfiles[]
- Applied migration: 20260305000851_add_technician_profiles
- Added technicianProfile and jobTypeRate to TENANT_SCOPED_MODELS with full 12-operation extension blocks
2026-03-05 08:10:46 +08:00
kevin-asprec
bdd0fda7d2 docs(03-04): complete Job Orders plan
Tasks completed: 2/2
- Task 1: JobOrder schema, migration, and tenant scoping
- Task 2: Job order service, API routes, and integration tests

SUMMARY: .planning/phases/03-operational-modules/03-04-SUMMARY.md
2026-03-05 08:05:50 +08:00
kevin-asprec
86284f1f5b feat(03-04): job order service, API routes, and 17 passing integration tests
- Added checkTicketAutoResolve/checkTicketRevertToOpen to ticket-service.ts
- Created job-order-service.ts: createJobOrder, updateJobOrderStatus, updateJobOrder,
  getJobOrder, listJobOrders, getMyJobOrders with VALID_JO_TRANSITIONS guard map
- PENDING->IN_PROGRESS->COMPLETED(outcomeNotes required)/CANCELLED lifecycle enforced
- OPEN ticket auto-transitions to ASSIGNED on first job order creation
- Auto-resolves ticket when all non-cancelled jobs COMPLETED
- Reverts ticket to OPEN when all jobs CANCELLED
- Created POST /api/tickets/[id]/job-orders, GET/PUT /api/job-orders/[id],
  POST /api/job-orders/[id]/status, GET /api/job-orders (with TECHNICIAN filter)
- 17 integration tests: lifecycle, auto-resolve, revert-to-open, partial completion,
  technician self-service, cross-tenant isolation — all green
2026-03-05 08:04:21 +08:00
kevin-asprec
d59f1d55ea feat(03-04): JobOrder schema, migration, and tenant scoping
- Added JobOrderStatus enum (PENDING, IN_PROGRESS, COMPLETED, CANCELLED)
- Added JobOrder model with ticket FK, assignedTo/createdBy user FKs
- Added orderNumber (JO-NNNN), scheduledDate, timestamps, outcomeNotes
- Added jobOrders reverse relation on Ticket model
- Added assignedJobOrders/createdJobOrders reverse relations on User model
- Applied migration: 20260304235859_add_job_orders
- Added jobOrder to TENANT_SCOPED_MODELS with full 12-operation extension block
2026-03-05 07:59:56 +08:00
kevin-asprec
0373810d9e docs(03-02): complete Collector Collection and Remittance plan
Tasks completed: 2/2
- Task 1: Collection/Remittance schema, 1030 COA, migration, tenant scoping
- Task 2: Collector service, remittance service, report service, APIs, 26 tests

SUMMARY: .planning/phases/03-operational-modules/03-02-SUMMARY.md
2026-03-05 07:56:20 +08:00
kevin-asprec
a72aaa987d feat(03-02): Collector service, remittance service, report service, APIs, and tests
- collector-service.ts: recordCollection (FIFO, zone enforcement, DR 1030/CR 1100 JE),
  voidCollection (reversing JE), getCollectionHistory
- remittance-service.ts: createRemittance, verifyRemittance (DR 1010/CR 1030, variance
  non-blocking), listRemittances
- collection-report-service.ts: getDailyCollectionSummary, getCollectorCollectionDetail
- 6 API routes: POST/GET /collections, GET /collections/[id],
  POST /collections/[id]/void, POST/GET /remittances,
  POST /remittances/[id]/verify, GET /reports/collections
- 26 integration tests: 13 collector (FIFO, zone enforcement, JE verification, void,
  cross-tenant) + 13 remittance (variance, JE accounts, double-verify rejection)
- All 26 tests pass
2026-03-05 07:54:39 +08:00