This commit is contained in:
natib21
2026-07-03 16:58:42 +00:00
parent ac55a867c0
commit 284c85e0e7

View File

@@ -118,11 +118,12 @@ const computeLastMileSteps = (
Boolean(releaseRow?.releaseDate),
record.status === "IN_TRANSIT" || record.status === "DELIVERED",
exactKm != null,
exactKm != null, // Generate Invoice — auto-generated when distance is saved
record.status === "DELIVERED",
];
// Current step = earliest incomplete one.
const activeIdx = flags.findIndex((f) => !f);
const labels = ["Ready to Transit", "Assign vehicle", "Truck arrived", "Truck leave", "In transit", "Add distance", "Delivered"];
const labels = ["Ready to Transit", "Assign vehicle", "Truck arrived", "Truck leave", "In transit", "Add distance", "Generate Invoice", "Delivered"];
const details: (string | null)[] = [
null,
record.vehicle?.plateNumber ?? null,
@@ -130,6 +131,7 @@ const computeLastMileSteps = (
fmtStamp(releaseRow?.releaseDate),
null,
exactKm != null ? `${exactKm} KM` : null,
exactKm != null ? "Invoice ready" : null,
fmtStamp(releaseRow?.deliveredAt),
];
return labels.map((label, i) => ({
@@ -1004,9 +1006,9 @@ const LastMilePage = () => {
const releaseRow =
pickupReadyByBooking.get(row.original.bookingId) ?? pickupReadyByBooking.get(bookingRef(row.original));
// Only the current step's action is active; the rest stay disabled.
// Step order: 0 Ready·1 Assign·2 Arrived·3 Leave·4 In-transit·5 Distance·6 Delivered.
// Steps: 0 Ready·1 Assign·2 Arrived·3 Leave·4 In-transit·5 Distance·6 Invoice·7 Delivered.
const activeStep = computeLastMileSteps(row.original, releaseRow).findIndex((s) => s.active);
const canAdvance = activeStep === 0 || activeStep === 4 || activeStep === 6;
const canAdvance = activeStep === 0 || activeStep === 4 || activeStep === 7;
const canAssignStep = activeStep === 1;
const canDistance = activeStep === 5;
// Truck arrival/leaving are independent of the step sequence — each