autoUpdateCIMASupplierData
Overview
A cron job that processes a queued task to sync CIMA supplier delivery data into a specific order document and its associated order. Unlike the autoUpdateCIMASupplierDataBySupplierData sibling, this function is triggered per order document (one task = one document).
|
|
| Function |
autoUpdateCIMASupplierData |
| Task Code |
Auto Update CIMA Supplier Data |
| Schedule |
Every 10 seconds |
| Source File |
src/_cron/cron.service.ts |
Changelog
| Date |
Author |
Description |
| (original) |
— |
Initial implementation |
Current Logic
Schedule
EVERY_10_SECONDS
The task value field (JSON):
{
"orderDocumentId": 123
}
Processing Flow
- Pick oldest Pending task and mark Running
- Parse
orderDocumentId from task payload — if missing or 0, log warning and return
- Within a single transaction:
- Step 1: Find
OrderDocument by orderDocumentId — if not found, log warning and return
- Step 2: Find
CimaDeliveryInfo by deliveryOrderNumber = document.referenceKey AND plateNo = document.plateNo — if not found, log error and return
- Update
OrderDocument.documentStatus → Auto Approved
- If order found: update Order fields including
order.sendTo = order.clientName (unconditional override)
- Step 3: Update
CimaDeliveryInfo.status → Completed; if cimaInfo.saleOrderNo is null, also set saleOrderNo = order.saleOrderNo
- Step 4: Insert record into
OrderJobTrackingLog with action CIMA Supplier Data Auto Update
- Finally: update task status →
Success or Fail
Order Fields Updated
| Field |
Source |
| actualLoadedQuantity |
cimaInfo.netWeight |
| grossWeight |
cimaInfo.grossWeight |
| netWeight |
cimaInfo.netWeight |
| tareWeight |
cimaInfo.tareWeight |
| sealNumber |
cimaInfo.sealNo |
| supplierDoDatetime |
cimaInfo.deliveryDatetime |
| supplierDoPlateNo |
cimaInfo.plateNo |
| deliveryOrderNumber |
cimaInfo.deliveryOrderNumber |
| sendTo |
order.clientName (always overwritten) |
| updatedBy |
System |
CimaDeliveryInfo Fields Updated
| Field |
Condition |
Value |
| status |
always |
Completed |
| saleOrderNo |
only if cimaInfo.saleOrderNo is null |
order.saleOrderNo |
Key Differences vs Sibling Function
|
autoUpdateCIMASupplierData |
autoUpdateCIMASupplierDataBySupplierData |
| Trigger |
Per orderDocumentId (one task = one doc) |
Batch — all Pending CimaDeliveryInfo |
| OrderDocument lookup |
By id (direct) |
By referenceKey + plateNo + autoUpdateFor |
| OrderDocument status |
Always set to Auto Approved |
Only set if Pending Auto Update (CIMA) |
| saleOrderNo backfill |
Yes — if cimaInfo.saleOrderNo is null |
No |