Skip to main content

Receiving workflow

The dock workflow in four steps. Each step is a REST call; the events are written to the transactional outbox in the same transaction as the change and published by the relay.

Source: internal/adapters/inbound/http/server.go (routes), internal/application/usecases/{asn,receipt,consumers_appointment}.go. Omits: cancel paths and the read endpoints. Booking happens in dock-scheduling (ADR 0019); POST /appointments and its check-in and cancellation routes answer 410 appointment-moved.

StepUse caseState changeEvent
AnnounceRegisterAsnASN RegisteredASNRegistered
Appointnone here: dock-scheduling books; ApplyDockAppointmentBooked stores the copy, ApplyDockAppointmentRescheduled / ApplyDockAppointmentDoorReassigned keep its door and window current (ADR 0020)appointment copy Bookednone (this context raises nothing)
OpenOpenReceiptreceipt Open, ASN Registered -> ReceivingReceiptOpened (the ASN transition raises none)
ReceiveReceiveLineline counters growReceiptLineReceived per call
CloseCloseReceiptreceipt Closed, ASN Closed (the appointment is untouched)ReceiptClosed

Dock-to-stock (ADR 0021)​

Dock-to-stock is the time from the carrier's physical arrival at the gate (yard-management's VisitCheckedIn.arrived_at) to the stow of the last Good carton (inventory-storage's ContainerStowed.at, joined to the receipt's cartons by SSCC = LPN). It is measured per receipt: once a receipt opened from an appointment is Closed, the gate arrival of that appointment is known and every Good carton (accepted, all contents Good) has a stow, this context raises ReceiptStowCompleted exactly once, in whichever order those facts and the close arrive. dock_to_stock_seconds = stowed_at - arrived_at, never negative. Receipts without an appointment (walk-in) and receipts without cartons (line-only) have no dock-to-stock: they are out of scope and not reported. The report side is GET /reports/receiving-performance (dock_to_stock, with the share at or under the 3.1 h target).

Rules worth knowing​

  • Appointment is optional. A receipt may be opened without appointmentId (a walk-in delivery, no door). With one, the appointment must exist in the local copy (422 unknown-appointment), cover the ASN (422 asn-not-on-appointment) and not be cancelled (409 appointment-cancelled); the receipt takes its door code from it. A check-in is not required: the arrival is a yard-management fact.
  • The door follows the appointment until the receipt opens. The copy follows dock-scheduling's reschedules and door reassignments, so a receipt opened afterwards takes the new door. A receipt already open keeps its door: where the truck is unloaded is a physical fact (ADR 0020).
  • One open receipt per ASN. A second POST /receipts for the same ASN is 409 receipt-already-open. After a receipt closes the ASN is Closed, which is not receivable.
  • Receiving lines is not naturally idempotent, so the Idempotency-Key is required: a retry with the same key never counts the units twice.
  • Cancel is only possible while nothing started: an ASN from Registered (from Receiving it is 409 asn-in-progress). Appointments are cancelled in dock-scheduling.
  • Handover. Every ReceiptLineReceived is the handover event. inventory-storage books condition=Good quantities as staged stock; Damaged units are recorded on the receipt and in its discrepancies but are not booked (ADR 0003).

Concurrency and replays​

  • Every mutable resource has a version that is also its strong ETag. Action POSTs may send If-Match; a stale value is 412 version-mismatch, and a write that loses a race in the database is 409 concurrent-modification.
  • Resource-creating POSTs (/asns, /appointments, /receipts, /receipts/{id}/lines) require Idempotency-Key; the action POSTs (cancel, check-in, close) accept it but do not require it, since the state machine already refuses a repeat with 409.

Receiving cartons by scan and carton discrepancies​

A carton ASN announces SSCC-labelled cartons. POST /receipts/{receiptId}/scans receives one scan: an SSCC accepts the carton's whole manifest, a case GTIN books qty cases (the service multiplies by the active CASE units per pack), an each GTIN books qty eaches. Quantities and events are always eaches; ReceiptLineReceived is the only quantity authority and ReceiptCartonReceived is identity only. A refused scan books nothing, answers 200 with accepted=false and raises CartonDiscrepancyRaised; ReceiptClosed keeps its three v1 kinds. See ADR 0012, 0013 and 0014.

