mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 03:10:54 +00:00
Every facility raises a GRN — the goods changed hands, whether or not anyone stores them. What differs is what happens next: Indode has a warehouse, so cargo left there goes through the existing warehouse flow and accrues storage and demurrage; Sebeta, Modjo, Adama and Dire Dawa only move cargo between train and truck, so the handling event and its GRN are the whole record. facility_handling_events carries that record because warehouse_inventory cannot: its warehouse/yard/zone are NOT NULL, so a facility with equipment but no warehouse could never have a row there. inventory_id links the storage record when the facility does keep the cargo, which is what ties an Indode handover to its demurrage. generateGrnNumber moves to common/grn.util.ts so a GRN raised at a facility is indistinguishable from one raised in a warehouse — the two live in different tables, and a second generator would let the formats drift. Recording is best-effort: the cargo moved regardless, so paperwork must never fail the journey. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
14 lines
652 B
TypeScript
14 lines
652 B
TypeScript
/**
|
|
* Goods Received Note number: `GRN-<DIRECTION>-<YYYYMMDD>-<REF8>`.
|
|
*
|
|
* Shared so a GRN raised at a load/unload facility is indistinguishable from one
|
|
* raised in a warehouse — the two live in different tables
|
|
* (facility_handling_events vs warehouse_inventory), and a second generator would
|
|
* eventually let their formats drift apart.
|
|
*/
|
|
export function generateGrnNumber(direction: string, referenceId: string, date: Date): string {
|
|
const stamp = date.toISOString().slice(0, 10).replace(/-/g, '');
|
|
const suffix = referenceId.replace(/-/g, '').slice(0, 8).toUpperCase();
|
|
return `GRN-${direction.toUpperCase()}-${stamp}-${suffix}`;
|
|
}
|