Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

#[[<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Route Scheduling Analytics</title>
<style>
  :root{
    --bg:#0b1120; --panel:#111a2e; --panel2:#16213c; --line:#1f2c47;
    --txt:#e6edf7; --muted:#8ea0bd; --soft:#64759a;
    --indigo:#6366f1; --indigo2:#818cf8; --cyan:#22d3ee; --green:#34d399;
    --amber:#fbbf24; --red:#f87171; --pink:#f472b6;
    --good:#34d399; --warn:#fbbf24; --bad:#f87171;
  }
  *{box-sizing:border-box}
  html,body{margin:0;background:var(--bg);color:var(--txt);
    font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    -webkit-font-smoothing:antialiased}
  a{color:var(--indigo2)}
  .wrap{max-width:1280px;margin:0 auto;padding:24px 28px 80px}

  /* header */
  header.top{display:flex;align-items:flex-end;justify-content:space-between;gap:20px;
    padding:18px 0 22px;border-bottom:1px solid var(--line);margin-bottom:26px;flex-wrap:wrap}
  .brand{display:flex;flex-direction:column;gap:6px}
  .brand .eyebrow{font-size:12px;letter-spacing:.16em;text-transform:uppercase;color:var(--indigo2);font-weight:700}
  .brand h1{margin:0;font-size:26px;font-weight:750;letter-spacing:-.01em}
  .brand .sub{color:var(--muted);font-size:13px}
  .hd-right{display:flex;align-items:center;gap:14px}
  .pill{background:var(--panel2);border:1px solid var(--line);border-radius:999px;padding:8px 14px;font-size:12.5px;color:var(--muted)}
  .pill b{color:var(--txt)}
  button.refresh{background:linear-gradient(135deg,var(--indigo),#4f46e5);border:0;color:#fff;font-weight:650;
    padding:9px 16px;border-radius:10px;cursor:pointer;font-size:13px;box-shadow:0 6px 18px rgba(79,70,229,.35)}
  button.refresh:active{transform:translateY(1px)}

  /* kpi row */
  .kpis{display:grid;grid-template-columns:repeat(5,1fr);gap:14px;margin-bottom:26px}
  .kpi{background:linear-gradient(180deg,var(--panel2),var(--panel));border:1px solid var(--line);
    border-radius:16px;padding:16px 18px;position:relative;overflow:hidden}
  .kpi::after{content:"";position:absolute;inset:0 0 auto 0;height:3px;background:var(--accent,var(--indigo))}
  .kpi .label{font-size:11.5px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);font-weight:650}
  .kpi .val{font-size:30px;font-weight:780;margin-top:8px;letter-spacing:-.02em;line-height:1}
  .kpi .val small{font-size:15px;color:var(--muted);font-weight:600}
  .kpi .foot{font-size:12px;color:var(--muted);margin-top:8px}

  /* layout */
  .grid{display:grid;gap:18px}
  .g2{grid-template-columns:1fr 1fr}
  .g3{grid-template-columns:1.3fr 1fr}
  .card{background:var(--panel);border:1px solid var(--line);border-radius:16px;padding:20px 22px;margin-bottom:18px}
  .card h2{margin:0 0 4px;font-size:16px;font-weight:720;letter-spacing:-.01em}
  .card .desc{color:var(--muted);font-size:12.5px;margin:0 0 16px}

  /* bars */
  .barrow{display:grid;grid-template-columns:78px 1fr 60px;align-items:center;gap:12px;margin:9px 0}
  .barrow .name{font-size:13px;color:var(--txt);font-weight:600}
  .track{background:#0b1424;border-radius:8px;height:22px;position:relative;overflow:hidden;border:1px solid #16223c}
  .fill{height:100%;border-radius:8px 0 0 8px;background:linear-gradient(90deg,var(--indigo),var(--indigo2));
    display:flex;align-items:center;justify-content:flex-end;padding-right:7px;font-size:11px;color:#fff;font-weight:650;min-width:2px}
  .barrow .meta{font-size:12px;color:var(--muted);text-align:right}

  /* table */
  table{width:100%;border-collapse:collapse;font-size:13px}
  th,td{text-align:left;padding:9px 10px;border-bottom:1px solid var(--line)}
  th{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);font-weight:650;cursor:pointer;user-select:none;white-space:nowrap}
  th.num,td.num{text-align:right}
  tbody tr:hover{background:#0e1830}
  .lvl{display:inline-block;font-size:11px;font-weight:700;padding:2px 7px;border-radius:6px;background:#1e2a47;color:var(--indigo2)}
  .adh{font-weight:700}
  .meter{display:inline-block;width:64px;height:7px;border-radius:4px;background:#16223c;vertical-align:middle;margin-left:8px;overflow:hidden}
  .meter > i{display:block;height:100%;border-radius:4px}

  /* donut */
  .donutwrap{display:flex;align-items:center;gap:22px}
  .donut{width:148px;height:148px;border-radius:50%;flex:none;position:relative;
    -webkit-mask:radial-gradient(circle 44px at center,transparent 98%,#000 100%);
    mask:radial-gradient(circle 44px at center,transparent 98%,#000 100%)}
  .donut .center{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;-webkit-mask:none;mask:none}
  .legend{display:flex;flex-direction:column;gap:9px;font-size:13px}
  .legend .it{display:flex;align-items:center;gap:9px}
  .dot{width:11px;height:11px;border-radius:3px;flex:none}

  /* reason list */
  .reason{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 0;border-bottom:1px solid var(--line)}
  .reason .txt{font-size:13px}
  .reason .n{font-weight:750;font-size:14px}
  .tag{font-size:10.5px;font-weight:700;padding:2px 7px;border-radius:5px;margin-left:8px;text-transform:uppercase;letter-spacing:.04em}
  .tag.sys{background:#3b2a13;color:var(--amber)}
  .tag.human{background:#10331f;color:var(--green)}

  /* stat tiles */
  .tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
  .tile{background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:14px}
  .tile .t{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);font-weight:600}
  .tile .v{font-size:22px;font-weight:760;margin-top:6px}
  .tile .v small{font-size:13px;color:var(--muted);font-weight:600}

  /* dq chips */
  .dq{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
  .chip{display:flex;align-items:center;gap:12px;background:var(--panel2);border:1px solid var(--line);border-radius:12px;padding:12px 14px}
  .chip .sev{width:10px;height:10px;border-radius:50%;flex:none}
  .chip .body{flex:1}
  .chip .ttl{font-size:13px;font-weight:600}
  .chip .det{font-size:12px;color:var(--muted);margin-top:2px}
  .chip .pct{font-size:18px;font-weight:760}

  .callout{background:linear-gradient(135deg,#15213c,#101a31);border:1px solid #25345a;border-radius:16px;padding:20px 22px}
  .callout h2{margin-top:0}
  .callout ul{margin:6px 0 0;padding-left:20px;line-height:1.75;font-size:13.5px;color:#cdd8ec}
  .callout li b{color:#fff}

  .sectionlabel{font-size:12px;letter-spacing:.14em;text-transform:uppercase;color:var(--soft);font-weight:700;margin:30px 2px 12px}
  .loading{padding:80px;text-align:center;color:var(--muted)}
  .spinner{width:34px;height:34px;border:3px solid #22314f;border-top-color:var(--indigo2);border-radius:50%;
    animation:spin 1s linear infinite;margin:0 auto 14px}
  @keyframes spin{to{transform:rotate(360deg)}}
  @media (max-width:980px){.kpis{grid-template-columns:repeat(2,1fr)}.g2,.g3{grid-template-columns:1fr}.dq{grid-template-columns:1fr}}
</style>
</head>
<body>
<div class="wrap">
  <header class="top">
    <div class="brand">
      <span class="eyebrow">SmartDukaan &middot; Field Sales</span>
      <h1>Route Scheduling Analytics</h1>
      <span class="sub" id="sub">Beat Plan (PJP) execution &mdash; running month</span>
    </div>
    <div class="hd-right">
      <span class="pill" id="monthpill">&hellip;</span>
      <span class="pill" id="genpill">&hellip;</span>
      <button class="refresh" onclick="load()">&#8635; Refresh</button>
    </div>
  </header>

  <div id="content">
    <div class="loading"><div class="spinner"></div>Loading current-month data&hellip;</div>
  </div>
</div>

<script>
var D = null;

function esc(s){return String(s==null?'':s).replace(/[&<>"]/g,function(c){return {'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c];});}
function adhColor(p){ if(p>=80)return '#34d399'; if(p>=50)return '#fbbf24'; if(p>=25)return '#fb923c'; return '#f87171'; }
function sevColor(p,inv){ var v=inv?100-p:p; if(v>=66)return '#f87171'; if(v>=33)return '#fbbf24'; return '#34d399'; }

function load(){
  document.getElementById('content').innerHTML='<div class="loading"><div class="spinner"></div>Loading current-month data&hellip;</div>';
  fetch(location.pathname.replace(/\/$/,'')+'/data',{headers:{'Accept':'application/json'}})
    .then(function(r){ if(!r.ok) throw new Error('http '+r.status); return r.json(); })
    .then(function(j){ D=j; render(); })
    .catch(function(e){ document.getElementById('content').innerHTML='<div class="loading">Could not load data ('+esc(e.message)+'). Are you signed in as an authorised user?</div>'; });
}

function render(){
  var k=D.kpis, dq=D.dataQuality, ds=D.deferralSummary, tp=D.travelPlan, ta=D.travelActual, ld=D.leads;
  document.getElementById('monthpill').innerHTML='Month: <b>'+esc(D.monthStart)+'</b> &rarr; <b>'+esc(D.today)+'</b>';
  document.getElementById('genpill').innerHTML='Generated <b>'+new Date().toLocaleString()+'</b>';

  var html='';

  /* KPIs */
  html+='<div class="kpis">';
  html+=kpi('Adherence (MTD)', k.adherencePct+'<small>%</small>', k.actualElapsed+' of '+k.plannedElapsed+' planned stops', adhColor(k.adherencePct));
  var l1=lvl('L1');
  html+=kpi('PJP Coverage L1', (l1?l1.coveragePct:0)+'<small>%</small>', (l1?l1.withPjp+'/'+l1.totalUsers:'0')+' field reps have a plan', '#22d3ee');
  html+=kpi('Active Beats', k.activeBeats, k.owners+' owners &middot; '+k.scheduleRows+' day-schedules', '#818cf8');
  html+=kpi('Auto "Missed"', ds.total, ds.systemGenerated+' system &middot; '+ds.human+' real reasons', '#fbbf24');
  html+=kpi('Heads Acted', ds.actioned, ds.rescheduled+' rescheduled &middot; '+ds.cancelled+' cancelled', ds.actioned? '#34d399':'#f87171');
  html+='</div>';

  /* coverage + reps */
  html+='<div class="sectionlabel">Plan Coverage &amp; Adherence</div>';
  html+='<div class="grid g3">';
  html+='<div class="card">'+repsTable()+'</div>';
  html+='<div class="card"><h2>PJP coverage by sales level</h2><p class="desc">Sales positions (cs.position cat 4) that have at least one scheduled beat-day this month.</p>'+coverageBars()+'</div>';
  html+='</div>';

  /* deferrals */
  html+='<div class="sectionlabel">Deferrals &amp; Reasons</div>';
  html+='<div class="grid g2">';
  html+='<div class="card"><h2>Deferral nature</h2><p class="desc">Are deferrals deliberate (real reason) or auto-flagged missed beats?</p>'+deferDonut()+'</div>';
  html+='<div class="card"><h2>Reasons posted</h2><p class="desc">Every reason string recorded against a deferral this month.</p>'+reasonList()+'</div>';
  html+='</div>';

  /* routes + travel */
  html+='<div class="sectionlabel">Route Appropriateness &amp; Travel Time</div>';
  html+='<div class="grid g2">';
  html+='<div class="card"><h2>Distance between consecutive stops</h2><p class="desc">Straight-line distance per leg across all routed beat-days. Well-designed beats cluster geographically (mostly &lt;15&nbsp;km).</p>'+legBars()+'</div>';
  html+='<div class="card"><h2>Expected vs actual travel</h2><p class="desc">Expected = 1.2&times; straight-line distance @ 25&nbsp;km/h. Actual = device-recorded transit time on executed visits.</p>'+travelBlock()+'</div>';
  html+='</div>';

  /* data quality */
  html+='<div class="sectionlabel">Data Quality &amp; System Health</div>';
  html+='<div class="card"><h2>Data quality signals</h2><p class="desc">Higher red = more missing / inconsistent data weakening the analytics.</p>'+dqChips()+'</div>';

  /* leads */
  html+='<div class="card"><h2>Lead pipeline usage (current month)</h2><p class="desc">Adoption of lead scheduling within beats.</p>'+
    '<div class="tiles">'+
    tile('Leads created', ld.leadsCreated)+
    tile('Lead routes scheduled', ld.routesScheduled)+
    tile('Lead approvals raised', ld.approvalsRaised)+
    '</div></div>';

  /* findings */
  html+='<div class="callout">'+findings()+'</div>';

  document.getElementById('content').innerHTML=html;
}

function kpi(label,val,foot,accent){
  return '<div class="kpi" style="--accent:'+accent+'"><div class="label">'+label+'</div>'+
    '<div class="val" style="color:'+accent+'">'+val+'</div><div class="foot">'+foot+'</div></div>';
}
function tile(t,v){ return '<div class="tile"><div class="t">'+t+'</div><div class="v">'+v+'</div></div>'; }
function lvl(name){ for(var i=0;i<D.coverageByLevel.length;i++){ if(D.coverageByLevel[i].level===name) return D.coverageByLevel[i]; } return null; }

function coverageBars(){
  var rows=D.coverageByLevel, max=0; rows.forEach(function(r){ if(r.totalUsers>max)max=r.totalUsers; });
  var h=''; rows.forEach(function(r){
    var w = max? Math.round(100*r.withPjp/max):0;
    var wt = max? Math.round(100*r.totalUsers/max):0;
    h+='<div class="barrow"><div class="name">'+esc(r.level)+'</div>'+
       '<div class="track"><div style="position:absolute;inset:0;width:'+wt+'%;background:#1a2742;border-radius:8px"></div>'+
       '<div class="fill" style="width:'+w+'%;position:relative">'+(r.withPjp||'')+'</div></div>'+
       '<div class="meta">'+r.withPjp+'/'+r.totalUsers+' &middot; '+r.coveragePct+'%</div></div>';
  });
  h+='<p class="desc" style="margin-top:14px">Filled bar = reps <b>with</b> a plan; faint bar = total reps at that level. L4/L5 are managers and typically supervise rather than run a beat.</p>';
  return h;
}

function repsTable(){
  var rows=D.reps.slice();
  var h='<h2>Per-rep adherence ('+rows.length+' beat owners)</h2><p class="desc">Planned vs actually checked-in stops, month-to-date. Click a header to sort.</p>';
  h+='<div style="max-height:430px;overflow:auto"><table id="reptbl"><thead><tr>'+
     '<th onclick="sortReps(\'name\')">Rep</th><th onclick="sortReps(\'level\')">Lvl</th>'+
     '<th class="num" onclick="sortReps(\'plannedElapsed\')">Plan</th>'+
     '<th class="num" onclick="sortReps(\'actual\')">Done</th>'+
     '<th class="num" onclick="sortReps(\'adherencePct\')">Adher.</th>'+
     '<th class="num" onclick="sortReps(\'autoMissed\')">Missed</th>'+
     '<th class="num" onclick="sortReps(\'punchDays\')">Days</th></tr></thead><tbody>';
  rows.forEach(function(r){
    var c=adhColor(r.adherencePct);
    h+='<tr><td>'+esc(r.name)+'</td><td><span class="lvl">'+esc(r.level)+'</span></td>'+
       '<td class="num">'+r.plannedElapsed+'</td><td class="num">'+r.actual+'</td>'+
       '<td class="num"><span class="adh" style="color:'+c+'">'+r.adherencePct+'%</span>'+
       '<span class="meter"><i style="width:'+Math.min(100,r.adherencePct)+'%;background:'+c+'"></i></span></td>'+
       '<td class="num"'+(r.autoMissed>0?' style="color:#fbbf24;font-weight:650"':'')+'>'+r.autoMissed+'</td>'+
       '<td class="num">'+r.punchDays+'</td></tr>';
  });
  h+='</tbody></table></div>';
  return h;
}
var sortDir={};
function sortReps(key){
  sortDir[key]=!sortDir[key];
  D.reps.sort(function(a,b){ var x=a[key],y=b[key];
    if(typeof x==='string'){ return sortDir[key]? (''+x).localeCompare(y):(''+y).localeCompare(x); }
    return sortDir[key]? x-y : y-x; });
  document.querySelector('#content .g3 .card').innerHTML=repsTable();
}

function deferDonut(){
  var s=D.deferralSummary, tot=s.total||1;
  var sysPct=Math.round(100*s.systemGenerated/tot), humanPct=100-sysPct;
  var g='conic-gradient(#fbbf24 0 '+sysPct+'%, #34d399 '+sysPct+'% 100%)';
  var h='<div class="donutwrap"><div class="donut" style="background:'+g+'"><div class="center">'+
        '<div style="font-size:26px;font-weight:780">'+s.total+'</div><div style="font-size:11px;color:#8ea0bd">deferrals</div></div></div>'+
        '<div class="legend">'+
        '<div class="it"><span class="dot" style="background:#fbbf24"></span><div><b>'+s.systemGenerated+'</b> system auto-flagged ('+sysPct+'%)<br><span style="color:#8ea0bd;font-size:12px">"Beat missed", "no punch-in", "agenda unfilled"</span></div></div>'+
        '<div class="it"><span class="dot" style="background:#34d399"></span><div><b>'+s.human+'</b> genuine reason ('+humanPct+'%)</div></div>'+
        '<div class="it"><span class="dot" style="background:#6366f1"></span><div><b>'+s.actioned+'</b> acted on by a head ('+s.rescheduled+' rescheduled, '+s.cancelled+' cancelled)</div></div>'+
        '</div></div>';
  return h;
}

function reasonList(){
  var h='<div style="max-height:330px;overflow:auto">';
  D.deferralReasons.forEach(function(r){
    var tag=r.systemGenerated?'<span class="tag sys">system</span>':'<span class="tag human">real</span>';
    h+='<div class="reason"><div class="txt">'+esc(r.reason)+tag+' <span style="color:#64759a;font-size:11px">('+esc(r.status)+')</span></div><div class="n">'+r.count+'</div></div>';
  });
  h+='</div>';
  return h;
}

function legBars(){
  var rows=D.legBuckets, max=0; rows.forEach(function(r){ if(r.count>max)max=r.count; });
  var colors={'0-2 km':'#34d399','2-5 km':'#34d399','5-15 km':'#a3e635','15-50 km':'#fbbf24','50-200 km':'#fb923c','200 km+':'#f87171'};
  var h=''; rows.forEach(function(r){
    var w=max?Math.round(100*r.count/max):0; var col=colors[r.bucket]||'#6366f1';
    h+='<div class="barrow"><div class="name">'+esc(r.bucket)+'</div>'+
       '<div class="track"><div class="fill" style="width:'+w+'%;background:'+col+'">'+r.count+'</div></div>'+
       '<div class="meta"></div></div>';
  });
  var tp=D.travelPlan;
  h+='<div class="tiles" style="margin-top:16px">'+
     tile('Avg leg', tp.avgLegKm+'<small> km</small>')+
     tile('Longest leg', Math.round(tp.maxLegKm)+'<small> km</small>')+
     tile('Legs &gt; 15 km', tp.pctOver15+'<small>%</small>')+
     '</div>';
  return h;
}

function travelBlock(){
  var ta=D.travelActual, tp=D.travelPlan;
  var maxh=Math.max(ta.transitHrs,ta.estimatedHrs,1);
  function bar(label,val,col){ var w=Math.round(100*val/maxh);
    return '<div class="barrow" style="grid-template-columns:120px 1fr 70px"><div class="name">'+label+'</div>'+
      '<div class="track"><div class="fill" style="width:'+w+'%;background:'+col+'"></div></div>'+
      '<div class="meta">'+val+' h</div></div>'; }
  var h=bar('App estimate',ta.estimatedHrs,'#6366f1')+bar('Actual transit',ta.transitHrs,'#f87171');
  h+='<div class="tiles" style="margin-top:16px">'+
     tile('Actual / estimate', ta.actualVsEstimateRatio+'<small>&times;</small>')+
     tile('Avg transit / visit', ta.avgTransitMin+'<small> min</small>')+
     tile('Expected drive/day', (tp.beatDays? (Math.round(tp.expectedTravelHrs/tp.beatDays*10)/10):0)+'<small> h</small>')+
     '</div>';
  h+='<p class="desc" style="margin-top:14px">Across the planned month, expected driving totals <b>'+Math.round(tp.expectedRoadKm)+' km</b> ('+tp.expectedTravelHrs+' h) over '+tp.beatDays+' beat-days &mdash; '+(tp.beatDays?Math.round(tp.expectedRoadKm/tp.beatDays):0)+' km/day on average.</p>';
  return h;
}

function dqChips(){
  var dq=D.dataQuality;
  function chip(ttl,det,pct,inv){
    var col=sevColor(pct,inv);
    return '<div class="chip"><span class="sev" style="background:'+col+'"></span><div class="body"><div class="ttl">'+ttl+'</div><div class="det">'+det+'</div></div><div class="pct" style="color:'+col+'">'+pct+'%</div></div>';
  }
  var bridgePct = dq.beatOwners? Math.round(100*dq.ownersMappedToExecution/dq.beatOwners):0;
  var h='';
  h+=chip('Route legs missing distance','beat_route.distance_from_prev_km is NULL ('+dq.routeNullDistance+'/'+dq.routeStops+')',dq.routeNullDistancePct,false);
  h+=chip('Visits with zero transit time',dq.zeroTransitPct+'% of '+dq.visitRecords+' franchisee visits',dq.zeroTransitPct,false);
  h+=chip('Visits missing time-spent','time_spent is 00:00:00',dq.zeroTimeSpentPct,false);
  h+=chip('Visits missing GPS location','visit_location empty',dq.noVisitLocationPct,false);
  h+=chip('Visits missing battery level','battery_level not reported',dq.noBatteryPct,false);
  h+=chip('Planning &harr; execution identity bridge',dq.ownersMappedToExecution+'/'+dq.beatOwners+' owners resolvable by email (no FK exists)',bridgePct,true);
  var noActPct = dq.scheduledBeatDaysElapsed? Math.round(100*dq.beatDaysNoActivity/dq.scheduledBeatDaysElapsed):0;
  h+=chip('Scheduled beat-days with no activity',dq.beatDaysNoActivity+'/'+dq.scheduledBeatDaysElapsed+' planned days had zero tracking',noActPct,false);
  h+=chip('Distinct mark_type spellings',dq.distinctMarkTypes+' variants incl. CHECKIN-CHECKOUT vs CHECKIN_CHECKOUT &amp; "2"',dq.distinctMarkTypes>6?80:(dq.distinctMarkTypes>3?45:10),false);
  return '<div class="dq">'+h+'</div>';
}

function findings(){
  var k=D.kpis, ds=D.deferralSummary, tp=D.travelPlan, ta=D.travelActual, dq=D.dataQuality, l1=lvl('L1');
  var h='<h2>What the data says &amp; what to fix</h2><ul>';
  h+='<li><b>Routes are not geographically clustered.</b> '+tp.pctOver15+'% of legs exceed 15&nbsp;km and the longest is '+Math.round(tp.maxLegKm)+'&nbsp;km &mdash; consecutive stops sit in different cities. Re-sequence beats by proximity (nearest-neighbour) and cap daily travel.</li>';
  h+='<li><b>Deferrals are not real deferrals.</b> '+Math.round(100*ds.systemGenerated/(ds.total||1))+'% are system "missed beat" flags and heads acted on '+ds.actioned+'. Add a mandatory reason picker on genuine deferral and an action SLA for managers.</li>';
  h+='<li><b>Travel is under-estimated.</b> Actual transit runs '+ta.actualVsEstimateRatio+'&times; the app estimate ('+ta.avgTransitMin+'&nbsp;min/visit). Recalibrate the planner&rsquo;s speed/road-factor and persist per-leg distance &amp; time.</li>';
  h+='<li><b>Coverage gap.</b> '+(l1?l1.withPjp+' of '+l1.totalUsers:'?')+' L1 field reps have a plan this month; the rest run no PJP. Make a monthly PJP mandatory before month start.</li>';
  h+='<li><b>Data plumbing is fragile.</b> '+dq.routeNullDistancePct+'% of route legs store no distance, mark_type has '+dq.distinctMarkTypes+' spellings, and planning &amp; execution share no key (bridged only by email). Standardise mark_type, persist leg metrics, and add an auth&rarr;dtr user mapping.</li>';
  h+='</ul>';
  return h;
}

load();
</script>
</body>
</html>]]#