feat: invoices and bills take a project, line by line (B-37 item 8)

A client project's invoiced revenue and a contractor's billed cost could
never count toward the project: books.create_invoice and books.create_bill
posted at once with untagged lines, and only a draft's line takes a class.
Job costing (B-37 item 3) collects a job's billings and the supplier
invoices for its direct costs on its cost sheet, so each document line
now takes an optional project.

The owner decided it on 2026-10-22 (plan D-43, rules.md B-37 item 8):
each line takes one project or none; a document spanning N projects is N
lines, each with its own amount; no percentage split, so every figure is
exact; a cost truly shared among projects names none on the document
and reaches projects only as entries of their own under the company's
monthly allocation convention, when books.conventions has one (otherwise
it stays untagged and the agent asks the human). The reasoning, stated
in B-37: job costing charges a job the costs traceable to it, whole, and
reaches shared costs only by allocation on a stated basis. ASC
340-40-25-7 counts as directly related both the costs traceable to a
contract (25-7(a), (b), (d), (e)) and allocations of costs that relate
directly to it (25-7(c)); 25-8 expenses general and administrative cost.
The books carry the first whole on the document's line and the second as
the allocation convention's own entries; neither is a percentage on the
document (sources/fasb-asc.md, 25-7 and 25-8 added). The handbook's
projects rule and the line's class parameter say the same, and no
handbook sentence lets a shared cost be split across a document's lines.

The accounting: the document's entry posts one revenue (an invoice's) or
expense (a bill's) line per project its lines name, in the order each is
first named, each the sum of that project's lines, and the untagged
lines' sum as one more line (arap::document_parts, conservation checked
by a proptest). A document naming no project therefore posts exactly the
one line every document posted before. The receivable or payable line is
never tagged: it is a balance-sheet line, which item 3 counts nothing;
the payments (receive_payment, pay_bill) move cash against it and take no
project either. Nothing but the projects moves: the P&L, the 1099
worksheet (payments made, B-19) and party totals (what moved the money,
B-35) read the same with or without the tags (twin-books test); the
projects with the untagged lines still partition the P&L.

- ledger-core: DocumentLine.class_id (serde-omitted when none, so old
  documents serialize as before); create_invoice / create_bill split the
  revenue or expense side by project and tag it; an unknown project is
  refused whole (atomically).
