// FRAZIER Finance OS — Cash flow (page id 'forecast'; master sheet, 8 Oct 2026). // READ-ONLY HISTORY, NOT A FORECAST. Every month's Bank Book // money in / out / month-end cash (payload.year.cashHistory joined with // payload.year.months for the "as of" date and continuity), as a chart and // a table, plus the open receivables by age as the expected inflow (when // they will be paid is unknown: the sheet has no due dates). // - selected month (useFinPeriod): the metrics, the highlighted month and // the receivables "as of" its as-of date; "All months" (opted in // below) shows the whole range and the receivables as of today // - a month with no Bank Book rows never reads as Rp 0: "No entries", and // its balance is the last known one, "as of " // - a missing Bank Book tab is a gap, never a zero // Live updates keep the selected month, an open month detail and the chart. // The old projection, recurring costs, cash checkpoint and what-ifs are gone // (the sheet holds none of that; CONTRACT §2.5 forecastAvailable = false). finPeriodAllowAll('forecast'); function finFcPlural(n, one, many) { return n + ' ' + (n === 1 ? one : (many || one + 's')); } function finFcNum(v) { return v !== null && v !== undefined && isFinite(Number(v)); } // 'YYYY-MM' → 'Sep'; with year → 'Sep 2026'. function finFcMon(ym, withYear) { const m = /^(\d{4})-(\d{2})/.exec(String(ym || '')); if (!m) return String(ym || ''); return FIN_MON[Number(m[2]) - 1] + (withYear ? ' ' + m[1] : ''); } function finFcSigned(n) { const v = Math.round(Number(n) || 0); return (v > 0 ? '+' : '') + finIDR(v); } // Axis tick labels: finIDRParts(v, { trim: true }) gives '4 jt', '−2,5 jt'. // One axis never mixes units: every tick takes the unit of the largest. function finFcAxisLabels(ticks) { const parts = ticks.map((t) => finIDRParts(t, { trim: true })); const units = parts.filter((p, i) => ticks[i] !== 0).map((p) => p.unit); const mixed = units.some((u) => u !== units[0]); return ticks.map((t, i) => { if (!t) return '0'; if (!mixed) { const p = parts[i]; return p.sign + p.num + (p.unit ? FIN_NBSP + p.unit : ''); } const maxAbs = Math.max.apply(null, ticks.map((x) => Math.abs(x))); const top = finIDRParts(maxAbs, { trim: true }); const div = top.unit === 'T' ? 1e12 : top.unit === 'M' ? 1e9 : top.unit === 'jt' ? 1e6 : 1; let num = (Math.round(Math.abs(t) / div * 100) / 100).toFixed(2); num = num.replace(/0+$/, '').replace(/\.$/, '').replace('.', ','); return (t < 0 ? FIN_MINUS : '') + num + (top.unit ? FIN_NBSP + top.unit : ''); }); } // Nice ticks covering [lo, hi]: of the 1 / 2 / 2,5 / 5 steps that give 3 // to maxTicks ticks, the one that wastes the least plot height. function finFcTicks(lo, hi, maxTicks) { if (hi === lo) { hi = lo + 1; } const range = hi - lo; let best = null; const mag0 = Math.pow(10, Math.floor(Math.log10(range / maxTicks))); [mag0 / 10, mag0, mag0 * 10].forEach((mag) => { [1, 2, 2.5, 5].forEach((s) => { const step = s * mag; const t0 = Math.floor(lo / step) * step; const t1 = Math.ceil(hi / step) * step; const count = Math.round((t1 - t0) / step) + 1; if (count < 3 || count > maxTicks) return; const waste = (t1 - t0) - range; if (!best || waste < best.waste - 1e-6 || (Math.abs(waste - best.waste) < 1e-6 && count < best.count)) best = { t0, step, count, waste }; }); }); if (!best) { const step = Math.pow(10, Math.ceil(Math.log10(range / Math.max(1, maxTicks - 1)))); const t0 = Math.floor(lo / step) * step; best = { t0, step, count: Math.round((Math.ceil(hi / step) * step - t0) / step) + 1 }; } const out = []; for (let i = 0; i < best.count; i++) out.push(Math.round(best.t0 + i * best.step)); return out; } function finFcCoarse() { try { return !!(window.matchMedia && window.matchMedia('(pointer: coarse)').matches); } catch (e) { return false; } } // One row per month: cashHistory (in / out / closing) + year.months // (as-of date, continuity, sales / vendor / payroll) + the period header. function finFcRows(data) { const year = (data && data.year) || {}; const hist = (year.cashHistory && year.cashHistory.months) || []; const ym = {}; (year.months || []).forEach((m) => { ym[m.key] = m; }); const per = {}; ((data && data.periods) || []).forEach((p) => { per[p.key] = p; }); const keys = hist.length ? hist.map((h) => h.key) : (year.months || []).map((m) => m.key); const hk = {}; hist.forEach((h) => { hk[h.key] = h; }); return keys.map((k) => { const h = hk[k] || null; const m = ym[k] || null; const p = per[k] || null; const bank = m && m.bank ? m.bank : null; const available = !!(p ? p.available !== false : (h ? h.available !== false : m && m.available !== false)); const hasBank = available && !!(h || bank) && !(p && p.bank && p.bank.available === false); const src = h || bank || {}; const entries = Number(src.entries) || 0; return { key: k, label: (p && p.label) || (m && m.label) || (h && h.label) || finMonthLabel(k), rangeLabel: (p && p.rangeLabel) || (m && m.rangeLabel) || '', period: p, month: m, start: (p && p.start) || (m && m.start), end: (p && p.end) || (m && m.end), available, hasBank, reason: !available ? 'This month is missing from the data.' : !hasBank ? ((p && p.bank && p.bank.reason) || 'The finance sheet has no Bank Book tab.') : null, opening: hasBank && finFcNum(src.opening) ? Number(src.opening) : null, in: hasBank ? Number(src.in) || 0 : null, out: hasBank ? Number(src.out) || 0 : null, net: hasBank ? Number(src.net) || 0 : null, closing: hasBank && finFcNum(src.closing) ? Number(src.closing) : null, entries, noData: hasBank && (h ? !!h.noData : entries === 0), asOf: bank ? bank.asOf : null, continuity: bank ? bank.continuity : null, isCurrent: !!((p && p.isCurrent) || (m && m.isCurrent)), }; }); } // ── Chart: money in (up) and out (down) per month + month-end cash line ── // One IDR axis (all three are rupiah of the same size). In = info blue, // out = neutral silver drawn below Rp 0 (position is the second cue), cash // = the silver line; a hollow dot = a month with no entries (balance // carried from the last entry), a gap = no Bank Book tab. function FinFcChart({ rows, selKey, onPick, label }) { const wrapRef = React.useRef(null); const [box, setBox] = React.useState({ w: 0, h: 0 }); const [hover, setHover] = React.useState(null); React.useLayoutEffect(() => { const el = wrapRef.current; if (!el) return undefined; const sync = () => setBox((b) => (b.w === el.clientWidth && b.h === el.clientHeight ? b : { w: el.clientWidth, h: el.clientHeight })); sync(); const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(sync) : null; if (ro) ro.observe(el); return () => { if (ro) ro.disconnect(); }; }, []); const n = rows.length; const W = box.w; const H = box.h; let geo = null; if (W > 0 && H > 0 && n > 0) { const ins = rows.filter((r) => r.hasBank).map((r) => r.in); const outs = rows.filter((r) => r.hasBank).map((r) => -r.out); const cls = rows.filter((r) => r.closing !== null).map((r) => r.closing); const vals = ins.concat(outs, cls, [0]); const ticks = finFcTicks(Math.min.apply(null, vals), Math.max.apply(null, vals), H < 260 ? 5 : 7); const tickLbl = finFcAxisLabels(ticks); const lo = ticks[0]; const hi = ticks[ticks.length - 1]; const tickW = Math.max.apply(null, tickLbl.map((t) => t.length)) * 7 + 12; const multiY = new Set(rows.map((r) => r.key.slice(0, 4))).size > 1; const padL = Math.max(34, tickW); const padR = 8; const padT = multiY ? 22 : 14; const padB = 28; const plotW = Math.max(10, W - padL - padR); const plotH = Math.max(10, H - padT - padB); const band = plotW / n; const cx = (i) => padL + band * (i + 0.5); const y = (v) => padT + (hi - v) / (hi - lo || 1) * plotH; const barW = Math.max(6, Math.min(28, band * 0.42)); const every = Math.max(1, Math.ceil(44 / Math.max(1, band))); // Several years: a hairline before each January and the year above it // (the first year at the left edge), so a long range reads by year. const yearsN = new Set(rows.map((r) => r.key.slice(0, 4))).size; const yearMarks = yearsN > 1 ? rows.map((r, i) => (i === 0 || r.key.slice(5, 7) === '01' ? { i, year: r.key.slice(0, 4), x: padL + band * i } : null)).filter(Boolean) : []; geo = { ticks, tickLbl, padL, padR, padT, padB, plotH, band, cx, y, zeroY: y(0), barW, every, yearMarks }; } // A bar from the baseline with only its data end rounded (r = 3). const barPath = (x, y0, y1) => { const w = geo.barW; const h = Math.abs(y1 - y0); if (h < 0.5) return null; const r = Math.min(3, h, w / 2); const L = x - w / 2; const R = x + w / 2; if (y1 < y0) return 'M' + L + ' ' + y0 + ' V' + (y1 + r) + ' Q' + L + ' ' + y1 + ' ' + (L + r) + ' ' + y1 + ' H' + (R - r) + ' Q' + R + ' ' + y1 + ' ' + R + ' ' + (y1 + r) + ' V' + y0 + ' Z'; return 'M' + L + ' ' + y0 + ' V' + (y1 - r) + ' Q' + L + ' ' + y1 + ' ' + (L + r) + ' ' + y1 + ' H' + (R - r) + ' Q' + R + ' ' + y1 + ' ' + R + ' ' + (y1 - r) + ' V' + y0 + ' Z'; }; // The cash line in runs: a gap at a month without Bank Book; dashed into a // month with no entries (the balance is carried, not known for it). const segs = []; if (geo) { for (let i = 1; i < n; i++) { const a = rows[i - 1]; const b = rows[i]; if (a.closing === null || b.closing === null) continue; segs.push({ i, d: 'M' + geo.cx(i - 1).toFixed(1) + ' ' + geo.y(a.closing).toFixed(1) + ' L' + geo.cx(i).toFixed(1) + ' ' + geo.y(b.closing).toFixed(1), carried: b.noData }); } } const idxFromEvent = (e) => { if (!geo) return null; const r = wrapRef.current.getBoundingClientRect(); const i = Math.floor((e.clientX - r.left - geo.padL) / geo.band); return i < 0 || i >= n ? null : i; }; const onKey = (e) => { if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') { e.preventDefault(); setHover((h) => { const cur = h === null ? (e.key === 'ArrowRight' ? -1 : n) : h; return Math.max(0, Math.min(n - 1, cur + (e.key === 'ArrowRight' ? 1 : -1))); }); } else if ((e.key === 'Enter' || e.key === ' ') && hover !== null) { e.preventDefault(); onPick && onPick(rows[hover].key); } else if (e.key === 'Escape') setHover(null); }; const tip = hover !== null && geo ? (() => { const r = rows[hover]; const px = geo.cx(hover); const narrow = W < 560; return ( ); })() : null; const selIdx = rows.findIndex((r) => r.key === selKey); return (
setHover(null)} onPointerMove={(e) => { if (e.pointerType === 'mouse' || e.pointerType === 'pen') setHover(idxFromEvent(e)); }} onPointerLeave={() => setHover(null)} onClick={(e) => { const i = idxFromEvent(e); if (i !== null && onPick) onPick(rows[i].key); }}> {geo ? ( ) : null} {tip}
); } // ── One month, every number traced (read-only) ────────────────────────── function FinFcMonthModal({ row, rows, selKey, onMove, onClose, onSelect, onNavigate }) { const i = rows.findIndex((r) => r.key === row.key); const prev = i > 0 ? rows[i - 1] : null; const next = i >= 0 && i < rows.length - 1 ? rows[i + 1] : null; const p = row.period; const m = row.month; const bank = p && p.bank && p.bank.available !== false ? p.bank : null; const O = bank && bank.opening ? bank.opening : null; const asOfNote = row.asOf && (row.noData || (row.end && row.asOf < row.end)) ? 'as of ' + finDate(row.asOf) : null; const flows = !row.available || !row.hasBank ? null : [ { id: 'o', label: 'Opening', note: O && O.entriesBefore ? 'year row + ' + finFcPlural(O.entriesBefore, 'entry', 'entries') + ' before' : (O && O.markerFound ? 'year row' : null), value: finIDR(row.opening) }, { id: 'i', label: 'Money in', note: row.noData ? null : finFcPlural(bank && bank.totals ? bank.totals.inEntries : 0, 'entry', 'entries'), value: row.noData ? 'No entries' : finIDR(row.in), tone: row.noData ? 'muted' : undefined }, { id: 'u', label: 'Money out', note: row.noData ? null : finFcPlural(bank && bank.totals ? bank.totals.outEntries : 0, 'entry', 'entries'), value: row.noData ? 'No entries' : finIDR(-row.out), tone: row.noData ? 'muted' : undefined }, { id: 'n', label: 'Net', value: row.noData ? '—' : finFcSigned(row.net), tone: row.noData ? 'muted' : row.net < 0 ? 'crit' : undefined }, { id: 'c', label: row.isCurrent ? 'Cash now' : 'Month-end cash', note: asOfNote, value: finIDR(row.closing), total: true, tone: row.closing < 0 ? 'crit' : undefined }, ]; const other = m && row.available ? [ m.sales ? { id: 'b', label: 'Invoices billed', note: finFcPlural(m.sales.invoices || 0, 'invoice') + ', DPP', value: finIDR(m.sales.billedDpp) } : null, m.sales ? { id: 'co', label: 'Collected', note: 'by paid date', value: finIDR(m.sales.collected) } : null, finFcNum(m.receivablesAtEnd) ? { id: 'r', label: 'Open receivables', note: 'at ' + (row.isCurrent ? 'today' : 'month end'), value: finIDR(m.receivablesAtEnd) } : null, m.vendor ? { id: 'v', label: 'Vendor bills', note: finFcPlural(m.vendor.bills || 0, 'bill'), value: finIDR(m.vendor.total) } : null, m.vendor && m.vendor.unpaid ? { id: 'vu', label: 'Of which unpaid', value: finIDR(m.vendor.unpaid), tone: 'warn' } : null, m.payroll ? { id: 'pp', label: 'People on payroll', value: String(m.payroll.people), note: m.payroll.amountsFilled ? null : 'amounts not filled' } : null, ] : []; const bankUrl = p ? finSheetTabUrl(p, 'bank') : null; return ( } footerRight={row.key !== selKey ? ( ) : ( )}> {!row.available ? ( {row.reason} No numbers are shown for this month. ) : !row.hasBank ? ( {row.reason} ) : null} {flows ? : null} {row.continuity === 'mismatch' && O ? ( The opening differs from the previous month’s closing by {finIDR(O.continuityDiff)}. ) : null} {row.noData && row.hasBank ? (

