546 lines
25 KiB
HTML
546 lines
25 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Summary Reconciliation Check — Undo Designs</title>
|
||
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
||
<style>
|
||
:root {
|
||
--navy: #0C1A3A;
|
||
--navy-2: #12244C;
|
||
--navy-3: #1a2f5e;
|
||
--navy-4: #0a1428;
|
||
--cyan: #00D4FF;
|
||
--cyan-dim: rgba(0,212,255,.12);
|
||
--cyan-glow: rgba(0,212,255,.06);
|
||
--blue: #1B8EF8;
|
||
--green: #10D98A;
|
||
--green-dim: rgba(16,217,138,.12);
|
||
--red: #F04438;
|
||
--red-dim: rgba(240,68,56,.12);
|
||
--amber: #F79009;
|
||
--amber-dim: rgba(247,144,9,.12);
|
||
--w1: rgba(255,255,255,.95);
|
||
--w2: rgba(255,255,255,.65);
|
||
--w3: rgba(255,255,255,.35);
|
||
--w4: rgba(255,255,255,.10);
|
||
--w5: rgba(255,255,255,.05);
|
||
--border: rgba(255,255,255,.07);
|
||
--border-c: rgba(0,212,255,.18);
|
||
--mono: 'JetBrains Mono', monospace;
|
||
--disp: 'Space Grotesk', sans-serif;
|
||
--body: 'Inter', sans-serif;
|
||
--radius: 10px;
|
||
}
|
||
|
||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||
|
||
body {
|
||
font-family: var(--body);
|
||
background: var(--navy-4);
|
||
color: var(--w1);
|
||
min-height: 100vh;
|
||
-webkit-font-smoothing: antialiased;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
body::before {
|
||
content: '';
|
||
position: fixed; inset: 0; pointer-events: none; z-index: 0;
|
||
background-image: radial-gradient(circle, rgba(0,212,255,.07) 1px, transparent 1px);
|
||
background-size: 28px 28px;
|
||
}
|
||
|
||
header {
|
||
position: sticky; top: 0; z-index: 100;
|
||
background: rgba(12,26,58,.85);
|
||
backdrop-filter: blur(12px);
|
||
border-bottom: 1px solid var(--border);
|
||
padding: 0 32px;
|
||
height: 60px;
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
}
|
||
.logo {
|
||
display: flex; align-items: center; gap: 10px;
|
||
font-family: var(--disp); font-size: 15px; font-weight: 600;
|
||
color: var(--w1); text-decoration: none;
|
||
}
|
||
.logo-icon {
|
||
width: 30px; height: 30px;
|
||
background: linear-gradient(135deg, var(--navy-3), var(--navy-2));
|
||
border: 1px solid var(--border-c);
|
||
border-radius: 7px;
|
||
display: flex; align-items: center; justify-content: center;
|
||
}
|
||
.logo-icon svg { width: 16px; height: 16px; }
|
||
.logo span { color: var(--cyan); }
|
||
|
||
main {
|
||
position: relative; z-index: 1;
|
||
flex: 1;
|
||
max-width: 760px;
|
||
width: 100%;
|
||
margin: 0 auto;
|
||
padding: 48px 24px 80px;
|
||
}
|
||
|
||
.page-title { margin-bottom: 24px; }
|
||
.eyebrow {
|
||
font-family: var(--mono); font-size: 10px;
|
||
letter-spacing: .16em; text-transform: uppercase;
|
||
color: var(--cyan); margin-bottom: 10px;
|
||
}
|
||
.page-title h1 {
|
||
font-family: var(--disp); font-size: 26px; font-weight: 700;
|
||
color: var(--w1); line-height: 1.2; margin-bottom: 8px;
|
||
}
|
||
.page-title p { font-size: 14px; color: var(--w2); line-height: 1.6; }
|
||
|
||
.card {
|
||
background: var(--navy-2);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
padding: 24px;
|
||
margin-bottom: 16px;
|
||
}
|
||
.card-label {
|
||
font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em;
|
||
text-transform: uppercase; color: var(--w3); margin-bottom: 14px;
|
||
}
|
||
|
||
.file-zone {
|
||
border: 1.5px dashed var(--border);
|
||
border-radius: 8px;
|
||
padding: 22px 16px;
|
||
text-align: center;
|
||
cursor: pointer;
|
||
transition: all .2s;
|
||
position: relative;
|
||
}
|
||
.file-zone:hover, .file-zone.drag-over { border-color: var(--cyan); background: var(--cyan-glow); }
|
||
.file-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
|
||
.file-zone-label { font-size: 13px; color: var(--w2); }
|
||
.file-zone-label strong { color: var(--cyan); }
|
||
.file-zone-sub { font-size: 11px; color: var(--w3); margin-top: 4px; }
|
||
.file-chosen { font-family: var(--mono); font-size: 11.5px; color: var(--green); margin-top: 8px; }
|
||
.field-note { font-size: 11.5px; color: var(--w3); margin-top: 6px; line-height: 1.5; }
|
||
|
||
.btn {
|
||
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
|
||
padding: 11px 22px; border-radius: 8px; border: none;
|
||
font-family: var(--disp); font-size: 13px; font-weight: 600;
|
||
cursor: pointer; transition: all .2s; text-decoration: none;
|
||
width: 100%; margin-top: 18px;
|
||
}
|
||
.btn-primary { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: var(--navy); }
|
||
.btn-primary:hover { filter: brightness(1.08); }
|
||
.btn-primary:disabled { opacity: .4; cursor: not-allowed; filter: none; }
|
||
|
||
.spinner {
|
||
display: none;
|
||
align-items: center; gap: 8px;
|
||
font-family: var(--mono); font-size: 11px; color: var(--w3);
|
||
margin-top: 12px;
|
||
}
|
||
.spinner.visible { display: flex; }
|
||
.spinner-dot {
|
||
width: 6px; height: 6px; border-radius: 50%; background: var(--cyan);
|
||
animation: pulse 1s infinite ease-in-out;
|
||
}
|
||
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
|
||
|
||
.error-note {
|
||
display: none;
|
||
font-size: 12px; color: var(--red); background: var(--red-dim);
|
||
border: 1px solid rgba(240,68,56,.2); border-radius: 8px;
|
||
padding: 12px 14px; margin-top: 12px;
|
||
}
|
||
.error-note.visible { display: block; }
|
||
|
||
.result-card { display: none; }
|
||
.result-card.visible { display: block; }
|
||
.result-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
|
||
.result-icon {
|
||
width: 32px; height: 32px; border-radius: 8px;
|
||
display: flex; align-items: center; justify-content: center;
|
||
}
|
||
.result-icon.ok { background: var(--green-dim); }
|
||
.result-icon.warn { background: var(--red-dim); }
|
||
.result-icon svg { width: 16px; height: 16px; }
|
||
.result-title { font-family: var(--disp); font-size: 15px; font-weight: 600; color: var(--w1); }
|
||
.result-sub { font-size: 12px; color: var(--w3); margin-top: 2px; }
|
||
|
||
.acct-row {
|
||
border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
|
||
margin-bottom: 8px;
|
||
}
|
||
.acct-row.mismatch { border-color: rgba(240,68,56,.3); background: var(--red-dim); }
|
||
.acct-row-head { display: grid; grid-template-columns: 1fr 110px 110px 90px 70px; gap: 10px; align-items: center; }
|
||
.acct-row-head span:not(:first-child) { text-align: right; font-family: var(--mono); font-size: 11.5px; }
|
||
.acct-label { font-size: 12.5px; color: var(--w1); }
|
||
.recon-badge { padding: 3px 9px; border-radius: 20px; font-size: 10px; font-weight: 500; text-align: center; }
|
||
.recon-badge.ok { background: var(--green-dim); color: var(--green); }
|
||
.recon-badge.warn { background: var(--red-dim); color: var(--red); }
|
||
|
||
.acct-hint { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--w5); }
|
||
.acct-hint-label {
|
||
font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
|
||
color: var(--amber); margin-bottom: 6px;
|
||
}
|
||
.acct-hint-row {
|
||
display: flex; justify-content: space-between; font-size: 11.5px; color: var(--w2);
|
||
padding: 3px 0; font-family: var(--mono);
|
||
}
|
||
.acct-hint-empty { font-size: 11.5px; color: var(--w3); font-style: italic; }
|
||
|
||
.kb-toggle {
|
||
margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--w5);
|
||
display: flex; align-items: center; justify-content: space-between; cursor: pointer;
|
||
user-select: none;
|
||
}
|
||
.kb-toggle-label {
|
||
font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
|
||
color: var(--cyan);
|
||
}
|
||
.kb-toggle-arrow { color: var(--w3); font-size: 10px; transition: transform .15s; }
|
||
.kb-toggle.open .kb-toggle-arrow { transform: rotate(90deg); }
|
||
.kb-body { display: none; margin-top: 10px; }
|
||
.kb-body.open { display: block; }
|
||
.kb-explain-line { font-size: 11px; color: var(--w2); margin-bottom: 10px; line-height: 1.5; }
|
||
.kb-explain-line.partial { color: var(--amber); }
|
||
|
||
.kb-problem {
|
||
border: 1px solid var(--w5); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px;
|
||
font-size: 11px;
|
||
}
|
||
.kb-problem-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
|
||
.kb-problem-title { color: var(--w1); }
|
||
.kb-problem-kind {
|
||
font-family: var(--mono); font-size: 8.5px; letter-spacing: .06em; text-transform: uppercase;
|
||
padding: 1px 6px; border-radius: 10px; white-space: nowrap; height: fit-content;
|
||
}
|
||
.kb-problem-kind.keyed { background: var(--amber-dim); color: var(--amber); }
|
||
.kb-problem-kind.blanket { background: rgba(27,142,248,.15); color: var(--blue); }
|
||
.kb-problem-kind.uncovered { background: var(--red-dim); color: var(--red); }
|
||
.kb-problem-row { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--w2); padding: 1px 0; }
|
||
.kb-problem-row .lbl { color: var(--w3); }
|
||
.kb-problem-note { font-size: 10.5px; color: var(--w3); margin-top: 4px; line-height: 1.5; }
|
||
.kb-problem-note strong { color: var(--w2); }
|
||
|
||
.col-head {
|
||
display: grid; grid-template-columns: 1fr 110px 110px 90px 70px; gap: 10px;
|
||
font-family: var(--mono); font-size: 9px; letter-spacing: .06em; text-transform: uppercase;
|
||
color: var(--w3); padding: 0 14px 8px;
|
||
}
|
||
.col-head span:not(:first-child) { text-align: right; }
|
||
|
||
footer { position: relative; z-index: 1; text-align: center; padding: 20px; font-size: 11px; color: var(--w3); border-top: 1px solid var(--border); }
|
||
footer a { color: var(--cyan); text-decoration: none; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<header>
|
||
<a class="logo" href="/">
|
||
<div class="logo-icon">
|
||
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||
<path d="M2 4h12M2 8h8M2 12h5" stroke="#00D4FF" stroke-width="1.5" stroke-linecap="round"/>
|
||
</svg>
|
||
</div>
|
||
Summary <span>Check</span>
|
||
</a>
|
||
</header>
|
||
|
||
<main>
|
||
<div class="page-title">
|
||
<div class="eyebrow">Planeterra International Foundation</div>
|
||
<h1>Summary Reconciliation Check</h1>
|
||
<p>Reproduces the per-account balance check from "1. Summary (Manual)" columns AE-AJ: an independent trial balance total per account, compared against what the Summary sheet's own formulas currently produce. Flags any account whose manual E/F mapping doesn't fully cover the trial balance.</p>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-label">This Period's Workbook</div>
|
||
<div class="file-zone" id="currentZone">
|
||
<input type="file" id="currentFileInput" accept=".xlsx,.xls">
|
||
<div class="file-zone-label"><strong>Drop this period's consolidated workbook here</strong> or browse</div>
|
||
<div class="file-zone-sub">Must contain "TB SC & Pr (Manual)" and "1. Summary (Manual)" sheets</div>
|
||
</div>
|
||
<div class="file-chosen" id="currentFileChosen" style="display:none"></div>
|
||
|
||
<div class="card-label" style="margin-top:20px">Prior Period's Workbook (optional)</div>
|
||
<div class="file-zone" id="priorZone">
|
||
<input type="file" id="priorFileInput" accept=".xlsx,.xls">
|
||
<div class="file-zone-label"><strong>Drop last period's workbook here</strong> or browse</div>
|
||
<div class="file-zone-sub">Enables the "new lines since last period" hint for any mismatched account</div>
|
||
</div>
|
||
<div class="file-chosen" id="priorFileChosen" style="display:none"></div>
|
||
|
||
<button class="btn btn-primary" id="checkBtn" disabled>Run Check</button>
|
||
<div class="spinner" id="spinner">
|
||
<div class="spinner-dot"></div>
|
||
Checking…
|
||
</div>
|
||
<div class="error-note" id="errorNote"></div>
|
||
</div>
|
||
|
||
<div class="card result-card" id="resultCard">
|
||
<div class="result-header">
|
||
<div class="result-icon" id="resultIcon">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="#10D98A" stroke-width="2.5">
|
||
<polyline points="20,6 9,17 4,12"/>
|
||
</svg>
|
||
</div>
|
||
<div>
|
||
<div class="result-title" id="resultTitle"></div>
|
||
<div class="result-sub" id="resultSub"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card-label" style="margin-top:4px">Aggregate Balance (the "is this workbook actually balanced" answer)</div>
|
||
<div id="totalsRows" style="margin-bottom:18px"></div>
|
||
|
||
<div class="card-label">Per-Account Detail</div>
|
||
<p class="field-note" style="margin-bottom:12px">Individual accounts can show a nonzero diff even when the aggregate above balances — that's usually a misclassification between two related accounts (their diffs cancel out), not a real coverage gap. Focus on accounts whose diff isn't offset by a matching pair. TB row numbers below refer to "TB RC & Pr (Manual)" for revenue accounts and "TB SC & Pr (Manual)" for expense accounts.</p>
|
||
<div class="col-head">
|
||
<span>Account</span><span>TB Total</span><span>Summary Total</span><span>Diff</span><span>Status</span>
|
||
</div>
|
||
<div id="acctRows"></div>
|
||
</div>
|
||
</main>
|
||
|
||
<footer>
|
||
Built by <a href="https://undodesigns.com" target="_blank">Undo Designs</a> · Summary Reconciliation Check v1
|
||
</footer>
|
||
|
||
<script>
|
||
const $ = id => document.getElementById(id);
|
||
|
||
function escapeHtml(s) {
|
||
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||
}
|
||
function fmtMoney(n) {
|
||
const sign = n < 0 ? '-' : '';
|
||
return sign + '$' + Math.abs(n).toLocaleString('en-US', {minimumFractionDigits: 2});
|
||
}
|
||
|
||
let currentFile = null;
|
||
let priorFile = null;
|
||
|
||
function setupZone(zoneId, inputId, chosenId, onSet) {
|
||
const zone = $(zoneId);
|
||
const input = $(inputId);
|
||
function handle(file) {
|
||
if (!file) return;
|
||
if (!/\.(xlsx|xls)$/i.test(file.name)) return;
|
||
onSet(file);
|
||
$(chosenId).textContent = file.name;
|
||
$(chosenId).style.display = 'block';
|
||
$('checkBtn').disabled = !currentFile;
|
||
$('resultCard').classList.remove('visible');
|
||
}
|
||
input.addEventListener('change', () => handle(input.files[0]));
|
||
zone.addEventListener('dragover', e => { e.preventDefault(); zone.classList.add('drag-over'); });
|
||
zone.addEventListener('dragleave', () => zone.classList.remove('drag-over'));
|
||
zone.addEventListener('drop', e => {
|
||
e.preventDefault(); zone.classList.remove('drag-over');
|
||
handle(e.dataTransfer.files[0]);
|
||
});
|
||
}
|
||
|
||
setupZone('currentZone', 'currentFileInput', 'currentFileChosen', f => currentFile = f);
|
||
setupZone('priorZone', 'priorFileInput', 'priorFileChosen', f => priorFile = f);
|
||
|
||
$('checkBtn').addEventListener('click', async () => {
|
||
if (!currentFile) return;
|
||
|
||
$('checkBtn').disabled = true;
|
||
$('spinner').classList.add('visible');
|
||
$('errorNote').classList.remove('visible');
|
||
$('resultCard').classList.remove('visible');
|
||
|
||
const fd = new FormData();
|
||
fd.append('current_file', currentFile);
|
||
if (priorFile) fd.append('prior_file', priorFile);
|
||
|
||
try {
|
||
const r = await fetch('/summary-check/api/check', { method: 'POST', body: fd });
|
||
const d = await r.json();
|
||
|
||
if (d.status === 'ok') {
|
||
const icon = $('resultIcon');
|
||
const aggregateBalanced = d.totals.revenue.matches && d.totals.expenses.matches;
|
||
if (aggregateBalanced) {
|
||
icon.className = 'result-icon ok';
|
||
$('resultTitle').textContent = 'Workbook balances';
|
||
} else {
|
||
icon.className = 'result-icon warn';
|
||
$('resultTitle').textContent = 'Workbook does not balance';
|
||
}
|
||
$('resultSub').textContent = (d.mismatch_count === 0 ? 'All accounts match individually. ' : `${d.mismatch_count} of ${d.total_count} individual accounts show a diff (see detail below). `)
|
||
+ (d.prior_file_used
|
||
? 'Prior-period workbook supplied — new-line hints included for mismatched accounts.'
|
||
: 'No prior-period workbook supplied — add one for new-line hints on mismatched accounts.');
|
||
|
||
$('totalsRows').innerHTML = ['revenue', 'expenses'].map(key => {
|
||
const t = d.totals[key];
|
||
const label = key === 'revenue' ? 'Total Revenue' : 'Total Expenses';
|
||
return `<div class="acct-row${t.matches ? '' : ' mismatch'}">
|
||
<div class="acct-row-head">
|
||
<span class="acct-label">${label}</span>
|
||
<span>${fmtMoney(t.tb_total)}</span>
|
||
<span>${fmtMoney(t.summary_total)}</span>
|
||
<span>${fmtMoney(t.diff)}</span>
|
||
<span class="recon-badge ${t.matches ? 'ok' : 'warn'}">${t.matches ? 'OK' : 'MISMATCH'}</span>
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
|
||
function fmtTbRows(rowsArr) {
|
||
if (!rowsArr || !rowsArr.length) return '';
|
||
return 'TB row' + (rowsArr.length > 1 ? 's ' : ' ') + rowsArr.join(', ');
|
||
}
|
||
function fmtCatProj(n) {
|
||
return escapeHtml(n.category) + ' / ' + escapeHtml(n.project);
|
||
}
|
||
|
||
function fmtSubtractionHint(p) {
|
||
const bits = [];
|
||
if (p.missing_from_subtraction_canada && p.missing_from_subtraction_canada.length) {
|
||
bits.push(`Summary row${p.missing_from_subtraction_canada.length>1?'s':''} <strong>${p.missing_from_subtraction_canada.join(', ')}</strong> ${p.missing_from_subtraction_canada.length>1?'are':'is'} not excluded from this row's Canada (E) formula — likely double-counted`);
|
||
}
|
||
if (p.missing_from_subtraction_us && p.missing_from_subtraction_us.length && p.blanket_us) {
|
||
bits.push(`Summary row${p.missing_from_subtraction_us.length>1?'s':''} <strong>${p.missing_from_subtraction_us.join(', ')}</strong> ${p.missing_from_subtraction_us.length>1?'are':'is'} not excluded from this row's US (F) formula`);
|
||
}
|
||
if (p.extra_subtraction_canada && p.extra_subtraction_canada.length) {
|
||
bits.push(`Row${p.extra_subtraction_canada.length>1?'s':''} <strong>${p.extra_subtraction_canada.join(', ')}</strong> ${p.extra_subtraction_canada.length>1?'are':'is'} subtracted in Canada (E) but ${p.extra_subtraction_canada.length>1?"aren't":"isn't"} a dedicated row for this category — likely an over-subtraction`);
|
||
}
|
||
return bits.join('. ');
|
||
}
|
||
|
||
function fmtKbProblem(p) {
|
||
if (p.kind === 'keyed') {
|
||
return `<div class="kb-problem">
|
||
<div class="kb-problem-head">
|
||
<span class="kb-problem-title">${escapeHtml(p.category)} / ${escapeHtml(p.project)} ${p.summary_row ? '<span style="color:var(--w3)">→ Summary row ' + p.summary_row + '</span>' : '<span style="color:var(--red)">→ no TB data under this account (likely a cross-account reference)</span>'}</span>
|
||
<span class="kb-problem-kind keyed">Keyed row</span>
|
||
</div>
|
||
<div class="kb-problem-row"><span class="lbl">TB (${fmtTbRows(p.tb_rows) || 'none'})</span><span>${fmtMoney(p.tb_canada)} CAN / ${fmtMoney(p.tb_us)} US</span></div>
|
||
<div class="kb-problem-row"><span class="lbl">Summary row ${p.summary_row ?? '—'}</span><span>${fmtMoney(p.summary_canada)} CAN / ${fmtMoney(p.summary_us)} US</span></div>
|
||
<div class="kb-problem-row"><span class="lbl">Diff (Summary − TB)</span><span style="color:var(--red)">${fmtMoney(p.diff_canada)} CAN / ${fmtMoney(p.diff_us)} US</span></div>
|
||
</div>`;
|
||
}
|
||
if (p.kind === 'blanket') {
|
||
const hint = fmtSubtractionHint(p);
|
||
return `<div class="kb-problem">
|
||
<div class="kb-problem-head">
|
||
<span class="kb-problem-title">${escapeHtml(p.category)} <span style="color:var(--w3)">→ blanket Summary row ${p.summary_row}</span></span>
|
||
<span class="kb-problem-kind blanket">Blanket collector</span>
|
||
</div>
|
||
<div class="kb-problem-row"><span class="lbl">Uncovered TB residual (${fmtTbRows(p.tb_rows) || 'none'})</span><span>${fmtMoney(p.uncovered_canada)} CAN / ${fmtMoney(p.uncovered_us)} US</span></div>
|
||
<div class="kb-problem-row"><span class="lbl">Blanket row cached value</span><span>${fmtMoney(p.blanket_canada)} CAN / ${fmtMoney(p.blanket_us)} US</span></div>
|
||
<div class="kb-problem-row"><span class="lbl">Diff (blanket − uncovered)</span><span style="color:var(--red)">${fmtMoney(p.diff_canada)} CAN / ${fmtMoney(p.diff_us)} US</span></div>
|
||
${hint ? `<div class="kb-problem-note">${hint}</div>` : ''}
|
||
</div>`;
|
||
}
|
||
// uncovered
|
||
return `<div class="kb-problem">
|
||
<div class="kb-problem-head">
|
||
<span class="kb-problem-title">${escapeHtml(p.category)} <span style="color:var(--red)">→ no Summary row captures this at all (no dedicated project row, no blanket collector)</span></span>
|
||
<span class="kb-problem-kind uncovered">Fully uncovered</span>
|
||
</div>
|
||
<div class="kb-problem-row"><span class="lbl">TB (${fmtTbRows(p.tb_rows) || 'none'})</span><span>${fmtMoney(p.canada)} CAN / ${fmtMoney(p.us)} US</span></div>
|
||
</div>`;
|
||
}
|
||
|
||
let kbCounter = 0;
|
||
window.toggleKb = function(id) {
|
||
const body = document.getElementById('kbBody' + id);
|
||
const toggle = document.getElementById('kbToggle' + id);
|
||
body.classList.toggle('open');
|
||
toggle.classList.toggle('open');
|
||
};
|
||
|
||
$('acctRows').innerHTML = d.accounts.map(a => {
|
||
let hints = '';
|
||
if (!a.matches) {
|
||
const rowCountLine = ('prior_tb_row_count' in a)
|
||
? `<div class="acct-hint-row"><span>TB row count</span><span>${a.prior_tb_row_count} prior → ${a.tb_row_count} current</span></div>`
|
||
: `<div class="acct-hint-row"><span>TB row count</span><span>${a.tb_row_count} current (no prior period uploaded)</span></div>`;
|
||
hints += `<div class="acct-hint">
|
||
<div class="acct-hint-label">Row count comparison</div>
|
||
${rowCountLine}
|
||
</div>`;
|
||
if (a.new_since_prior) {
|
||
hints += `<div class="acct-hint">
|
||
<div class="acct-hint-label">New category/project lines since prior period (present in current TB, absent from prior TB — plain diff, no guessing)</div>
|
||
${a.new_since_prior.length
|
||
? a.new_since_prior.map(n => `<div class="acct-hint-row"><span>${fmtCatProj(n)} <span style="color:var(--w3)">(${fmtTbRows(n.tb_rows)})</span></span><span>${fmtMoney(n.canada)} CAN / ${fmtMoney(n.us)} US</span></div>`).join('')
|
||
: '<div class="acct-hint-empty">None found among brand-new combos.</div>'}
|
||
</div>`;
|
||
}
|
||
if (a.grown_since_prior && a.grown_since_prior.length) {
|
||
hints += `<div class="acct-hint">
|
||
<div class="acct-hint-label" style="color:var(--amber)">Existing combos with MORE rows than last period — one or more of these rows is new, but shares its category/project with an old row so it can't be singled out automatically. Review all rows listed.</div>
|
||
${a.grown_since_prior.map(n => `<div class="acct-hint-row"><span>${fmtCatProj(n)} <span style="color:var(--w3)">(${n.prior_count} row${n.prior_count===1?'':'s'} prior → ${n.current_count} now — ${fmtTbRows(n.tb_rows)})</span></span><span>${fmtMoney(n.canada)} CAN / ${fmtMoney(n.us)} US</span></div>`).join('')}
|
||
</div>`;
|
||
}
|
||
if (!a.new_since_prior) {
|
||
hints += `<div class="acct-hint-empty" style="margin-top:6px">Upload a prior-period workbook to see exactly which lines are new for this account.</div>`;
|
||
}
|
||
}
|
||
|
||
let kbSection = '';
|
||
if (!a.matches && a.key_breakdown) {
|
||
const kb = a.key_breakdown;
|
||
kbCounter++;
|
||
const kid = kbCounter;
|
||
const fullyExplained = Math.abs(kb.unexplained_diff) < 0.02;
|
||
const explainLine = fullyExplained
|
||
? `This breakdown fully accounts for the ${fmtMoney(a.diff)} diff above — every dollar is traced to a specific row or gap below.`
|
||
: `This breakdown traces ${fmtMoney(kb.explained_diff)} of the ${fmtMoney(a.diff)} diff (${fmtMoney(kb.unexplained_diff)} unaccounted for). The remainder likely reflects a difference between the TB RC and TB SC sheets themselves for this account (revenue accounts' Spend-Category sheet is coarser than the Revenue-Category one), rather than a row-level formula bug.`;
|
||
const problemsHtml = kb.problems.length
|
||
? kb.problems.map(fmtKbProblem).join('')
|
||
: `<div class="acct-hint-empty">No individual row-level or blanket-collector mismatches found — checked ${kb.checked_keys} TB line(s) across ${kb.checked_categories} categor${kb.checked_categories===1?'y':'ies'}.</div>`;
|
||
kbSection = `
|
||
<div class="kb-toggle" id="kbToggle${kid}" onclick="toggleKb(${kid})">
|
||
<span class="kb-toggle-label">Detailed line-by-line breakdown (${kb.problems.length} flagged)</span>
|
||
<span class="kb-toggle-arrow">▶</span>
|
||
</div>
|
||
<div class="kb-body" id="kbBody${kid}">
|
||
<div class="kb-explain-line${fullyExplained ? '' : ' partial'}">${explainLine}</div>
|
||
${problemsHtml}
|
||
</div>`;
|
||
}
|
||
|
||
return `<div class="acct-row${a.matches ? '' : ' mismatch'}">
|
||
<div class="acct-row-head">
|
||
<span class="acct-label">${escapeHtml(a.account)}</span>
|
||
<span>${fmtMoney(a.tb_total)}</span>
|
||
<span>${fmtMoney(a.summary_total)}</span>
|
||
<span>${fmtMoney(a.diff)}</span>
|
||
<span class="recon-badge ${a.matches ? 'ok' : 'warn'}">${a.matches ? 'OK' : 'MISMATCH'}</span>
|
||
</div>
|
||
${hints}
|
||
${kbSection}
|
||
</div>`;
|
||
}).join('');
|
||
|
||
$('resultCard').classList.add('visible');
|
||
} else {
|
||
$('errorNote').textContent = d.error || 'Unexpected error';
|
||
$('errorNote').classList.add('visible');
|
||
}
|
||
} catch (e) {
|
||
$('errorNote').textContent = 'Network error: ' + e.message;
|
||
$('errorNote').classList.add('visible');
|
||
}
|
||
|
||
$('spinner').classList.remove('visible');
|
||
$('checkBtn').disabled = false;
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|