autoUpdateCIMASupplierDataBySupplierData
Overview
A cron job that processes queued tasks to sync CIMA supplier delivery data into the Order table. It matches CIMA records against order documents and updates order fields with the supplier-provided data.
|
|
| Function |
autoUpdateCIMASupplierDataBySupplierData |
| Task Code |
Auto Update CIMA Supplier Data By Supplier Data |
| Schedule |
Every 10 seconds (temp override) |
| Source File |
src/_cron/cron.service.ts |
Changelog
| Date |
Author |
Description |
| 2026-02-25 |
sf |
See v2 — fixed transaction scope, added null guards, added plateNo matching, restored schedule, removed sendTo override |
v2 — Current Logic (After Changes)
Schedule
EVERY_10_MINUTES
Processing Flow
- Pick oldest Pending task and mark Running
- Fetch all
CimaDeliveryInfo where status = Pending AND deliveryDatetime >= now - 1 month, ordered by id ASC
- For each record — processed in its own individual transaction:
- Find
OrderDocument where referenceKey = DO# AND autoUpdateFor = CIMA AND plateNo = supplierData.plateNo
- If not found → log warning and skip
- If found but
documentStatus not in allowed list → log debug and skip
- If
order not found by orderId → log warning and skip (Steps 4–6 are not executed)
- Update Order fields (without overriding
sendTo)
- Mark
CimaDeliveryInfo.status → Completed
- If
documentStatus = Pending Auto Update (CIMA) → update OrderDocument.documentStatus → Auto Approved
- Log to
OrderJobTrackingLog
- Finally: update task status →
Success or Fail
Allowed documentStatus values
Approved
Auto Approved
Pending Auto Update (CIMA)
Order Fields Updated
| Field |
Source |
| actualLoadedQuantity |
supplierData.netWeight |
| grossWeight |
supplierData.grossWeight |
| netWeight |
supplierData.netWeight |
| tareWeight |
supplierData.tareWeight |
| sealNumber |
supplierData.sealNo |
| supplierDoDatetime |
supplierData.deliveryDatetime |
| supplierDoPlateNo |
supplierData.plateNo |
| deliveryOrderNumber |
supplierData.deliveryOrderNumber |
| updatedBy |
System |
sendTo is not updated — preserved from original order value.
Changes from v1
| # |
Issue |
Fix |
| 1 |
Single transaction for all records — one failure rolled back everything |
Each record now has its own transaction |
| 2 |
Steps 4–6 ran even if order was null |
Added early return with warning if order not found |
| 3 |
No warning when OrderDocument not found |
Added logger.warn with DO# and plateNo |
| 4 |
No plateNo matching on OrderDocument lookup |
Added plateNo: supplierData.plateNo to query |
| 5 |
Schedule stuck at EVERY_10_SECONDS (temp override) |
Restored to EVERY_10_MINUTES |
| 6 |
order.sendTo = order.clientName unconditionally overwrote sendTo |
Removed — sendTo is never overridden |
| 7 |
deliveryDatetime had no filter — old stale records were processed |
Added deliveryDatetime >= now - 1 month filter |
v1 — Original Logic (Before Changes)
Schedule
EVERY_10_SECONDS (temp override of original EVERY_10_MINUTES)
Processing Flow
- Pick oldest Pending task and mark Running
- Fetch ALL
CimaDeliveryInfo where status = Pending — no date filter, no limit
- All records processed in a single transaction (one failure rolls back everything):
- Find
OrderDocument where referenceKey = DO# AND autoUpdateFor = CIMA — no plateNo matching
- If not found → silently skip (no log)
- If found but
documentStatus not in allowed list → log debug and skip
- Update Order fields including
order.sendTo = order.clientName (unconditional override)
- If order is null, Steps 4–6 still execute (CimaDeliveryInfo marked Completed even if order not updated)
- Mark
CimaDeliveryInfo.status → Completed
- If
documentStatus = Pending Auto Update (CIMA) → update OrderDocument.documentStatus → Auto Approved
- Log to
OrderJobTrackingLog
- Finally: update task status →
Success or Fail
Order Fields Updated (v1)
| Field |
Source |
| actualLoadedQuantity |
supplierData.netWeight |
| grossWeight |
supplierData.grossWeight |
| netWeight |
supplierData.netWeight |
| tareWeight |
supplierData.tareWeight |
| sealNumber |
supplierData.sealNo |
| supplierDoDatetime |
supplierData.deliveryDatetime |
| supplierDoPlateNo |
supplierData.plateNo |
| deliveryOrderNumber |
supplierData.deliveryOrderNumber |
| sendTo |
order.clientName (always overwritten) |
| updatedBy |
System |