// FRAZIER Finance OS — Books: Journal + Bank Book (master sheet, 8 Oct 2026). // // READ-ONLY. Both pages show the selected calendar month (useFinPeriod) // straight from the finance sheet (useFinSheet → fin_sheet_dashboard, // CONTRACT §2.2 `journal` and `bank`). One sheet covers every date. There // is no in-app input: every row links to its cell in the sheet. // Live updates swap the payload in place; search and filters stay. // // Bank Book: opening (the sheet's opening row + its rows before the 1st) // with the continuity check against the previous month, the rows // with the app's running balance (a badge where the sheet's own Balance // column differs or errors), in / out / net, closing "as of" the last entry. // Journal: the JV tab's lines of the period, grouped by day (each day header // carries the day's debit = credit check), filters, totals check. // // Never a row of zeros: a missing tab shows its reason, a month with no // dated rows its empty state, each with a link to the sheet. // Page-scoped names carry the finLed / FinLed / FIN_LED prefix. function finLedPlural(n, one, many) { return n + ' ' + (n === 1 ? one : (many || one + 's')); } // Hint fragments joined with " · "; a fragment never breaks inside. function FinLedHint({ parts }) { const list = (parts || []).filter(Boolean); return <>{list.map((p, i) => {i ? ' · ' : null}{p})}; } const FIN_LED_WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; function finLedWeekday(iso) { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? FIN_LED_WD[new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])).getUTCDay()] : ''; } // Every search term must appear somewhere in the haystack. function finLedMatch(hay, q) { const s = String(q || '').trim().toLowerCase(); if (!s) return true; const h = hay.filter((x) => x !== null && x !== undefined && x !== '').join(' ').toLowerCase(); return s.split(/\s+/).every((t) => h.indexOf(t) !== -1); } // Seeds the search from Jump to… (args.q) once per navigation. function useFinLedSeed(args, setQ) { React.useEffect(() => { if (args && args.q) setQ(String(args.q)); }, [args && args.nonce, args && args.q]); // eslint-disable-line } // Narrow tables (640 to 899px) fold the two money columns into one // "Amount" cell: each non-zero side on its own line with its label. function FinLedAmt({ items }) { const list = (items || []).filter((x) => Number(x.v)); if (!list.length) return —; return {list.map((x) => ( {x.l}{finIDR(x.v)} ))}; } // ── Shared states ────────────────────────────────────────────────────── // The sheet was read, but this tab is missing from it. function FinLedNoTab({ meta, section, icon, title }) { const href = (section && section.link) || (meta && meta.sheet && meta.sheet.url) || null; return ( : null} /> ); } // Server-written sentences may carry ISO dates ("through 2026-10-25"): show // them the way every other date on the page reads ("25 Oct 2026"). function finLedDates(text) { return String(text === null || text === undefined ? '' : text).replace(/\b(\d{4}-\d{2}-\d{2})\b/g, (m) => finDate(m)); } // Several years in one sheet: a later year row (Bank Book G, JV F / G) the // server compared with the balance carried from the year before and found // different (check year_opening_mismatch, about the whole sheet). Shown as // an alert on the January of that year, with both rows linked; the page // keeps its own running balance. The year comes from the check's message // ("Year row 2026 …"); without it the check stays in the list below only. function finLedYearRowChecks(period, tab) { if (!period || !/-01$/.test(String(period.key || ''))) return []; const y = String(period.key).slice(0, 4); return (period.checks || []).filter((c) => c.code === 'year_opening_mismatch' && c.tab === tab && (/Year row (\d{4})/.exec(String(c.message || '')) || [])[1] === y); } function FinLedYearRowAlert({ period, tab }) { const list = finLedYearRowChecks(period, tab); if (!list.length) return null; const y = String(period.key).slice(0, 4); return ( <> {list.map((c) => ( The sheet’s {y} year row doesn’t match the balance carried from {Number(y) - 1}.{' '} {finLedDates(c.message)} ))} ); } // Data checks for one tab (+ reconciliation notes), each linked to its cell. const FIN_LED_CHECKS_MAX = 6; function FinLedChecks({ items, title, sub }) { const [all, setAll] = React.useState(false); if (!items || !items.length) return null; const warn = items.filter((c) => c.level === 'warn').length; const shown = all ? items : items.slice(0, FIN_LED_CHECKS_MAX); return ( {items.length > FIN_LED_CHECKS_MAX ? ( ) : null} ); } // period.checks of one tab, warnings first (the payload already sorts them). function finLedTabChecks(period, tab, recoKeys) { const own = (period.checks || []).filter((c) => c.tab === tab); const reco = (period.reconciliation || []).filter((r) => recoKeys.indexOf(r.key) !== -1).map((r) => ({ id: 'reco:' + r.key, level: r.level === 'warn' ? 'warn' : 'info', title: r.title, message: r.message, link: (r.links && (r.links[tab] || r.links.jv || r.links.bank)) || null, })); return reco.concat(own).sort((a, b) => (a.level === 'warn' ? 0 : 1) - (b.level === 'warn' ? 0 : 1)); } // ════════════════════════════════════════════════════════════════════════ // Journal // ════════════════════════════════════════════════════════════════════════ const FIN_LED_KINDS = [ { id: 'voucher', label: 'Vouchers', tone: 'info', title: 'Numbered vouchers (JV.001 …)' }, { id: 'bank', label: 'Bank', tone: 'violet', title: 'Lines typed "Bank"' }, { id: 'jv', label: 'JV', tone: 'neutral', title: 'Lines typed "JV"' }, { id: 'other', label: 'Other', tone: 'warn', title: 'Any other type' }, ]; function finLedKind(id) { return FIN_LED_KINDS.find((k) => k.id === id) || FIN_LED_KINDS[3]; } function FinJournal({ args }) { const { data, meta } = useFinSheet(); const { period, periodKey } = useFinPeriod(); const [q, setQ] = React.useState(''); const [kind, setKind] = React.useState('all'); const [acct, setAcct] = React.useState('all'); const [onlyOff, setOnlyOff] = React.useState(false); useFinLedSeed(args, setQ); // A new month has other accounts and days: drop the month-bound filters. React.useEffect(() => { setAcct('all'); setOnlyOff(false); setKind('all'); }, [periodKey]); const ok = !!period; const j = ok && period.journal && period.journal.available !== false ? period.journal : null; const lines = React.useMemo(() => { const ls = (j && j.lines) || []; return ls.map((l, i) => ({ l, i })).sort((a, b) => (a.l.date < b.l.date ? -1 : a.l.date > b.l.date ? 1 : (a.l.row || 0) - (b.l.row || 0) || a.i - b.i)).map((x) => x.l); }, [j]); const dayCheck = React.useMemo(() => { const m = {}; ((j && j.dayChecks) || []).forEach((d) => { m[d.date] = d; }); return m; }, [j]); const offDays = ((j && j.dayChecks) || []).filter((d) => !d.balanced); const offVouchers = ((j && j.voucherChecks) || []).filter((v) => !v.balanced); const acctOpts = React.useMemo(() => { const m = {}; lines.forEach((l) => { if (!m[l.coa]) m[l.coa] = { code: l.coa, name: l.coaName, n: 0 }; m[l.coa].n += 1; }); const list = Object.keys(m).sort().map((k) => ({ value: k, label: (k || '—') + ' · ' + (m[k].name || 'Unknown account') + ' (' + m[k].n + ')' })); return [{ value: 'all', label: 'All accounts' }].concat(list); }, [lines]); const scope = React.useMemo(() => lines.filter((l) => (acct === 'all' || l.coa === acct) && (!onlyOff || (dayCheck[l.date] && !dayCheck[l.date].balanced)) && finLedMatch([l.coa, l.coaName, l.ref, l.description, l.type, l.voucher, finDate(l.date)], q)), [lines, acct, onlyOff, dayCheck, q]); const visible = kind === 'all' ? scope : scope.filter((l) => l.kind === kind); const counts = {}; const allCounts = {}; scope.forEach((l) => { counts[l.kind] = (counts[l.kind] || 0) + 1; }); lines.forEach((l) => { allCounts[l.kind] = (allCounts[l.kind] || 0) + 1; }); const filtered = !!q.trim() || kind !== 'all' || acct !== 'all' || onlyOff; const clearAll = () => { setQ(''); setKind('all'); setAcct('all'); setOnlyOff(false); }; // Day groups of the visible lines. const days = React.useMemo(() => { const out = []; let cur = null; visible.forEach((l) => { if (!cur || cur.date !== l.date) { cur = { date: l.date, lines: [], debit: 0, credit: 0 }; out.push(cur); } cur.lines.push(l); cur.debit += Number(l.debit) || 0; cur.credit += Number(l.credit) || 0; }); return out; }, [visible]); const visDr = visible.reduce((s, l) => s + (Number(l.debit) || 0), 0); const visCr = visible.reduce((s, l) => s + (Number(l.credit) || 0), 0); const T = (j && j.totals) || { lines: 0, debit: 0, credit: 0, diff: 0, balanced: true, unbalancedDays: 0 }; const dayN = ((j && j.dayChecks) || []).length; const tabName = ok && period.tabs && period.tabs.jv && period.tabs.jv.name; const exportCsv = () => { finDownloadCsv(finCsvName('journal', period.key), ['Date', 'Sheet row', 'Type', 'Account code', 'Account name', 'Ref', 'Description', 'Debit', 'Credit'], visible.map((l) => [l.date, l.row, l.type || '', l.coa || '', l.coaName || '', l.ref || '', l.description || '', Number(l.debit) || 0, Number(l.credit) || 0])); }; const balancePill = (balanced, diff, sm) => (balanced ? Balanced : Out by {finIDR(Math.abs(diff))}); const head = ( : null} actions={ok ? <> {j && lines.length ? ( ) : null} : null} /> ); if (!period) return
{head}
; if (!j) return
{head}
; // No row of any tab is dated in this month: one empty state, no zeros. if (period.hasData === false) { return
{head}
; } const legend = FIN_LED_KINDS.filter((k) => allCounts[k.id] || kind === k.id).map((k) => ({ id: k.id, label: k.label, n: counts[k.id] || 0, tone: k.tone, title: k.title, on: kind === k.id, disabled: !(counts[k.id] || 0) && kind !== k.id, onClick: () => setKind((v) => (v === k.id ? 'all' : k.id)), })); // The sheet's own "no opening balances" check already says it; no reco duplicate. const checks = finLedTabChecks(period, 'jv', []); return (
{head} {lines.length ? ( {filtered ? : null} ) : null} {offDays.length || offVouchers.length ? ( setOnlyOff((v) => !v)}> {onlyOff ? 'Show all days' : 'Show only these days'} ) : null}> {offDays.length ? <>{finLedPlural(offDays.length, 'day doesn’t', 'days don’t')} balance: {offDays.map((d, i) => ( {i ? ', ' : ''}{finDate(d.date, { year: false })} out by {finIDR(Math.abs(d.diff))} ))}. : null} {offVouchers.length ? <>{offDays.length ? ' ' : ''}{finLedPlural(offVouchers.length, 'voucher')} out of balance: {offVouchers.map((v, i) => ( {i ? ', ' : ''}{v.voucher} by {finIDR(Math.abs(v.diff))} ))}. : null} ) : null} {/* No lines: no "Lines by type" bar at all (an empty grey track reads as a broken chart). Filters matching nothing: the chips stay (one may be the active filter), the empty bar hides (CSS). */} : 'No journal lines dated in ' + period.label} caption={lines.length ? 'Lines by type' + (filtered && kind === 'all' ? ' · matching filters' : '') : undefined} segments={lines.length ? FIN_LED_KINDS.map((k) => ({ tone: k.tone, n: counts[k.id] || 0, label: k.label })) : undefined} legend={lines.length ? legend : []} facts={lines.length ? undefined : [{ id: 'types', label: 'Lines by type', value: No lines this month }]} /> {visible.length ? ( {days.map((d) => { const dc = dayCheck[d.date]; const off = dc && !dc.balanced; return ( {d.lines.map((l) => { const dr = Number(l.debit) || 0; const cr = Number(l.credit) || 0; const isCr = !dr && cr; const k = finLedKind(l.kind); return ( ); })} ); })}
Account Description · type · ref Debit Credit Amount Open in Google Sheets
{finDate(d.date)} {finLedWeekday(d.date)}{dc ? ' · ' + finLedPlural(dc.lines, 'line') : ''} {dc ? {balancePill(dc.balanced, dc.diff, true)} : null}
{filtered || !dc ? null : finIDR(dc.debit)} {filtered || !dc ? null : finIDR(dc.credit)} {dc ? : null}
{l.coaName || 'Unknown account'} {l.coa || '—'}{l.coaKnown === false ? Not in COA : null}
{l.description || '—'}
{dr ? finIDR(dr) : —} {cr ? finIDR(cr) : —}
{filtered ? 'Shown · ' + finLedPlural(visible.length, 'line') : 'Total · ' + finLedPlural(T.lines, 'line')} {filtered ? Filtered: the month check is above : balancePill(T.balanced, T.diff)}
{finIDR(filtered ? visDr : T.debit)} {finIDR(filtered ? visCr : T.credit)} Dr{finIDR(filtered ? visDr : T.debit)} Cr{finIDR(filtered ? visCr : T.credit)}
) : lines.length ? ( Clear filters} /> ) : ( } /> )}
); } // ════════════════════════════════════════════════════════════════════════ // Bank Book // ════════════════════════════════════════════════════════════════════════ function finLedBalFlag(r) { if (r.sheetBalanceError) return { tone: 'warn', text: 'Sheet: ' + r.sheetBalanceError, title: 'The sheet’s Balance cell shows ' + r.sheetBalanceError + '; the balance here is computed by the dashboard.' }; if (r.balanceMismatch) return { tone: 'crit', text: 'Sheet: ' + finIDR(r.sheetBalance), title: 'The sheet’s Balance column says ' + finIDR(r.sheetBalance) + '; the running balance computed from Cash In / Cash Out is ' + finIDR(r.balance) + '.' }; return null; } function FinBankBook({ args }) { const { meta } = useFinSheet(); const { period, periodKey, periods } = useFinPeriod(); const [q, setQ] = React.useState(''); const [flow, setFlow] = React.useState('all'); useFinLedSeed(args, setQ); React.useEffect(() => { setFlow('all'); }, [periodKey]); const ok = !!period; const b = ok && period.bank && period.bank.available !== false ? period.bank : null; const rows = (b && b.rows) || []; const flagged = rows.filter((r) => finLedBalFlag(r)); const scope = rows.filter((r) => finLedMatch([r.description, r.keterangan, r.ketRek, finDate(r.date), r.in ? String(r.in) : '', r.out ? String(r.out) : ''], q)); const visible = flow === 'all' ? scope : scope.filter((r) => (flow === 'in' ? r.in > 0 : flow === 'out' ? r.out > 0 : !!finLedBalFlag(r))); const filtered = !!q.trim() || flow !== 'all'; const clearAll = () => { setQ(''); setFlow('all'); }; const tabName = ok && period.tabs && period.tabs.bank && period.tabs.bank.name; const head = ( : null} actions={ok ? <> {b ? ( ) : null} : null} /> ); if (!period) return
{head}
; if (!b) return
{head}
; const O = b.opening || {}; const T = b.totals || { in: 0, out: 0, net: 0, entries: 0, inEntries: 0, outEntries: 0, inJournal: 0, balanceMismatches: 0 }; const cash = b.cash || {}; const prev = O.previousPeriodKey ? (periods || []).find((p) => p.key === O.previousPeriodKey) : null; const prevLabel = prev ? prev.label : (O.previousPeriodKey ? finMonthLabel(O.previousPeriodKey) : null); // Closing is known up to the last Bank Book entry; past that it is "as of". const asOfDate = (period.asOf && period.asOf.date) || period.end; const known = b.knownThrough || cash.asOf || null; const knownShort = known && asOfDate && known < asOfDate; const closingLabel = period.isCurrent ? 'Balance now' : 'Closing balance'; // Money in / out / net of the month are UNKNOWN (not zero) when the Bank // Book's last entry is before the month starts: same rule and words as // Home (finHomeBankState) and Calendar. const flowKnown = !!(known && known >= period.start); const flowReason = known ? 'No Bank Book entries since ' + finDate(known) : 'No Bank Book entries yet'; const through = flowKnown && knownShort ? 'through ' + finDate(known, { year: false }) : null; const dash = —; // The hint form keeps the date in one piece ("1 Feb 2026" never splits). const flowReasonHint = known ? <>No Bank Book entries since {finDate(known)} : flowReason; const flowHint = (n, none) => (!flowKnown ? flowReasonHint : n ? : none); const contFact = O.continuity === 'match' ? Matches {prev ? finMonthShort(prev.key) : 'previous'} : O.continuity === 'mismatch' ? Off by {finIDR(Math.abs(O.continuityDiff || 0))} : O.continuity === 'gap' ? Gap before : First month; // Several years in one sheet: the starting balance is the FIRST year row // (e.g. 2025); a month of a later year names that year so the opening // never reads as this year's row. const oy = O.markerFound && O.markerYear && String(O.markerYear) !== String(period.key).slice(0, 4) ? String(O.markerYear) : null; const beforeDate = finDate(period.start, oy ? undefined : { year: false }); const openingSub = O.markerFound ? (oy ? oy + ' year row ' + (O.markerRow || '') + (O.markerTabName ? ' of “' + O.markerTabName + '”' : '') : 'Sheet opening row ' + (O.markerRow || '')) + ' (' + finIDR(O.markerAmount) + ')' + (O.entriesBefore ? ' + ' + finLedPlural(O.entriesBefore, 'entry', 'entries') + ' before ' + beforeDate + ' (' + (O.movementBefore > 0 ? '+' : '') + finIDR(O.movementBefore) + ')' : '') : 'No opening row in the sheet: starts from Rp 0' + (O.entriesBefore ? ' + ' + finLedPlural(O.entriesBefore, 'entry', 'entries') + ' before ' + beforeDate : ''); // Same derivation in two short pieces that wrap between them (the full // sentence stays in the tooltip and the CSV). const openingParts = [ O.markerFound ? (oy ? oy + ' year row' : 'Sheet row ' + (O.markerRow || '')) + ' (' + finIDR(O.markerAmount) + ')' : 'No opening row: from Rp 0', O.entriesBefore ? '+ ' + finLedPlural(O.entriesBefore, 'earlier entry', 'earlier entries') + (O.markerFound ? ' (' + (O.movementBefore > 0 ? '+' : '') + finIDR(O.movementBefore) + ')' : '') : null, ].filter(Boolean); const sumIn = filtered ? visible.reduce((s, r) => s + (Number(r.in) || 0), 0) : T.in; const sumOut = filtered ? visible.reduce((s, r) => s + (Number(r.out) || 0), 0) : T.out; function exportCsv() { const out = [[period.start, O.markerRow || '', 'Opening balance', openingSub, '', '', '', O.amount, '', '']]; visible.forEach((r) => { const f = finLedBalFlag(r); out.push([r.date, r.row, r.description || '', r.keterangan || '', r.ketRek || '', r.in || 0, r.out || 0, r.balance, r.sheetBalanceError || (r.sheetBalance !== null && r.sheetBalance !== undefined ? r.sheetBalance : ''), f ? f.text : '']); }); finDownloadCsv(finCsvName('bank-book', period.key), ['Date', 'Sheet row', 'Description', 'Keterangan', 'Ket. Rek', 'Cash in', 'Cash out', 'Balance (computed)', 'Balance (sheet)', 'Flag'], out); } const flowOpts = [ { value: 'all', label: 'All' }, { value: 'in', label: 'Money in', disabled: !T.inEntries }, { value: 'out', label: 'Money out', disabled: !T.outEntries }, ].concat(flagged.length ? [{ value: 'flag', label: 'Flagged (' + flagged.length + ')' }] : []); // How many of the month's entries the JV tab has: a reconciliation fact, // so it sits with the checks (not under Net change). const jvNote = T.entries ? [{ id: 'led:bank-in-jv', level: 'info', title: 'Bank Book entries in the JV tab', message: T.inJournal === T.entries ? 'All ' + finLedPlural(T.entries, 'entry', 'entries') + ' of this month are found in the JV tab.' : T.inJournal + ' of ' + finLedPlural(T.entries, 'entry', 'entries') + ' of this month are found in the JV tab' + (T.inJournal ? '.' : ': none are booked there yet.'), link: (period.tabs && period.tabs.jv && period.tabs.jv.url) || null, linkLabel: 'Open JV tab', }] : []; const checks = finLedTabChecks(period, 'bank', ['cash_bank_vs_jv']).concat(jvNote) .sort((a, b2) => (a.level === 'warn' ? 0 : 1) - (b2.level === 'warn' ? 0 : 1)); return (
{head} {O.continuity === 'mismatch' ? ( : null}> This month opens at {finIDR(O.amount)}, but {prevLabel} closed at {finIDR(O.previousClosing)} (difference {finIDR(O.continuityDiff)}). Check the Bank Book rows around {finDate(period.start)} and its opening row. ) : null} } caption={'Opening · ' + period.rangeLabel} facts={[ { id: 'open', label: 'Opening balance', value: finIDR(O.amount), title: openingSub }, { id: 'from', label: 'Opens on', value: finDate(period.start) }, { id: 'cont', label: prevLabel ? 'vs ' + prevLabel : 'Continuity', value: contFact }, ]} /> : flowReasonHint} /> {flagged.length ? ( setFlow((v) => (v === 'flag' ? 'all' : 'flag'))}>{flow === 'flag' ? 'Show all rows' : 'Show flagged rows'}}> {finLedPlural(flagged.length, 'row')} where the sheet’s own Balance column differs from the running balance (or shows an error). The balances here are computed from Cash In and Cash Out. ) : null} {rows.length ? ( {filtered ? : null} ) : null} {visible.map((r) => { const f = finLedBalFlag(r); const sub = [r.keterangan, r.ketRek].filter(Boolean).join(' · '); return ( ); })} {!visible.length ? ( ) : null}
Date Description · keterangan In Out Amount Balance Open in Google Sheets
{finDate(period.start)}Start
Opening balance{openingParts.map((p) => {p})}
— — —
{finIDR(O.amount)}{contFact}
{O.link ? : null}
{finDate(r.date)} Row {r.row}{r.tabName && tabName && r.tabName !== tabName ? ' · ' + r.tabName : ''}
{r.description || '—'} {sub || 'No keterangan'} {r.dateInherited ? Date from row above : null} {r.hiddenInSheet ? Hidden in sheet : null}
{r.in ? finIDR(r.in) : —} {r.out ? finIDR(r.out) : —}
{finIDR(r.balance)} {f ? {f.text} : null}
{rows.length ? Clear filters} /> : } />}
{filtered ? 'Shown · ' + finLedPlural(visible.length, 'entry', 'entries') : 'Total · ' + finLedPlural(T.entries, 'entry', 'entries')} {flowKnown ? finIDR(sumIn) : dash} {flowKnown ? finIDR(sumOut) : dash} In{flowKnown ? finIDR(sumIn) : dash} Out{flowKnown ? finIDR(sumOut) : dash} {finIDR(b.closing)}
Net · in minus out{filtered ? ' (whole month)' : ''} {flowKnown ? (T.net > 0 ? '+' : '') + finIDR(T.net) : dash} {flowKnown ? (T.net > 0 ? '+' : '') + finIDR(T.net) : dash} {known ? 'as of ' + finDate(known) : ''}
); } Object.assign(window, { FinJournal, FinBankBook });