Loading…
async function showRoutingHist() { const recId = S.editRecordId; if (!recId) return; const body = document.getElementById('routingHistBody'); body.innerHTML = '
Fetching secure timeline...
'; openMo('moRoutingHist'); try { // Fetch all Live QR Punches for this specific record const { data, error } = await supabaseClient .from('audit_logs') .select('*') .eq('record_id', recId) .eq('action', 'Live QR Punch') .order('timestamp', { ascending: false }); if (error) throw error; if (!data || data.length === 0) { body.innerHTML = '

No QR Scans Yet

This document has not been scanned by any processing department.

'; return; } body.innerHTML = data.map(log => { const d = new Date(log.timestamp).toLocaleString('en-US', { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true }); // Color-code the timeline based on the action const isError = log.details.includes('Flagged Error'); const isOut = log.details.includes('Time OUT'); const color = isError ? 'var(--danger)' : (isOut ? 'var(--success)' : 'var(--info)'); const bg = isError ? '#fff1f2' : (isOut ? '#dcfce7' : '#eff6ff'); const icon = isError ? '⚠️' : (isOut ? '📤' : '📥'); return `
${esc(log.user_name)}
${esc(log.role.replace('_', ' '))}
${d}
${icon} ${esc(log.details)}
`; }).join(''); } catch(e) { body.innerHTML = `

Error loading history

${esc(e.message)}

`; } }