mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
Invoice genaration and seal
This commit is contained in:
@@ -21,6 +21,9 @@ export interface ImportTrainRow {
|
||||
totalBookings: number;
|
||||
totalContainers: number;
|
||||
totalCargoes: number;
|
||||
unloadedBookings: number;
|
||||
pendingUnloadBookings: number;
|
||||
fullyUnloaded: boolean;
|
||||
status: string;
|
||||
}
|
||||
|
||||
@@ -205,7 +208,24 @@ export class SchedulingReadFacade {
|
||||
WHERE tsbc.train_schedule_id = ts.id AND c.deleted_at IS NULL) AS "totalContainers",
|
||||
(SELECT count(*) FROM freight.cargoes cg
|
||||
JOIN freight.train_schedule_bookings tsbg ON tsbg.booking_id = cg.booking_id AND tsbg.deleted_at IS NULL
|
||||
WHERE tsbg.train_schedule_id = ts.id AND cg.deleted_at IS NULL) AS "totalCargoes"
|
||||
WHERE tsbg.train_schedule_id = ts.id AND cg.deleted_at IS NULL) AS "totalCargoes",
|
||||
(SELECT count(*) FROM freight.train_schedule_bookings tsbp
|
||||
JOIN freight.bookings bp ON bp.id = tsbp.booking_id AND bp.deleted_at IS NULL
|
||||
WHERE tsbp.train_schedule_id = ts.id
|
||||
AND tsbp.deleted_at IS NULL
|
||||
AND bp.status NOT IN ('DRAFT', 'REJECTED', 'CANCELLED', 'COMPLETED')
|
||||
AND (
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM freight.warehouse_inventory invp
|
||||
WHERE invp.booking_id = bp.id AND invp.deleted_at IS NULL
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM freight.warehouse_inventory invr
|
||||
WHERE invr.booking_id = bp.id
|
||||
AND invr.deleted_at IS NULL
|
||||
AND invr.status = 'RECEIVED'
|
||||
)
|
||||
)) AS "pendingUnloadBookings"
|
||||
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
|
||||
@@ -219,13 +239,22 @@ export class SchedulingReadFacade {
|
||||
(r) =>
|
||||
deriveTradeDirection({ country: r.originCountry }, { country: r.destinationCountry }) === 'IMPORT',
|
||||
)
|
||||
.map(({ originCountry: _oc, destinationCountry: _dc, ...rest }) => ({
|
||||
...rest,
|
||||
totalBookings: Number(rest.totalBookings) || 0,
|
||||
totalContainers: Number(rest.totalContainers) || 0,
|
||||
totalCargoes: Number(rest.totalCargoes) || 0,
|
||||
route: rest.origin || rest.destination ? `${rest.origin ?? '?'} → ${rest.destination ?? '?'}` : null,
|
||||
}));
|
||||
.map(({ originCountry: _oc, destinationCountry: _dc, ...rest }) => {
|
||||
const totalBookings = Number(rest.totalBookings) || 0;
|
||||
const pendingUnloadBookings = Number(rest.pendingUnloadBookings) || 0;
|
||||
const unloadedBookings = Math.max(totalBookings - pendingUnloadBookings, 0);
|
||||
|
||||
return {
|
||||
...rest,
|
||||
totalBookings,
|
||||
totalContainers: Number(rest.totalContainers) || 0,
|
||||
totalCargoes: Number(rest.totalCargoes) || 0,
|
||||
unloadedBookings,
|
||||
pendingUnloadBookings,
|
||||
fullyUnloaded: totalBookings > 0 && pendingUnloadBookings === 0,
|
||||
route: rest.origin || rest.destination ? `${rest.origin ?? '?'} → ${rest.destination ?? '?'}` : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Assigned bookings/items for an arrived import train (one row per booking). Read-only. */
|
||||
|
||||
Reference in New Issue
Block a user