mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
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.
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user