Skip to main content

Overview — CIMA Supplier Data Flow

Purpose

This chapter documents how CIMA supplier delivery data flows into the Order table via background cron jobs. There are two independent entry points (Flow A and Flow B), both ultimately syncing CIMA data into the order.


Flow A — CIMA Lorry In/Out Report File Upload

Triggered when a CIMA Lorry In/Out Report file is uploaded.

User uploads CimaLorryInOutReport file (via API)
  │
  └─ afterCreate hook (hooks.ts)
       └─ Creates MicroserviceTask:
            code:  'Process CIMA Lorry In_Out Report'
            value: { cima_lorry_in_out_report_id }
  │
  └─ Cron: processCimaLorryInoutReports (every 2 hours)
       ├─ Fetch all Pending tasks for 'Process CIMA Lorry In_Out Report'
       ├─ Mark all as Running
       └─ For each task:
            ├─ Load CimaLorryInOutReport by id
            ├─ Call cimaLorryInOutReportService.processCimaLorryInOutReport()
            │    └─ Parses file → populates CimaDeliveryInfo records
            ├─ On success → mark task 'Success'
            │    └─ Creates MicroserviceTask:
            │         code: 'Auto Update CIMA Supplier Data By Supplier Data'
            └─ On failure → mark task 'Fail'
  │
  └─ Cron: autoUpdateCIMASupplierDataBySupplierData (every 10 minutes)
       └─ See details: autoUpdateCIMASupplierDataBySupplierData

Flow B — Order Document OCR Upload

Triggered when an Order Document is uploaded and OCR-processed.

User uploads OrderDocument (OCR processed)
  │
  └─ order-document.service.ts
       ├─ If autoUpdateFor = 'CIMA' AND SO# matches order:
       │    ├─ Sets OrderDocument.documentStatus → 'Pending Auto Update (CIMA)'
       │    └─ Creates MicroserviceTask:
       │         code:  'Auto Update CIMA Supplier Data'
       │         value: { orderDocumentId }
       └─ If SO# does NOT match:
            └─ Sets OrderDocument.documentStatus → 'Auto Rejected'
  │
  └─ Cron: autoUpdateCIMASupplierData (every 3 minutes)
       └─ See details: autoUpdateCIMASupplierData

Task Code Reference

MicroserviceTask Code Created By Processed By Schedule
Process CIMA Lorry In_Out Report afterCreate hook on file upload processCimaLorryInoutReports Every 2 hours
Auto Update CIMA Supplier Data By Supplier Data processCimaLorryInoutReports (after file parsed) autoUpdateCIMASupplierDataBySupplierData Every 10 minutes
Auto Update CIMA Supplier Data order-document.service.ts (after OCR) autoUpdateCIMASupplierData Every 3 minutes

Flow A vs Flow B — Key Differences

Flow A Flow B
Entry point File upload → afterCreate hook OCR document upload → service
CimaDeliveryInfo matching Batch — all Pending by DO# + plateNo + autoUpdateFor Single — by orderDocumentId directly
OrderDocument status update Only if Pending Auto Update (CIMA) Always set to Auto Approved
saleOrderNo backfill No Yes — if cimaInfo.saleOrderNo is null
Processing frequency Every 10 minutes (after 2hr file parse) Every 3 minutes