mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 07:38:10 +00:00
Enhance bulk booking handling and wagon capacity calculations across services
This commit is contained in:
@@ -436,7 +436,21 @@ export function expandContainerItems(
|
||||
return items;
|
||||
}
|
||||
|
||||
export function sumWagonsRequired(booking: Booking): number {
|
||||
/**
|
||||
* Wagons a booking actually occupies. Prefer counting the built wagon plan's
|
||||
* slots that carry one of the booking's allocations — for BULK that is its
|
||||
* tonnage spread over real wagons (a 700T booking on 70T wagons rides 10
|
||||
* wagons, and downstream gross-weight math charges 10 tares, not 1). Without
|
||||
* a plan there is no capacity to divide by, so fall back to the pre-plan
|
||||
* estimates: 1 for bulk, the lines' stored counts for containers.
|
||||
*/
|
||||
export function sumWagonsRequired(booking: Booking, wagonPlan?: WagonPlanSlot[]): number {
|
||||
const occupiedSlots = (wagonPlan ?? []).filter((slot) =>
|
||||
slot.allocations.some((allocation) => allocation.bookingId === booking.id),
|
||||
).length;
|
||||
if (occupiedSlots > 0) {
|
||||
return occupiedSlots;
|
||||
}
|
||||
if (booking.freightType === 'BULK') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user