The Bank Book has no rows dated in this month, so the balance is carried from the last entry{row.asOf ? ' (' + finDate(row.asOf) + ')' : ''}. It is not known for the month itself.

) : null} {other.filter(Boolean).length ? (

Also this month

Sales, Vendor and Salary tabs
) : null} {bankUrl ? (
{bankUrl ? : null}
) : null}
); } // ── Year row of the month table (several years only) ───────────────────── // "2025 · 9 months with entries" and the year's money in / out / net and // year-end cash (as of its last entry). A year without Bank Book entries // says so; nothing reads as Rp 0. function FinFcYearRow({ year, rows }) { const ys = rows.filter((r) => r.key.slice(0, 4) === year); const ok = ys.filter((r) => r.available && r.hasBank); const withE = ok.filter((r) => !r.noData); const t = withE.reduce((a, r) => ({ in: a.in + r.in, out: a.out + r.out }), { in: 0, out: 0 }); const lastOk = ok.length ? ok[ok.length - 1] : null; const end = lastOk && lastOk.closing !== null ? lastOk.closing : null; const asOf = lastOk && lastOk.asOf && (lastOk.noData || (lastOk.end && lastOk.asOf < lastOk.end)) ? lastOk.asOf : null; const isNow = ys.some((r) => r.isCurrent); return (
{year}{withE.length ? finFcPlural(withE.length, 'month') + ' with entries' : 'No Bank Book entries'} {withE.length ? ( In {finIDR(t.in)} Out {finIDR(-t.out)} Net {finFcSigned(t.in - t.out)} {end !== null ? {isNow ? 'Cash now' : 'Year-end'} {finIDR(end)}{asOf ? as of {finDate(asOf)} : null} : null} ) : null}
); } // ── Page ──────────────────────────────────────────────────────────────── function FinForecast({ onNavigate }) { const { data } = useFinSheet(); const { period, periodKey, isAll, setPeriodKey } = useFinPeriod(); const [openKey, setOpenKey] = React.useState(null); const meta = (data && data.meta) || {}; const year = (data && data.year) || {}; const ch = year.cashHistory || {}; const rows = React.useMemo(() => finFcRows(data), [data]); const sel = isAll ? null : rows.find((r) => r.key === periodKey) || null; const okRows = rows.filter((r) => r.available && r.hasBank); const badRows = rows.filter((r) => !r.available || !r.hasBank); const withEntries = okRows.filter((r) => !r.noData); const first = rows.length ? rows[0] : null; const last = rows.length ? rows[rows.length - 1] : null; const rangeText = first && last ? (first.key === last.key ? finFcMon(first.key, true) : finFcMon(first.key, first.key.slice(0, 4) !== last.key.slice(0, 4)) + ' – ' + finFcMon(last.key, true)) : ''; const sheetUrl = meta.sheet && meta.sheet.url; const multiYear = finPeriodYears(rows).length > 1; // ── Metrics: the selected month, or every month of the sheet ─────── let M = null; if (isAll) { const lastOk = okRows.length ? okRows[okRows.length - 1] : null; const sum = (k) => withEntries.reduce((a, r) => a + r[k], 0); const ents = withEntries.reduce((a, r) => a + r.entries, 0); M = { cashLabel: 'Cash now', cash: lastOk ? lastOk.closing : null, cashAsOf: lastOk ? lastOk.asOf : null, cashStale: !!(lastOk && lastOk.asOf && meta.today && finFcDays(lastOk.asOf, meta.today) > ((meta.settings && meta.settings.staleDays) || 14)), in: withEntries.length ? sum('in') : null, out: withEntries.length ? sum('out') : null, net: withEntries.length ? sum('net') : null, flowHint: withEntries.length ? finFcPlural(ents, 'entry', 'entries') + ' in ' + finFcPlural(withEntries.length, 'month') : 'No Bank Book entries in any month', scope: rangeText, }; } else if (sel && sel.available && sel.hasBank) { const kc = sel.period && sel.period.kpis ? sel.period.kpis.cash : null; M = { cashLabel: sel.isCurrent ? 'Cash now' : 'Month-end cash', cash: kc && finFcNum(kc.amount) ? kc.amount : sel.closing, cashAsOf: (kc && kc.asOf) || sel.asOf, cashStale: !!(kc && kc.stale), in: sel.noData ? null : sel.in, out: sel.noData ? null : sel.out, net: sel.noData ? null : sel.net, flowHint: sel.noData ? 'No Bank Book entries dated in ' + finFcMon(sel.key, true) : finFcPlural(sel.entries, 'entry', 'entries'), scope: finFcMon(sel.key, true), }; } // ── Expected inflow: open receivables by age ──────────────────────── const now = (data && data.now) || {}; const K = sel && sel.period ? sel.period.kpis : null; const recv = isAll ? now.receivables : (K ? K.receivables : null); const aging = isAll ? now.aging : (K ? K.aging : null); const overdue = isAll ? now.overdue : (K ? K.overdue : null); const payables = isAll ? now.payables : (K ? K.payables : null); const recvAsOf = recv ? (recv.asOfDate || (isAll ? now.date : K && K.asOfDate)) : null; const overdueDays = (meta.settings && Number(meta.settings.overdueDays)) || 30; const AGE_TONE = { '0-30': 'info', '31-60': 'warn', '>60': 'crit' }; const openInv = Array.isArray(now.openInvoices) ? now.openInvoices : []; const today = meta.today || now.date; const open = openKey ? rows.find((r) => r.key === openKey) || null : null; const trend = ch.trend || null; const chartLabel = 'Money in, money out and month-end cash from the Bank Book, ' + rangeText; return (
Money in and out of the Bank Book, month by month, across the sheet ({rangeText}).} actions={(sel && sel.period) || last ? : null} /> {!isAll && sel && !sel.available ? ( : null} /> ) : !isAll && sel && !sel.hasBank ? ( : null} /> ) : M ? ( Old : null} hint={M.cashAsOf ? 'Bank Book · as of ' + finDate(M.cashAsOf) : 'Bank Book'} /> ) : null} History, not a forecast.{' '} {trend && finFcNum(trend.avgNet) ? <>Over the last {finFcPlural(Array.isArray(trend.months) ? trend.months.length : Number(trend.months) || 0, 'month')} with entries{Array.isArray(trend.months) && trend.months.length ? ' (' + trend.months.map((k) => finFcMon(k, true)).join(', ') + ')' : ''}, net cash averaged {finFcSigned(trend.avgNet)} a month. That is a past average, not a projection. : (ch.forecastNote || 'There is not enough Bank Book history for a projection.')}
Money in Money out (below Rp 0) Month-end cash {rows.some((r) => r.noData) ? No entries, balance carried : null} {badRows.length ? No Bank Book : null}
{rows.length ? ( ) : }
{rows.map((r, ri) => { const yearHead = multiYear && (ri === 0 || rows[ri - 1].key.slice(0, 4) !== r.key.slice(0, 4)) ? : null; const isSel = !isAll && r.key === periodKey; const bad = !r.available || !r.hasBank; const sub = (bad ? (r.available ? 'No Bank Book tab' : 'Not in the data') : r.noData ? 'No Bank Book entries' : finFcPlural(r.entries, 'entry', 'entries') + (r.continuity === 'mismatch' ? ' · opening differs' : '')); const asOfNote = !bad && r.asOf && (r.noData || (r.end && r.asOf < r.end)) ? 'as of ' + finDate(r.asOf, { year: r.asOf.slice(0, 4) !== r.key.slice(0, 4) ? undefined : false }) : null; const flow = (v, neg) => (bad ? — : r.noData ? No entries : (neg ? finIDR(-v) : finIDR(v))); return ( {yearHead} setOpenKey(r.key)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setOpenKey(r.key); } }}> ); })} {withEntries.length && first && last ? (() => { const t = withEntries.reduce((a, r) => ({ in: a.in + r.in, out: a.out + r.out }), { in: 0, out: 0 }); const firstOk = okRows[0]; const lastOk = okRows[okRows.length - 1]; return ( ); })() : null}
Month Opening Money in Money out Net Month-end cash
{r.label}{isSel ? Selected : null}{r.isCurrent ? Now : null}} sub={sub} subTone={bad ? 'crit' : undefined} /> {bad || r.opening === null ? '—' : finIDR(r.opening)} {flow(r.in)} {flow(r.out, true)} {bad || r.noData ? — : finFcSigned(r.net)} {bad || r.closing === null ? — : {finIDR(r.closing)}} sub={asOfNote} dash={false} />} {bad ? null : ( )}
{rangeText}{badRows.length ? ' · ' + finFcPlural(badRows.length, 'month') + ' without Bank Book' : ''}{rangeText} {firstOk && firstOk.opening !== null ? finIDR(firstOk.opening) : '—'} {finIDR(t.in)} {finIDR(-t.out)} {finFcSigned(t.in - t.out)} {lastOk && lastOk.closing !== null ? : '—'}
{recv ? ( {recv.invoices ? finFcPlural(recv.invoices, 'invoice') + ' not paid' : 'Every invoice is paid'} as of {finDate(recvAsOf)}. When they will be paid is unknown: the sheet has no due dates. } caption={'By age since the invoice date · over ' + overdueDays + ' days counts as overdue'} action={onNavigate ? : null} segments={(aging || []).map((a) => ({ tone: AGE_TONE[a.key] || 'neutral', n: Number(a.amount) || 0, label: a.label }))} barLabel={(aging || []).map((a) => a.label + ' ' + finIDR(a.amount)).join(', ')} legend={(aging || []).map((a) => ({ id: a.key, label: a.label, tone: AGE_TONE[a.key] || 'neutral', value: a.count ? finIDRCompact(a.amount) : '—', title: finFcPlural(a.count || 0, 'invoice') + ' · ' + finIDR(a.amount) }))} facts={[ overdue ? { id: 'od', label: 'Overdue', tone: overdue.amount ? 'crit' : undefined, value: overdue.amount ? finIDRCompact(overdue.amount) : 'None', title: finFcPlural(overdue.invoices || 0, 'invoice') + ' open over ' + overdueDays + ' days' } : null, payables ? { id: 'pb', label: 'Unpaid vendor bills', value: payables.amount ? finIDRCompact(payables.amount) : 'None', title: 'Expected outflow: ' + finFcPlural(payables.bills || 0, 'bill') + ' not marked PAID' } : null, ].filter(Boolean)} /> ) : !isAll && sel && !sel.available ? null : ( )} {openInv.length ? ( {openInv.map((v) => ( onNavigate && onNavigate('invoices', { q: v.invoiceNo || v.customer }, { p: v.periodKey })} onKeyDown={(e) => { if ((e.key === 'Enter' || e.key === ' ') && onNavigate) { e.preventDefault(); onNavigate('invoices', { q: v.invoiceNo || v.customer }, { p: v.periodKey }); } }}> ))}
Customer Invoice date Age Outstanding Sheet row
{v.invoiceNo || '—'} · {finDate(v.date)}} /> {finDate(v.date)} {finFcPlural(v.ageDays || 0, 'day')}{v.status === 'overdue' ? ' · overdue' : ''} {finIDR(v.outstanding)} e.stopPropagation()}>
) : null} {open ? ( setOpenKey(null)} onSelect={(k) => { setOpenKey(null); setPeriodKey(k); }} onNavigate={onNavigate} /> ) : null}
); } // Whole days from a to b (ISO dates, string maths, no timezone shift). function finFcDays(a, b) { const pa = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(a || '')); const pb = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(b || '')); if (!pa || !pb) return 0; return Math.round((Date.UTC(+pb[1], +pb[2] - 1, +pb[3]) - Date.UTC(+pa[1], +pa[2] - 1, +pa[3])) / 86400000); } Object.assign(window, { FinForecast });