Enhance bulk booking handling and wagon capacity calculations across services

This commit is contained in:
Marshal
2026-07-09 15:30:00 +00:00
parent 3259bd7667
commit 1690f9e498
11 changed files with 278 additions and 32 deletions

View File

@@ -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;
}