From e8f46675dcf568f976c4769044fee8043249e124 Mon Sep 17 00:00:00 2001 From: Nathnael Date: Mon, 24 Aug 2026 07:12:40 +0000 Subject: [PATCH] feat(reports): add a total wagons column to charged vs actual volume Loaded and empty wagons were both shown but never summed, so the train's actual consist had to be added up by hand on every row. MAX() on the empty count for the same reason the distance uses it: the value is constant within a group that includes ts.id and the leg. --- .../reports/definitions/charged-vs-actual-volume.report.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/edr-freight-api/src/modules/reports/definitions/charged-vs-actual-volume.report.ts b/apps/edr-freight-api/src/modules/reports/definitions/charged-vs-actual-volume.report.ts index 9784589e0..5fe6ba81b 100644 --- a/apps/edr-freight-api/src/modules/reports/definitions/charged-vs-actual-volume.report.ts +++ b/apps/edr-freight-api/src/modules/reports/definitions/charged-vs-actual-volume.report.ts @@ -53,6 +53,7 @@ const LEG_TO = 'COALESCE(leg.to_yard_id, ts.destination_station_id)'; */ const LEG_KM = `MAX(${distanceKmBetween(LEG_FROM, LEG_TO)})`; const EMPTY_WAGONS = `MAX(${SCHEDULE_EMPTY_WAGONS})`; +const TOTAL_WAGONS = `(COUNT(DISTINCT tsw.id) + ${EMPTY_WAGONS})::int`; /** * Ton/Km and Vehicle-Km are NULL — not zero — when the yard pair has no @@ -105,6 +106,7 @@ export const chargedVsActualVolumeReport: ReportDefinition = { { key: 'teu', label: 'TEU', type: 'number' }, { key: 'wagons', label: 'Loaded wagons', type: 'number' }, { key: 'emptyWagons', label: 'Empty wagons', type: 'number' }, + { key: 'totalWagons', label: 'Total wagons', type: 'number', sortable: true }, { key: 'distanceKm', label: 'Distance (km)', type: 'number' }, { key: 'tonKm', label: 'Ton/Km', type: 'number', sortable: true }, { key: 'vehicleKm', label: 'Vehicle-Km', type: 'number' }, @@ -121,6 +123,7 @@ export const chargedVsActualVolumeReport: ReportDefinition = { .addSelect(TEU_EXPR, 'teu') .addSelect(LOADED_WAGONS_EXPR, 'wagons') .addSelect(`${EMPTY_WAGONS}::int`, 'emptyWagons') + .addSelect(TOTAL_WAGONS, 'totalWagons') .addSelect(`${LEG_KM}::float8`, 'distanceKm') .addSelect(TON_KM, 'tonKm') .addSelect(VEHICLE_KM, 'vehicleKm')