Every report a CPA expects, laid out the way US small-business books read (QuickBooks as the reference): - Exports: books.export gains general_ledger (by account, running balances, splits), general_journal (the entry-ordered listing, which the CPA package used to mislabel "general ledger"; alias journal), members_equity, and trial_balance as of a date, in xlsx/csv/json, and PDF for all five statements (P&L, balance sheet, cash flow, trial balance, members' equity). books.trial_balance takes as_of. - CPA package: every statement as PDF and XLSX, plus the general ledger and general journal, all for the fiscal year to date. - Layout (ledger-import::report): multi-column statements (Total; Debit/Credit; one column per member plus Total), "$" on subtotals and totals, a rule above every sum (none over an empty section), a double rule under statement totals, zero as 0.00, negatives in parentheses with the closing paren hanging so decimal points align. - Terms: "Net income (loss)"; for a multi-member LLC, "Members' equity", member contributions and distributions named in the cash flow, and the balance sheet splitting retained earnings (the Retained Earnings account plus earnings not yet closed from earlier years) from the fiscal year's net income (loss); the cash flow's "Adjustments to reconcile net income (loss) to net cash from operating activities" and "Net increase (decrease) in cash". - PDF: Inter replaces the typst-assets serif fonts (bundled, SIL OFL 1.1, license in fonts/; from the official v4.1 release), centered title block, column-header row, full-width rules, footer "Accrual basis · Prepared <date> · Journal seq N" with page numbers. Amounts on total rows stay regular weight so bold figures can't leave the decimal column. typst-assets dependency removed. - XLSX: centered title block, header row, Excel accounting formats with "$" attached on sums, general ledger and general journal workbooks. - Config: wanderbooks.toml [[company.members]] (name, share "50%" or "0.5", capital_account; shares must total 100%) and [books] accounting_basis (accrual | cash). - Core: RETAINED_EARNINGS_CODE names the "3999" that period close uses. - Fix: "today" is local time, not UTC; in US evenings UTC is tomorrow, so reports defaulting to "through today" included the next day and footers carried the wrong date. Tests: layout (currency and rule placement, retained earnings vs. this year's net income for a member LLC, footer text); exact template data; deterministic PDFs; config parsing (members, shares, basis); stdio: trial balance as of, February general ledger (beginning 1,004.00, splits, ending 1,003.50), members' equity (contributions 1,000.00, net income 3.50, ending 1,003.50), members' equity PDF, the CPA package's ten files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MtYEaR6M6Ybdhm6X98BWNu
116 lines
3.6 KiB
Typst
116 lines
3.6 KiB
Typst
// A financial statement: P&L, balance sheet, cash flow, trial balance, or
|
|
// members' equity, in US small-business (QuickBooks-style) presentation.
|
|
//
|
|
// Everything arrives as data in sys.inputs.data (JSON), already laid out by
|
|
// ledger-import::report, with amounts already split into exact parts. The
|
|
// template only typesets: no arithmetic happens here, and no label is ever
|
|
// parsed as markup.
|
|
//
|
|
// Shape: { company, title, period, footer, columns: ["Total"] | [...],
|
|
// rows: [{ kind: "section" | "subheading" | "line" | "subtotal"
|
|
// | "total" | "spacer",
|
|
// label, rule (rule above), currency ("$" on amounts),
|
|
// amounts: [null | { digits: "1,234.56", negative }] }] }
|
|
//
|
|
// Amounts: Inter's tabular figures; negatives in parentheses with the
|
|
// closing parenthesis hanging (its width is reserved on every row, so
|
|
// decimal points always line up); "$" attached on subtotals and totals.
|
|
|
|
#let d = json(bytes(sys.inputs.data))
|
|
#let ncols = d.columns.len()
|
|
#let ink = luma(25)
|
|
#let quiet = luma(110)
|
|
#let hair = 0.5pt + luma(160)
|
|
#let firm = 0.6pt + ink
|
|
|
|
#set document(title: d.company + " — " + d.title, author: d.company)
|
|
#set text(font: "Inter", size: 9pt, fill: ink, number-width: "tabular")
|
|
#set page(
|
|
paper: "us-letter",
|
|
margin: (x: 0.75in, top: 0.75in, bottom: 0.75in),
|
|
header: context {
|
|
if counter(page).get().first() > 1 {
|
|
set text(7.5pt, fill: quiet)
|
|
[#d.company · #d.title #h(1fr) #d.period]
|
|
}
|
|
},
|
|
footer: context {
|
|
set text(7.5pt, fill: quiet)
|
|
grid(
|
|
columns: (1fr, auto, 1fr),
|
|
[],
|
|
d.footer,
|
|
align(right)[Page #counter(page).display() of #counter(page).final().first()],
|
|
)
|
|
},
|
|
)
|
|
|
|
#align(center)[
|
|
#text(15pt, fill: luma(45), d.company) \
|
|
#v(4pt)
|
|
#text(10.5pt, weight: "bold", d.title) \
|
|
#v(2pt)
|
|
#d.period
|
|
]
|
|
#v(12pt)
|
|
|
|
#let amount(a, currency) = {
|
|
if a == none { return [] }
|
|
let open = if a.negative { [(] } else { [] }
|
|
let close = if a.negative { [)] } else { hide[)] }
|
|
let sign = if currency [\$] else []
|
|
[#open#sign#a.digits#close]
|
|
}
|
|
|
|
#let full(body, ..args) = table.cell(colspan: ncols + 1, ..args, body)
|
|
|
|
#let row-cells(r) = {
|
|
let bold = r.kind == "subtotal" or r.kind == "total"
|
|
let stroke = if r.rule { (top: if r.kind == "total" { firm } else { hair }) } else { none }
|
|
let label = if r.kind == "line" { pad(left: 1.4em, r.label) } else { r.label }
|
|
let label = if bold { text(weight: "bold", label) } else { label }
|
|
(
|
|
table.cell(stroke: stroke, label),
|
|
..r.amounts.map(a => table.cell(stroke: stroke, amount(a, r.currency))),
|
|
)
|
|
}
|
|
|
|
#table(
|
|
columns: (1fr,) + (8em,) * ncols,
|
|
stroke: none,
|
|
inset: (x: 4pt, y: 3.6pt),
|
|
align: (left + horizon,) + (right + horizon,) * ncols,
|
|
table.header(
|
|
table.cell(stroke: (top: firm, bottom: hair), []),
|
|
..d.columns.map(c => table.cell(
|
|
stroke: (top: firm, bottom: hair),
|
|
text(7.5pt, weight: "bold", tracking: 0.04em, upper(c)),
|
|
)),
|
|
),
|
|
..d
|
|
.rows
|
|
.map(r => {
|
|
if r.kind == "spacer" {
|
|
(full(v(2pt), inset: 2pt),)
|
|
} else if r.kind == "section" {
|
|
(full(text(weight: "semibold", r.label)),)
|
|
} else if r.kind == "subheading" {
|
|
(full(pad(left: 1.4em, emph(r.label))),)
|
|
} else if r.kind == "total" {
|
|
// The double rule under a statement total, full width.
|
|
let double = full(
|
|
inset: (x: 0pt, y: 0pt),
|
|
stack(
|
|
spacing: 1.6pt,
|
|
line(length: 100%, stroke: firm),
|
|
line(length: 100%, stroke: firm),
|
|
),
|
|
)
|
|
row-cells(r) + (double,)
|
|
} else {
|
|
row-cells(r)
|
|
}
|
|
})
|
|
.flatten(),
|
|
)
|