Merge pull request #494 from Tria-plc/PertruckExit

Export Loading to train
This commit is contained in:
Hagernesh Tadesse
2026-07-06 22:21:03 +03:00
committed by GitHub
10 changed files with 1205 additions and 6 deletions

View File

@@ -63,6 +63,58 @@ import type {
WarehouseZone,
} from '@/types/warehouse';
export type ContainerItemStage = 'PENDING' | 'RECEIVED' | 'GRN' | 'LOADED' | 'LEFT' | 'DELIVERED';
export interface ContainerItem {
containerNumber: string;
goods: string | null;
stage: ContainerItemStage;
grnNumber: string | null;
truckAssignmentId: string | null;
truckPlate: string | null;
truckArrived: boolean;
truckLeft: boolean;
bookingReference: string | null;
contractId: string | null;
hasLastMile: boolean;
}
/** A pre-dispatch EXPORT train that has inventory waiting to be loaded. */
export interface LoadableTrain {
scheduleId: string;
trainNumber: string | null;
origin: string | null;
destination: string | null;
status: string;
departureTime: string | null;
readyCount: number;
loadedCount: number;
}
/** A container/cargo inventory item assigned to a train, with its allocated wagon. */
export interface TrainLoadableItem {
id: string;
bookingId: string | null;
bookingReference: string | null;
customerName: string | null;
containerNumber: string | null;
cargoType: string | null;
weight: number | null;
grnNumber: string | null;
inspectionStatus: string | null;
status: string;
wagonId: string | null;
wagonNumber: string | null;
sequenceNo: number | null;
loadable: boolean;
}
export interface TrainLoadResult {
loadedCount: number;
skippedCount: number;
results: { inventoryId: string; status: string; reason?: string }[];
}
const cleanParams = (params: object) =>
Object.fromEntries(
Object.entries(params).filter(([, value]) => value !== undefined && value !== '' && value !== null),
@@ -75,6 +127,14 @@ export const warehouseService = {
return data?.data ?? data ?? [];
},
/** Per-container/bulk items of a booking with lifecycle stage + refs. */
getContainerItems: async (bookingId: string): Promise<ContainerItem[]> => {
const { data } = await apiClient.get(
`/warehouse-inventory/bookings/${bookingId}/container-items`,
);
return data?.data ?? data ?? [];
},
/** Booking container numbers not yet loaded onto any truck. */
getLoadableContainers: async (bookingId: string): Promise<string[]> => {
const { data } = await apiClient.get(
@@ -96,6 +156,33 @@ export const warehouseService = {
return data?.data ?? data ?? [];
},
// ── Load to Train ─────────────────────────────────────────────────────────
/** Pre-dispatch EXPORT trains with inventory waiting to be loaded. */
getLoadableTrains: async (): Promise<LoadableTrain[]> => {
const { data } = await apiClient.get('/warehouse-inventory/loadable-trains');
return data?.data ?? data ?? [];
},
/** Container/cargo items assigned to a train, with allocated wagon + stage. */
getTrainLoadableItems: async (scheduleId: string): Promise<TrainLoadableItem[]> => {
const { data } = await apiClient.get(
`/warehouse-inventory/train/${scheduleId}/loadable-items`,
);
return data?.data ?? data ?? [];
},
/** Load selected inventory items onto their allocated wagons for a train. */
loadItemsOntoTrain: async (
scheduleId: string,
inventoryIds: string[],
): Promise<TrainLoadResult> => {
const { data } = await apiClient.post(
`/warehouse-inventory/train/${scheduleId}/load`,
{ inventoryIds },
);
return data?.data ?? data ?? { loadedCount: 0, skippedCount: 0, results: [] };
},
// ── Warehouses ──────────────────────────────────────────────────────────
list: (filter?: WarehouseFilter) =>
apiClient.get<Warehouse[]>(URL_CONSTANTS.WAREHOUSES.BASE, {