This commit is contained in:
@@ -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 = () => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Tires/Rims<span className="bilingual-label">车胎/车圈</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('tires') || getChecklistStatus('Tires')}</td>
|
||||
<td>Door(s)<span className="bilingual-label">车门</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('door') || getChecklistStatus('Door')}</td>
|
||||
<td>Seat/Seat-belt<span className="bilingual-label">座位/安全带</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('seat') || getChecklistStatus('Seat')}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Mirrors/Windows<span className="bilingual-label">镜子/窗户</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('mirror') || getChecklistStatus('Mirror') || getChecklistStatus('window') || getChecklistStatus('Window')}</td>
|
||||
<td>Light(s)<span className="bilingual-label">车灯</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('light') || getChecklistStatus('Light')}</td>
|
||||
<td>Lift (wheelchair)<span className="bilingual-label">轮椅起降器</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('lift') || getChecklistStatus('Lift')}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Emergency Folder<span className="bilingual-label">紧急情况信息夹</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('emergency') || getChecklistStatus('Emergency')}</td>
|
||||
<td>Tie Down<span className="bilingual-label">固定绳索</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('tie') || getChecklistStatus('Tie')}</td>
|
||||
<td>Heater/AC<span className="bilingual-label">暖气/冷气</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('heater') || getChecklistStatus('Heater') || getChecklistStatus('ac') || getChecklistStatus('AC')}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Fire Extinguisher<span className="bilingual-label">灭火器</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('fire') || getChecklistStatus('Fire') || getChecklistStatus('extinguisher')}</td>
|
||||
<td>Body<span className="bilingual-label">车身</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('body') || getChecklistStatus('Body')}</td>
|
||||
<td>Coolant<span className="bilingual-label">冷冻液</span></td>
|
||||
<td style={{ textAlign: 'center' }}>{getChecklistStatus('coolant') || getChecklistStatus('Coolant')}</td>
|
||||
</tr>
|
||||
{checklistRows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} style={{ textAlign: 'center' }}>No checklist data</td>
|
||||
</tr>
|
||||
)}
|
||||
{checklistRows.map((row, rowIndex) => (
|
||||
<tr key={`checklist-row-${rowIndex}`}>
|
||||
{[0, 1, 2].map((cellIndex) => {
|
||||
const item = row[cellIndex];
|
||||
if (!item) {
|
||||
return (
|
||||
<React.Fragment key={`checklist-empty-${rowIndex}-${cellIndex}`}>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<React.Fragment key={`checklist-item-${rowIndex}-${cellIndex}`}>
|
||||
<td>{item.label}</td>
|
||||
<td style={{ textAlign: 'center' }}>{item.inspected ? '✓' : ''}</td>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user