Merge pull request #826 from Tria-plc/freight_feature/usermanagement

changes
This commit is contained in:
marshal
2026-07-20 06:06:06 +03:00
committed by GitHub
10 changed files with 456 additions and 271 deletions

View File

@@ -1926,7 +1926,8 @@ export class WarehouseInventoryService {
// 1. Schedule must exist, be ARRIVED, and be an IMPORT route (derived from station countries).
const [schedule] = await this.dataSource.query(
`SELECT ts.id, ts.status, oy.country AS "originCountry", dy.country AS "destinationCountry"
`SELECT ts.id, ts.status, ts.destination_station_id AS "destinationStationId",
oy.country AS "originCountry", dy.country AS "destinationCountry"
FROM freight.train_schedules ts
LEFT JOIN freight.yards oy ON oy.id = ts.origin_station_id
LEFT JOIN freight.yards dy ON dy.id = ts.destination_station_id
@@ -1957,14 +1958,20 @@ export class WarehouseInventoryService {
tradeDirection: string | null;
cargoTypeCode: string | null;
}[] = await this.dataSource.query(
// Only bookings whose destination IS this train's final yard unload into
// this (final-destination) warehouse. A mid-corridor import that alighted
// at an intermediate yard was already unloaded there by the checkpoint
// auto-unload; without this filter it would be mis-located into the final
// yard's inventory too.
`SELECT b.id, b.status, b.cargo_total_weight_vgm AS weight,
b.freight_type AS "freightType", b.trade_direction AS "tradeDirection",
cgt.code AS "cargoTypeCode"
FROM freight.train_schedule_bookings tsb
JOIN freight.bookings b ON b.id = tsb.booking_id AND b.deleted_at IS NULL
LEFT JOIN freight.cargo_types cgt ON cgt.id = b.cargo_type_id
WHERE tsb.train_schedule_id = $1 AND tsb.deleted_at IS NULL`,
[scheduleId],
WHERE tsb.train_schedule_id = $1 AND tsb.deleted_at IS NULL
AND b.destination_yard_id = $2`,
[scheduleId, schedule.destinationStationId],
);
const requestedLocation = warehouseId ? await this.pickDefaultLocation(warehouseId) : null;