diff --git a/client/src/components/trans-routes/RouteReportWithSignature.js b/client/src/components/trans-routes/RouteReportWithSignature.js index 32e6353..ca5bc7e 100644 --- a/client/src/components/trans-routes/RouteReportWithSignature.js +++ b/client/src/components/trans-routes/RouteReportWithSignature.js @@ -81,27 +81,37 @@ const RouteReportWithSignature = () => { .toLowerCase() .replace(/[^a-z0-9]/g, ''); - // Include current route checklist, and also paired same-day route checklist. - // This keeps inspection checks visible whether results were saved on inbound or outbound. - const pairedRoute = getRelatedInboundOutboundRoutesForThisView(currentRoute?.type) - ?.find((route) => + const normalizedCurrentRouteName = currentRoute?.name?.toLowerCase()?.replaceAll(' ', ''); + const checklistSourceRoutes = [ + currentRoute, + ...(getRelatedInboundOutboundRoutesForThisView(currentRoute?.type) || []).filter((route) => route?.schedule_date === currentRoute?.schedule_date && - route?.name?.toLowerCase()?.replaceAll(' ', '') === currentRoute?.name?.toLowerCase()?.replaceAll(' ', '') - ); - const checklistResult = [ - ...(currentRoute?.checklist_result || []), - ...(pairedRoute?.checklist_result || []) - ]; - const getChecklistStatus = (itemKey) => { - const normalizedItemKey = normalizeChecklistText(itemKey); - const item = checklistResult.find((c) => { - const candidates = [c?.key, c?.label, c?.item] - .map(normalizeChecklistText) - .filter(Boolean); - return candidates.some((candidate) => candidate.includes(normalizedItemKey)); + route?.name?.toLowerCase()?.replaceAll(' ', '') === normalizedCurrentRouteName && + ['inbound', 'outbound'].includes(route?.type) + ) + ].filter(Boolean); + + const checklistItemsMap = new Map(); + checklistSourceRoutes.forEach((route) => { + (route?.checklist_result || []).forEach((item) => { + const displayLabel = item?.item || item?.label || item?.key || ''; + const normalizedKey = normalizeChecklistText(displayLabel); + if (!normalizedKey) return; + const current = checklistItemsMap.get(normalizedKey) || { + label: displayLabel, + inspected: false + }; + checklistItemsMap.set(normalizedKey, { + label: current.label || displayLabel, + inspected: current.inspected || item?.result === true || item?.checked === true + }); }); - return (item?.result === true || item?.checked === true) ? '✓' : ''; - }; + }); + const checklistItems = Array.from(checklistItemsMap.values()); + const checklistRows = []; + for (let i = 0; i < checklistItems.length; i += 3) { + checklistRows.push(checklistItems.slice(i, i + 3)); + } const sortedRouteCustomers = [...(currentRoute?.route_customer_list || [])].sort((a, b) => { const aOrder = Number(a?.customer_pickup_order); @@ -340,38 +350,32 @@ const RouteReportWithSignature = () => {
-