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

@@ -0,0 +1,182 @@
# An invoice's or bill's lines count toward the projects they name.
#
# wanderbooks: rules.md B-37 item 8 (journal feature
# `document_line_projects`); regression tests in ledger-core
# `tests/spec_document_projects.rs`, ledger-store
# `tests/document_projects.rs`, ledger-mcp `tests/spec_projects.rs`
# (`invoice_and_bill_lines_count_toward_their_projects`).
#
# Expected values worked by hand. Invoice 1 bills 3,000.00 + 500.00 of
# Zeta's design (3,500.00), 200.00 of Harbor's hosting and an untagged
# 100.00 rush fee: 3,800.00, all Revenue (4000), the receivable untagged.
# Bill 1 is 1,200.00 of Zeta's illustration and 50.00 of untagged
# postage: 1,250.00 of General Expenses (6999). Bill 2, 300.00, names no
# project. The customer's payment and the bill's payment move cash and
# the receivable or payable only: no project figure. So Zeta nets
# 3,500.00 - 1,200.00 = 2,300.00; Harbor 200.00 (both are client work,
# so neither has an unrecovered cost: on spec, a hoped-for payment is no
# receivable, B-37 item 4); the untagged lines 100.00 - 50.00 - 300.00
# - 1,500.00 (rent) = -1,750.00; together 750.00, the P&L's net
# (3,800.00 - 1,550.00 - 1,500.00). Dana was paid 1,250.00 from the bank,
# whatever the bill's projects; the second bill is still owed.
id = "projects-invoice-and-bill-lines-count-by-project"
title = "An invoice's or bill's lines count toward the projects they name"
rule = "Each line of an invoice or bill MAY name a project; its revenue (an invoice's) or cost (a bill's) MUST then count toward that project's figures exactly as a tagged line of a hand-built entry would, the receivable, the payable and their payments MUST count toward none, and every figure that is not a project's (the P&L, a payee's 1099 payments) MUST be what it would be with no project named."
status = "CONVENTION"
sources = [
"Job-order costing: a job cost sheet accumulates the revenue and the direct costs identified with one job, a supplier's invoice and the job's billing among them (management-accounting convention; wanderbooks docs/spec/rules.md B-37 items 3 and 8)",
"wanderbooks docs/spec/rules.md B-11 and B-14: a period's net income is its revenue less its expenses",
"Treas. Reg. §1.6041-1(a)(1)(iv) (docs/spec/sources/irs-1099-payment-method.md): a 1099 counts payments made, not how the books classify them",
]
tags = ["projects", "classes", "job-costing", "accrual", "invoices", "bills"]
[setup]
currency = "USD"
fiscal_year_start = "01-01"
basis = "accrual"
rounding = "half-even"
cash_accounts = ["1000"]
[[setup.accounts]]
code = "1000"
name = "Bank"
type = "asset"
[[setup.accounts]]
code = "1200"
name = "Accounts Receivable"
type = "asset"
[[setup.accounts]]
code = "2000"
name = "Accounts Payable"
type = "liability"
[[setup.accounts]]
code = "4000"
name = "Revenue"
type = "revenue"
[[setup.accounts]]
code = "6200"
name = "Rent"
type = "expense"
[[setup.accounts]]
code = "6999"
name = "General Expenses"
type = "expense"
[[setup.projects]]
name = "Zeta"
kind = "client"
[[setup.projects]]
name = "Harbor"
kind = "client"
[[setup.payees]]
name = "Dana Illustration"
form = "1099-NEC"
[[events]]
date = "2026-03-02"
description = "Invoice to Cedar"
invoice = { customer = "Cedar Client", lines = [
{ description = "Design", amount = "3000.00", project = "Zeta" },
{ description = "Hosting", amount = "200.00", project = "Harbor" },
{ description = "Rush fee", amount = "100.00" },
{ description = "Revisions", amount = "500.00", project = "Zeta" },
] }
[[events]]
date = "2026-03-09"
description = "Dana's bill"
bill = { vendor = "Dana Illustration", lines = [
{ description = "Illustration", amount = "1200.00", project = "Zeta" },
{ description = "Postage", amount = "50.00" },
] }
[[events]]
date = "2026-03-20"
description = "Cedar pays invoice 1"
lines = [
{ account = "1000", side = "debit", amount = "3800.00" },
{ account = "1200", side = "credit", amount = "3800.00" },
]
[[events]]
date = "2026-03-30"
description = "Pay Dana's bill"
payee = "Dana Illustration"
lines = [
{ account = "2000", side = "debit", amount = "1250.00" },
{ account = "1000", side = "credit", amount = "1250.00" },
]
[[events]]
date = "2026-03-31"
description = "Studio rent"
lines = [
{ account = "6200", side = "debit", amount = "1500.00" },
{ account = "1000", side = "credit", amount = "1500.00" },
]
[[events]]
date = "2026-04-02"
description = "Dana's second bill"
bill = { vendor = "Dana Illustration", amount = "300.00" }
[[expect]]
query = "entry"
entry = 1
[expect.values]
"1200.debit" = "3800.00"
"4000.credit" = "3800.00"
[[expect]]
query = "entry"
entry = 2
[expect.values]
"6999.debit" = "1250.00"
"2000.credit" = "1250.00"
[[expect]]
query = "project"
project = "Zeta"
from = "2026-01-01"
to = "2026-12-31"
[expect.values]
revenue = "3500.00"
expenses = "1200.00"
net = "2300.00"
"to_date.revenue" = "3500.00"
"to_date.expenses" = "1200.00"
"to_date.net" = "2300.00"
unrecovered_cost = "none"
[[expect]]
query = "project"
project = "Harbor"
from = "2026-01-01"
to = "2026-12-31"
[expect.values]
revenue = "200.00"
expenses = "0.00"
net = "200.00"
"to_date.revenue" = "200.00"
"to_date.expenses" = "0.00"
"to_date.net" = "200.00"
unrecovered_cost = "none"
[[expect]]
query = "profit_and_loss"
from = "2026-01-01"
to = "2026-12-31"
[expect.values]
"4000" = "3800.00"
"6200" = "1500.00"
"6999" = "1550.00"
net_income = "750.00"
[[expect]]
query = "vendor_1099_paid"
from = "2026-01-01"
to = "2026-12-31"
[expect.values]
"Dana Illustration" = "1250.00"