Replace wagon/locomotive readiness with yard tracking, assign unassigned bookings from origin-yard fleet, standardize rates on USD with CBE ETB conversion, and update fleet/scheduling UI

This commit is contained in:
marshal
2026-06-14 01:32:39 +03:00
parent b73bf2154e
commit 87b0ce6339
45 changed files with 1249 additions and 520 deletions

View File

@@ -2,31 +2,30 @@ import { Freight } from "@edr/types";
import type { Wagon } from "@/services/wagon.service";
export function wagonMatchesScheduleDirection(
wagon: Pick<Wagon, "status" | "readiness">,
scheduleDirection?: string | null,
/** Check if a wagon is available for a schedule based on its current yard.
* A wagon is eligible if:
* 1. It is available (or pinned to this schedule)
* 2. It is physically located at the schedule's origin yard
*/
export function wagonMatchesScheduleOrigin(
wagon: Pick<Wagon, "id" | "status" | "currentYardId">,
originYardId?: string | null,
options?: { allowPinned?: boolean },
): boolean {
if (options?.allowPinned) return true;
if (wagon.status !== Freight.WagonStatus.Available) return false;
if (!scheduleDirection || scheduleDirection === "DOMESTIC") return true;
if (scheduleDirection === "IMPORT") {
return wagon.readiness === Freight.WagonReadiness.ImportReady;
}
if (scheduleDirection === "EXPORT") {
return wagon.readiness === Freight.WagonReadiness.ExportReady;
}
return true;
if (!originYardId) return true;
return wagon.currentYardId === originYardId;
}
export function filterWagonsForSchedule(
wagons: Wagon[],
scheduleDirection?: string | null,
originYardId?: string | null,
pinnedWagonIds?: Set<string>,
): Wagon[] {
return wagons.filter((wagon) => {
const isPinned = pinnedWagonIds?.has(wagon.id) ?? false;
return wagonMatchesScheduleDirection(wagon, scheduleDirection, {
return wagonMatchesScheduleOrigin(wagon, originYardId, {
allowPinned: isPinned,
});
});