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 30a9df7362
commit 7f2f73a6ab
2 files changed
+210 -14

No files matched your search

+28 -14
View File
@@ -64,9 +64,9 @@ operating = "0.00"
```
Events count from 1: the first `[[events]]` is event 1. An event is an
entry (`lines`), a reversal (`reverses`), a close (`close`, below) or a
bill (`bill`, below), each posting one entry; or one of the books'
commands that post what is due (`run_depreciation`, `dispose_asset`,
entry (`lines`), a reversal (`reverses`), a close (`close`, below), a
bill or an invoice (`bill`, `invoice`, below), each posting one entry;
or one of the books' commands that post what is due (`run_depreciation`, `dispose_asset`,
`run_schedules`, below), which post as many entries as are due, none
included; or a schedule's registration (`register_schedule`), which
posts none: exactly one of them. A key that names an event (`reverses =
@@ -77,10 +77,11 @@ posts one entry, event N's is entry #N. A change that posts no entry (a
rename, a policy) is a `[[changes]]` entry instead (below). A key the
shape doesn't have is refused too, never ignored.
An entry, a reversal, a close, a bill and a disposal are dated (`date`);
the other commands date their own entries (a run its month's end) and
take no date. An entry, a reversal, a close and a bill are described
(`description`); a command describes its own entries and takes none.
An entry, a reversal, a close, a bill, an invoice and a disposal are
dated (`date`); the other commands date their own entries (a run its
month's end) and take no date. An entry, a reversal, a close, a bill and
an invoice are described (`description`); a command describes its own
entries and takes none.
The books are the engine's own (`ledger_store::Store`, in a directory of
their own): each event is the command the books take it by, journaled as
@@ -238,7 +239,8 @@ the side gives the direction.
original's tags.
- `payee` on an event: the payee (by name, one of `setup.payees`) the
entry paid. Only on an entry (`lines`): a reversal takes its
original's, a bill names its vendor, a close and a command have none.
original's, a bill names its vendor, an invoice its customer, a close
and a command have none.
- `parties = [{ party, amount? }, { party, percent? }, ...]` on an event:
the parties (by name, in `setup.parties`) the entry is with, each with
its share: an `amount` (an exact decimal string), a `percent`, or
@@ -258,12 +260,24 @@ the side gives the direction.
splits that close's net on its own instead (books from an engine that
rounded each close by itself). A close must have something to close: it
posts one entry like any other event.
- `bill = { vendor, amount }` as an event: a bill from `vendor` (a name;
a payee's record if one has it) for `amount`, dated and due on the
event's date. It posts one entry: General Expenses (6999) debited and
Accounts Payable (2000) credited, each account created with that fixed
name when first needed, as the books create a control role's account
(B-32).
- `bill = { vendor, amount }` or `bill = { vendor, lines = [{ amount,
description?, project? }, ...] }` as an event: a bill from `vendor` (a
name; a payee's record if one has it) for `amount` (one line, described
as the event) or its `lines` (exactly one of them; a line's description
is the event's when left out), dated and due on the event's date. It
posts one entry: General Expenses (6999) debited and Accounts Payable
(2000) credited, each account created with that fixed name when first
needed, as the books create a control role's account (B-32). A line's
`project` (a `setup.projects` name) puts its cost on that project: the
entry's expense side is one line per project named, the untagged lines'
as one, the payable line never tagged (B-37 item 8).
- `invoice = { customer, amount }` or `invoice = { customer, lines = [...]
}` as an event: an invoice to `customer` (a name, its record added when
first named), as a bill is (the same `lines`), dated and due on the
event's date. It posts one entry: Accounts Receivable (1200) debited and
Revenue (4000) credited, each created with that fixed name when first
needed; a line's `project` puts its revenue on that project, the
receivable line never tagged (B-37 item 8).
- `run_depreciation = { asset, period }` as an event: the asset's run for
`period` (`"YYYY-MM"`), which posts what the schedule says is due
through the month's end and the books don't carry, dated then: a