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 by a scheduled cron that instructs RPA to download the CIMA Lorry In/Out Report, which is then uploaded and processed.
Cron: createMsRpaDownloadCimaLorryInOut (every 2 hours)
└─ Creates 2 MicroserviceTasks:
code: 'Download CIMA TRN Report'
code: 'Download CIMA DST Report'
value: { deliveryDateFrom: yesterday, deliveryDateTo: today,
productForm: 'Bulk', reportCode: ... }
│
└─ RPA picks up tasks → downloads report from CIMA portal
└─ Calls API: POST /cimaLorryInOutReports/createWithFile
└─ afterCreate hook (hooks.ts)
└─ Creates MicroserviceTask:
code: 'Process CIMA Lorry In_Out Report'
value: { cima_lorry_in_out_report_id }
│
└─ Cron: processCimaLorryInoutReports (every 10 minutes)
└─ Pick up 1 Pending task at a time (pessimistic lock)
├─ 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)
└─ Pick up 1 Pending task at a time (pessimistic lock)
├─ Fetch all CimaDeliveryInfo where status=Pending AND delivery_datetime >= now - 1 month
├─ For each record:
│ ├─ Find OrderDocument by DO# + plateNo + autoUpdateFor='CIMA'
│ ├─ Check documentStatus is Approved / Auto Approved / Pending Auto Update (CIMA)
│ ├─ Update Order fields (weights, sealNo, supplierDoDatetime, plateNo, DO#)
│ ├─ Update CimaDeliveryInfo status → 'Completed'
│ ├─ If status was 'Pending Auto Update (CIMA)' → update OrderDocument → 'Auto Approved'
│ └─ Log action in OrderJobTrackingLog
└─ Mark task 'Success'
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 |
|---|---|---|---|
Download CIMA TRN Report |
createMsRpaDownloadCimaLorryInOut (cron) |
RPA | Every 2 hours |
Download CIMA DST Report |
createMsRpaDownloadCimaLorryInOut (cron) |
RPA | Every 2 hours |
Process CIMA Lorry In_Out Report |
afterCreate hook on file upload |
processCimaLorryInoutReports | Every 10 minutes (1 task per run) |
Auto Update CIMA Supplier Data By Supplier Data |
processCimaLorryInoutReports (after file parsed) |
autoUpdateCIMASupplierDataBySupplierData | Every 10 minutes (1 task per run) |
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 | Cron → RPA → 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 (file triggered every 2 hours) | Every 3 minutes |