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')