KindRaised whenCarton accepted?
UnexpectedCartona valid SSCC that is not on the manifest is scannedno
MissingCartonat close, a manifest carton was never acceptedn/a
DuplicateSsccthe SSCC was scanned twice, or already receivedno
UnknownGtina scanned GTIN is not in the PackagingViewno
CaseQtyMismatchmanifest quantity differs from the CASE units per pack or the label countno
MixedCaseDeclaredAsCasePacka homogeneous carton's label names another SKUno
UnlabelledCartona case with no SSCC arrives against a carton ASN; it gets an internal LPN-<ulid>yes
CartonOverLimitdeclared weight or longest side is above CARTON_MAX_GROSS_WEIGHT_G / CARTON_MAX_LONGEST_SIDE_MMyes
MixedCartonContentMismatchcountedContents of a MIXED carton differ from its manifest per SKU; the counted quantity is receivedyes
LabelNonComplianta raw scan breaks the GS1 rules (bad check digit, AI 01 with AI 02, a missing mandatory AI, ...); expected is the reason code, actual the raw scanno
WrongDestinationthe label's ship-to GLN (AI 410) is not in RECEIVING_SITE_GLNS; actual is that GLNno
MissingContentGtina carton scan against a FLAT ASN (lines, no carton manifest) carried no AI 02 content GTIN, so no line could be resolved (ADR 0025)no

The last three are raised at the scan (ADR 0024 and ADR 0025): nothing is booked, and none has a W13 code (their CBV dispositions are non_conformant, mismatch_instance and non_conformant). A label with no AI 410 is never refused for its destination, and the destination rule is off while RECEIVING_SITE_GLNS is empty.

The label data of an accepted carton (lpn, CODE128, human readable text, SKU, units) is GET /receipts/{receiptId}/cartons/{lpn}/label; the floor client renders and prints it.

Dates on the label and mixed pallets​

An accepted carton keeps what its label said: bestBefore (AI 15), expiry (AI 17), productionDate (AI 11), packagingDate (AI 13), serial (AI 21), purchaseOrder (AI 400), shipToGln (AI 410) and shipForGln (AI 413, stored, never enforced). GET /receipts/{receiptId} reports the earliest bestBefore and expiry of the accepted cartons per line (lines[].earliestBestBefore / earliestExpiry) and per pallet (pallets[] = {parentSscc, cartonCount, earliestBestBefore?, earliestExpiry?}): the date a mixed pallet must be picked by. A day 00 is the last day of its month. The same earliest dates ride on each line of ReceivingAdviceIssued (ADR 0024).

A case with no label: AssignSscc​

POST /receipts/{receiptId}/sscc-assignments with the case gtin receives ONE case under an SSCC the receiver builds from its own GS1 company prefix (extension digit 0, a serial from a never-reused per-prefix Postgres sequence, a valid check digit) and answers 201 with sscc, humanReadable, elementString and symbology for the floor client to print. The carton is ssccSource: receiver and still raises UnlabelledCarton against a carton ASN. It answers 409 sscc-prefix-not-configured until the business supplies RECEIVER_GS1_COMPANY_PREFIX (a licensed asset: no default), and 409 sscc-serial-exhausted when the prefix's serials are used up.

Carton screens in the console​

The inbound_mfe remote (web/) has three screens for carton receiving. Quantities are always eaches; a homogeneous case reads "Case of N eaches".

ScreenRoute under /inbound-receivingData
ASN carton treeasns/:asnNumber/cartonsGET /asns/{asnNumber}/cartons: pallet SSCC → carton SSCC → contents per SKU, status Expected / Accepted / Missing
Carton discrepanciesreceipts/:receiptId/discrepanciesGET /receipts/{receiptId} (cartonDiscrepancies) and POST /receipts/{receiptId}/scans (a scan form); explains the nine kinds of ADR 0012/0014 with what to do (the two label kinds of ADR 0024 and the flat-ASN kind of ADR 0025 are listed by the receipt read but not yet explained on this screen: web/ is a separate change)
Carton labelreceipts/:receiptId/cartons/:lpn/labelGET /receipts/{receiptId}/cartons/{lpn}/label; Code 128 drawn as inline SVG (GS1-128 for an SSCC), printed with window.print() and a print stylesheet

The receipt keeps every carton discrepancy it raises (ADR 0015): GET /receipts/{receiptId} lists them as cartonDiscrepancies[] (kind, sscc?, expected?, actual?, at), in raise order, scan findings and the MissingCarton findings raised at close alike; the array is [] when there are none. The discrepancies screen shows that list, so it is the same in every browser, and re-reads the receipt after each scan. A receipt closed before ADR 0015 has none stored. Errors are keyed by problem code (carton-not-found, scan-kind-mismatch, ...) with what happened and what to do.