- ledger-store: a document line's project is journaled as class_id on
  invoice.created / bill.created, and the entry's line as
  entry.line_class_set right after its entry.line_added (the entry.posted
  lines carry class_id, as a hand-built entry's do). Behind a NEW journal
  feature, document_line_projects (KNOWN_FEATURES, declared by new books,
  asked for before the first journaled line, not even the control
  accounts written on refusal); not `projects`, which the live books
  already declared: the owner consents again at the next upgrade. A
  malformed class_id is corrupt; null or absent is none. Untagged
  documents journal byte for byte as before; old journals replay
  unchanged.
- ledger-mcp: each line takes class (id or name, resolved like
  add_line's, every one before anything is written); the result gains
  notes for a finished or abandoned project, and on an invoice for an
  on-spec project (is there now an agreement? on spec a hoped-for
  payment is no receivable, B-37 item 4), tagged anyway; books lacking
  the feature refuse with format_upgrade_pending. books.get_entry shows a
  line's class_id and project. The handbook's "an invoice or bill takes no
  project yet" caveat now depends on the books: gone where the feature is
  declared, an "until their format upgrade" note where it isn't.
- ledger-gui: an invoice's or bill's page (its entry's) lists the
  document's lines, each project a link that opens it; the demo's client
  invoices are tagged to "Client work", whose snapshot is now its revenue
  less its contractors. Looking at the page in a narrow window found a
  tagged line's tag pushing the amounts past the pane (any tagged entry):
  the name is now cut to leave the tag room, the tag itself at most half
  the cell.
- bookspec: an `invoice` event, and `lines` with `project` on a bill or
  an invoice; example projects-invoice-and-bill-lines-count-by-project,
  worked by hand, both projects client work (Zeta 3,500.00 - 1,200.00 =
  2,300.00; Harbor 200.00;
  untagged -1,750.00; together the P&L's 750.00; Dana's 1099 payments
  1,250.00).
- fuzz: fuzz_store_replay can declare journal features.
- Tests: core, store, MCP, viewer, the P2-served cutover fixture and a
  viewer/server parity test (its month lists the same length, not
  empty); a tagged document's reversal nets its projects to zero, live
  and replayed; books.get_entry's class_id; the handbook served as a
  resource both ways; each fix broken to confirm its test fails
  (docs/testing.md). Docs: rules.md B-27 and B-37 items 3 and 8,
  sources/fasb-asc.md, plan/served.md D-43,
  mcp-interface.md, testing.md, parity.md, plan/STATUS.md.

No proof changed (no kernel arithmetic: document_parts sums with the
existing document_total).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-10-22 19:28:40 -06:00
1 parent e19df28bf2
commit 528c070605
51 files changed
+3201 -166

No files matched your search

+45 -19
View File
@@ -505,7 +505,9 @@ every tool over every book in ledger-store's `tests/fixtures/old-books`.
schedule); and a reversal of a depreciation run or a schedule month's
posting (or of a reversal in its chain) dated before that entry's own
date (a correction comes after what it corrects, B-9).
- `books.get_entry { entry_id }` → full entry with lines, receipts, and
- `books.get_entry { entry_id }` → full entry with lines (each `{
account_id, code, name, side, amount, class_id?, project? }`: a tagged
line's project, its id and name), receipts, and
its `vendor`, `party_id`, and `party` (the party's label, when it names
exactly one) tags, `parties` / `parties_error` as in the `post_entry`
preview, and `no_party_reason` when it is marked as having no
@@ -1980,19 +1982,46 @@ accounting only: the caller supplies every figure), tax filing.
- `books.add_vendor { name }` → `{ id, party_id }`. Both link the record to
a party ("Tools — parties").
- `books.create_invoice { party_id, date, due_date, lines: [{ description,
amount }] }` → `{ id, total, entry_id, warnings? }`. Auto-posts Dr
`1200` Accounts Receivable / Cr `4000` Revenue. `warnings` names a
revenue account it created with no tax category (rules.md B-32).
`party_id` is the customer's `id` from `books.add_customer`, not its
`party_id`.
amount, class? }] }` → `{ id, total, entry_id, warnings?, notes? }`.
Auto-posts Dr `1200` Accounts Receivable / Cr `4000` Revenue. `warnings`
names a revenue account it created with no tax category (rules.md
B-32). `party_id` is the customer's `id` from `books.add_customer`, not
its `party_id`. A line's `class` (a project: name or id, resolved as
`books.add_line`'s) puts its revenue on that project (rules.md B-37 item
8, the owner's decision D-43): one project or none per line, several
projects as several lines each with its own amount, never a percentage
(a cost truly shared names none: it reaches the projects only as
entries of their own under the company's monthly allocation convention,
when `books.conventions` has one, and otherwise stays untagged while the
agent asks the human). The entry's revenue side is one line per project named, in the
order each is first named, the untagged lines' as one (a document
naming none posts the one revenue line it always did); the receivable
line is never tagged. Every project is resolved before anything is
written (an unknown one is refused, the document whole). `notes`: one
per finished or abandoned project named, as `books.add_line`'s `note`,
and one per on-spec project named, asking whether there is now an
agreement (on spec, a hoped-for payment is no receivable until
received: B-37 item 4) (tagged anyway). Books that haven't declared the journal feature
`document_line_projects` (B-27; the live books until their owner's next
upgrade, D-39) refuse a line naming a project with
`format_upgrade_pending`, journaling nothing; a document naming none is
taken as before.
- `books.create_bill { party_id, date, due_date, lines }` → `{ id, total,
entry_id, warnings? }`. Auto-posts Dr `6999` General Expenses / Cr
`2000` Accounts Payable; `warnings` as for invoices. `party_id` is the
vendor's `id` from `books.add_vendor`, not its `party_id`.
entry_id, warnings?, notes? }`. Auto-posts Dr `6999` General Expenses /
Cr `2000` Accounts Payable; `warnings` as for invoices. `party_id` is
the vendor's `id` from `books.add_vendor`, not its `party_id`. A line's
`class` puts its cost on that project, as an invoice's its revenue: one
expense line per project, the untagged lines' as one, the payable line
never tagged; `notes` as for invoices, but none for an on-spec project
(a cost of on-spec work is an expense like any other); the feature as
for invoices.
- `books.receive_payment { document_id, date, amount, cash_account }` →
`{ entry_id, remaining, status }`. Posts Dr Cash / Cr A/R.
`{ entry_id, remaining, status }`. Posts Dr Cash / Cr A/R, neither line
tagged with a project (balance-sheet only: the invoice's lines carry
its projects).
- `books.pay_bill { document_id, date, amount, cash_account }` →
`{ entry_id, remaining, status }`. Posts Dr A/P / Cr Cash.
`{ entry_id, remaining, status }`. Posts Dr A/P / Cr Cash, neither line
tagged with a project.
- `books.ar_aging { as_of? }` → `{ as_of, rows: [{ name, current, days_30,
days_60, days_90, days_90_plus, total }] }` (`as_of` omitted: today).
- `books.ap_aging { as_of? }` → same, per vendor (`as_of` omitted: today).
@@ -2121,14 +2150,11 @@ until the owner upgrades them.
- `books.record_payout` lines and adjustments take optional `class` (a
project); its result gains `notes`, one per finished or abandoned
project tagged, as `books.add_line`'s `note`.
- An invoice or a bill takes no project yet: `books.create_invoice` and
`books.create_bill` post their entry at once with untagged lines, and
only a draft's lines take a class (`books.add_line`'s `class`). Link the document to the
project (`books.link_attachment` subject kind `project`); when its lines
must count in the project's figures, book it as a hand-built entry
(`books.draft_entry` + `books.add_line` class) instead, which then is
no invoice or bill in the agings (an open item: tagged document
lines).
- An invoice's or bill's lines take a project too (`books.create_invoice`
and `books.create_bill`, `class` on a line, rules.md B-37 item 8), in
books that declared the journal feature `document_line_projects`; the
handbook's projects section says which these books are. Their payments
take none.
- `books.profit_and_loss_by_class { start?, end?, class? }` (omitted dates:
the fiscal year to date, as every period report) → per-class revenue,
expenses, net income, plus an unclassified row (only that class's row