This commit is contained in:
natib21
2026-07-03 21:57:53 +00:00
parent 9422e5588e
commit cad4b84b8c

View File

@@ -324,7 +324,10 @@ const tripSlipRows = (
: vehicle.vehicleId,
],
["Driver", vehicle.vehicle?.assignedDriverName || "—"],
["Container(s)", vehicle.containerNumber || "—"],
[
"Container(s)",
vehicle.containerNumber || bookingContainerNumbers(record).join(", ") || "—",
],
["Distance (KM)", vehicle.distanceKm != null ? String(vehicle.distanceKm) : "—"],
]
: [
@@ -469,7 +472,7 @@ const buildTripSlipHtml = (record: LastMileRecord, vehicle?: TripSlipVehicle | n
.ring-inner span { font-size: 9px; font-weight: 700; letter-spacing: 1px; }
.ring-inner strong { font-size: 13px; font-weight: 800; }
</style></head>
<body onload="window.print()">
<body>
<div class="head"><h1>EDR Freight</h1><p>Last Mile Trip Slip</p></div>
<div class="meta"><span>${escapeHtml(bookingRef(record))}</span><span>${escapeHtml(requestedDate(record))}</span></div>
<table>${rows}</table>
@@ -946,16 +949,16 @@ const LastMilePage = () => {
};
const handlePrintTripSlip = (record: LastMileRecord) => {
// Always open the picker so the operator chooses which truck to print.
setTripSlipRecord(record);
const assigns = record.vehicleAssignments ?? [];
if (assigns.length > 1) {
// Multiple trucks → let the operator pick which one to print.
setTripSlipVehicleId(null);
setTripSlipSelectOpen(true);
} else {
setTripSlipVehicleId(assigns[0]?.vehicleId ?? null);
setTripSlipOpen(true);
}
setTripSlipVehicleId(null);
setTripSlipSelectOpen(true);
};
const printBookingSlip = () => {
setTripSlipVehicleId(null);
setTripSlipSelectOpen(false);
setTripSlipOpen(true);
};
const chooseTripSlipVehicle = (vehicleId: string) => {
@@ -1016,6 +1019,15 @@ const LastMilePage = () => {
}
win.document.write(buildTripSlipHtml(tripSlipRecord, tripSlipVehicle));
win.document.close();
win.focus();
// Explicit print after the doc paints (onload can miss with document.write).
setTimeout(() => {
try {
win.print();
} catch {
/* window may have been closed */
}
}, 250);
};
const columns = useMemo((): ColumnDef<LastMileRecord>[] => {
@@ -1749,7 +1761,8 @@ const LastMilePage = () => {
>
<Stack gap="sm">
<Text size="sm" c="dimmed">
{tripSlipRecord ? bookingRef(tripSlipRecord) : ""} has multiple trucks choose one.
{tripSlipRecord ? bookingRef(tripSlipRecord) : ""} choose a truck to print its slip
(vehicle, driver, container).
</Text>
{(tripSlipRecord?.vehicleAssignments ?? []).map((a) => {
const v = a.vehicle;
@@ -1772,6 +1785,12 @@ const LastMilePage = () => {
</Button>
);
})}
{(tripSlipRecord?.vehicleAssignments?.length ?? 0) === 0 && (
<Text size="sm" c="dimmed">No vehicles assigned yet.</Text>
)}
<Button variant="subtle" onClick={printBookingSlip}>
Print booking slip (no vehicle)
</Button>
</Stack>
</Modal>