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 = () => { - - Tires/Rims车胎/车圈 - {getChecklistStatus('tires') || getChecklistStatus('Tires')} - Door(s)车门 - {getChecklistStatus('door') || getChecklistStatus('Door')} - Seat/Seat-belt座位/安全带 - {getChecklistStatus('seat') || getChecklistStatus('Seat')} - - - Mirrors/Windows镜子/窗户 - {getChecklistStatus('mirror') || getChecklistStatus('Mirror') || getChecklistStatus('window') || getChecklistStatus('Window')} - Light(s)车灯 - {getChecklistStatus('light') || getChecklistStatus('Light')} - Lift (wheelchair)轮椅起降器 - {getChecklistStatus('lift') || getChecklistStatus('Lift')} - - - Emergency Folder紧急情况信息夹 - {getChecklistStatus('emergency') || getChecklistStatus('Emergency')} - Tie Down固定绳索 - {getChecklistStatus('tie') || getChecklistStatus('Tie')} - Heater/AC暖气/冷气 - {getChecklistStatus('heater') || getChecklistStatus('Heater') || getChecklistStatus('ac') || getChecklistStatus('AC')} - - - Fire Extinguisher灭火器 - {getChecklistStatus('fire') || getChecklistStatus('Fire') || getChecklistStatus('extinguisher')} - Body车身 - {getChecklistStatus('body') || getChecklistStatus('Body')} - Coolant冷冻液 - {getChecklistStatus('coolant') || getChecklistStatus('Coolant')} - + {checklistRows.length === 0 && ( + + No checklist data + + )} + {checklistRows.map((row, rowIndex) => ( + + {[0, 1, 2].map((cellIndex) => { + const item = row[cellIndex]; + if (!item) { + return ( + + + + + ); + } + return ( + + {item.label} + {item.inspected ? '✓' : ''} + + ); + })} + + ))}