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:
51 files changed
+3201
-166
No files matched your search
+81
-14
@@ -1585,7 +1585,12 @@ value at contribution and the §704(c) method, B-25) and `projects` (a
|
||||
`project.set`, a new event type: a class's project facts; an
|
||||
`attachment.linked` to the subject kind `project`, which an older version
|
||||
would call corrupt; a `decision.recorded` with `projects`, which an older
|
||||
version would drop silently: B-37). A command asks for
|
||||
version would drop silently: B-37). After P3: `document_line_projects`
|
||||
(an `invoice.created` or `bill.created` line carrying `class_id`, its
|
||||
project, B-37 item 8; an older version would restore the document without
|
||||
it, silently). It is a feature of its own, not part of `projects`: books
|
||||
that declared `projects` before it existed wait for their owner's next
|
||||
upgrade before a document's line names a project. A command asks for
|
||||
the feature it needs (`Store::ensure_feature`) before its first journaled
|
||||
line, and only when the line it is about to write uses it, so a write
|
||||
refused for waiting on the upgrade journals nothing, never an entry
|
||||
@@ -2545,8 +2550,12 @@ package). **Checked:** `ledger-core` `tests/tax_capital.rs`;
|
||||
a class as a project ... Projects are entities too and can have name,
|
||||
description, whatever other metadata you think they should have"; the
|
||||
convention `link-to-projects` in the books: "whenever applicable, we link
|
||||
things to [projects]"); CONVENTION (job costing, item 3; the snapshot, item 7: a presentation choice from management accounting, not GAAP); AUTHORITY (on
|
||||
spec, item 4: ASC 450-30-25-1; ASC 340-40-25-5 with B-22;
|
||||
things to [projects]"); DECISION (the owner, 2026-10-22, plan D-43: an invoice's or bill's
|
||||
lines take a project, each line one or none, item 8); CONVENTION (job
|
||||
costing, items 3 and 8; the snapshot, item 7: a presentation choice from
|
||||
management accounting, not GAAP); AUTHORITY (on
|
||||
spec, item 4: ASC 450-30-25-1; ASC 340-40-25-5 with B-22; directly
|
||||
related costs, item 8: ASC 340-40-25-7;
|
||||
`sources/fasb-asc.md`, both quoted through Deloitte's DART roadmaps and
|
||||
not yet re-read in the ASC basic view: an open item)
|
||||
|
||||
@@ -2582,8 +2591,10 @@ not yet re-read in the ASC basic view: an open item)
|
||||
such line through the day, from the first day the books keep, whatever
|
||||
the project's dates. A tagged balance-sheet line counts nothing (an
|
||||
asset bought for it counts as it is depreciated or expensed, tagged
|
||||
then). No cost is allocated: a shared cost counts only as split across
|
||||
lines when it is entered. The projects with the untagged lines
|
||||
then). The books allocate no cost: a shared cost counts toward
|
||||
projects only as allocation entries of their own, made by the
|
||||
company's allocation convention (item 8). The projects with the
|
||||
untagged lines
|
||||
partition the P&L. By month, the period's last 240 months at most.
|
||||
4. **On spec.** Work done hoping to be paid: its costs are expenses when
|
||||
incurred (B-22; ASC 340-40-25-5 makes a cost of an anticipated
|
||||
@@ -2595,8 +2606,9 @@ not yet re-read in the ASC basic view: an open item)
|
||||
same). Its unrecovered cost, "if repaid", is expenses less revenue to
|
||||
date, never below zero: a figure, never an asset.
|
||||
5. **Status.** Finished and abandoned projects still take lines (a late
|
||||
cost, a final invoice); `books.add_line` and `books.record_payout` say
|
||||
so when one is tagged.
|
||||
cost, a final invoice); `books.add_line`, `books.record_payout`,
|
||||
`books.create_invoice` and `books.create_bill` say so when one is
|
||||
tagged.
|
||||
6. Omitted dates mean what B-30 says (`books.project`'s period); to date
|
||||
is always stated as such, beside it.
|
||||
7. **Snapshot (a presentation choice, not GAAP).** A project's net is
|
||||
@@ -2625,6 +2637,52 @@ not yet re-read in the ASC basic view: an open item)
|
||||
standard defines or requires these figures (ASC 280's segment
|
||||
reporting is for public entities' operating segments, not projects);
|
||||
they come from item 3's, one function the tools and the viewer share.
|
||||
8. **Invoices and bills (the owner's decision, 2026-10-22, D-43).** Each
|
||||
line of an invoice or bill names one project or none. A document that
|
||||
spans N projects is N lines, each with its own amount; there is no
|
||||
percentage split, so every figure is exact, as entered, with nothing
|
||||
to round. A cost truly shared among projects is not split on the
|
||||
document: its line names none, and it reaches the projects, if at
|
||||
all, only as allocation entries of their own, on the stated basis of
|
||||
the company's monthly allocation convention when `books.conventions`
|
||||
has one; without one the line stays untagged and the agent asks the
|
||||
human. The reasoning: job costing (item 3) charges a job the costs
|
||||
traceable to it, its direct costs, whole, and reaches a shared
|
||||
(indirect) cost only by an allocation on a stated basis, never by
|
||||
guessing at the document. ASC 340-40-25-7 counts as relating
|
||||
directly to a contract (25-5(a)) both the costs traceable to it
|
||||
(direct labor and materials, costs explicitly chargeable to the
|
||||
customer, costs incurred only because of the contract, such as
|
||||
subcontractors: 25-7(a), (b), (d), (e)) and allocations of costs that
|
||||
relate directly to the contract or its activities (25-7(c)); 25-8
|
||||
sends general and administrative costs to expense unless the contract
|
||||
makes them chargeable to the customer (`sources/fasb-asc.md`). The
|
||||
books carry the first kind whole on the document's line and the
|
||||
second as entries under the allocation convention on its basis;
|
||||
neither is a percentage on the document, and 25-7(c) is what the
|
||||
allocation convention models. An invoice line naming an on-spec
|
||||
project (item 4) is taken, and the tools ask whether there is now an
|
||||
agreement: on spec, a hoped-for payment is no receivable until it is
|
||||
received. Its revenue (an
|
||||
invoice's) or cost (a bill's) then counts toward the project exactly
|
||||
as a tagged line of a hand-built entry does: the document's entry
|
||||
posts one revenue (expense) 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 line (`arap::document_parts`), so a
|
||||
document naming none posts exactly the one line every document posted
|
||||
before. The receivable (payable) line is never tagged: it is a
|
||||
balance-sheet line (item 3 counts it nothing), and so are the
|
||||
payments (`books.receive_payment`, `books.pay_bill`: cash against the
|
||||
receivable or payable), which take no project. Nothing else moves: the
|
||||
P&L, the 1099 worksheet (B-19: payments made) and a party's totals
|
||||
(B-35: what moved the money) read the same with or without the
|
||||
projects; only the projects' figures and the P&L by class differ. A
|
||||
line naming a finished or abandoned project is taken, and the tools
|
||||
say so (item 5); one naming a project the books don't have is refused,
|
||||
the document whole. Journaled as the line's `class_id` in
|
||||
`invoice.created` or `bill.created` and an `entry.line_class_set` right
|
||||
after its revenue or expense line's `entry.line_added`, behind the
|
||||
journal feature `document_line_projects` (B-27).
|
||||
|
||||
**Enforced:** `ledger_core::classes::{ProjectFacts, ProjectStatus,
|
||||
ProjectKind}`, `Ledger::{check_set_project, set_project,
|
||||
@@ -2632,13 +2690,22 @@ replay_set_project, projects_of_party}`, `reports::{project_figures,
|
||||
project_to_date, project_entries, contribution_margin_pct}`,
|
||||
`ProjectToDate::{net, margin_pct, any_tagged}`, `ProjectFigures::{months_net_to_date,
|
||||
period_margin_pct, period_lines}`, `kernel::unrecovered_cost`;
|
||||
`Store::{add_project, set_project, subject_feature}` (feature
|
||||
`projects`); `books.add_project`, `books.update_project`,
|
||||
`books.projects`, `books.project`; the viewer's Projects pages.
|
||||
**Checked:** `ledger-core` `tests/spec_projects.rs`, `ledger-store`
|
||||
`tests/projects.rs`, `ledger-mcp` `tests/spec_projects.rs`, `ledger-gui`
|
||||
`tests/projects.rs`; bookspec `projects-net-is-its-tagged-lines` and
|
||||
`projects-on-spec-costs-are-expenses`; Kani `unrecovered_cost_laws`;
|
||||
`arap::document_parts`, `Ledger::{create_invoice, create_bill}` (item
|
||||
8); `Store::{add_project, set_project, subject_feature}` (feature
|
||||
`projects`), `Store::{create_invoice, create_bill}` (feature
|
||||
`document_line_projects`); `books.add_project`, `books.update_project`,
|
||||
`books.projects`, `books.project`, `books.create_invoice` and
|
||||
`books.create_bill` (`class` on a line); the viewer's Projects pages and
|
||||
an invoice's or bill's page (each line's project).
|
||||
**Checked:** `ledger-core` `tests/spec_projects.rs` and
|
||||
`tests/spec_document_projects.rs`, `ledger-store` `tests/projects.rs` and
|
||||
`tests/document_projects.rs`, `ledger-mcp` `tests/spec_projects.rs`,
|
||||
`ledger-gui` `tests/projects.rs`, `ledger-cli` `tests/projects_parity.rs`
|
||||
and `tests/format_upgrade.rs` (`books_p2_served_cut_over_whole`); bookspec
|
||||
`projects-net-is-its-tagged-lines`,
|
||||
`projects-on-spec-costs-are-expenses` and
|
||||
`projects-invoice-and-bill-lines-count-by-project`; proptest
|
||||
`prop_document_parts_partition_the_total`; Kani `unrecovered_cost_laws`;
|
||||
proptests `prop_project_nets_partition_the_pnl`,
|
||||
`prop_project_set_round_trips`, `prop_project_contribution_is_the_net_to_date`
|
||||
(core) and `prop_snapshot_contribution_is_the_net_to_date` (viewer).
|
||||
@@ -274,3 +274,32 @@ performance obligations in the future; and they "are expected to be
|
||||
recovered."
|
||||
→ B-37 item 4 (with B-22): on-spec work has no contract it is expected
|
||||
to recover its costs from, so its costs are expensed as incurred.
|
||||
|
||||
## 340-40-25-7 (Costs that relate directly to a contract)
|
||||
|
||||
Added 2026-10-22 for B-37 item 8 as the DART revenue roadmap sets it
|
||||
out; not re-read in the ASC basic view: check it there at the next
|
||||
reading. The costs that "relate directly to a contract" (25-5(a)) are
|
||||
(a) direct labor, (b) direct materials, (c) allocations of costs that
|
||||
relate directly to the contract or its activities (supervision,
|
||||
insurance, depreciation of the tools used on it), (d) costs explicitly
|
||||
chargeable to the customer, and (e) other costs incurred only because
|
||||
the entity entered into the contract (payments to subcontractors, for
|
||||
one). Allocations are among the directly related costs, not set apart
|
||||
from them.
|
||||
|
||||
## 340-40-25-8 (Costs expensed when incurred)
|
||||
|
||||
Added 2026-10-22 with 25-7, from the same DART chapter (13.3), likewise
|
||||
to check in the basic view. Expensed when incurred: general and
|
||||
administrative costs (unless explicitly chargeable to the customer under
|
||||
the contract), costs of wasted materials, labor or other resources not
|
||||
reflected in the contract's price, costs that relate to satisfied (or
|
||||
partly satisfied) performance obligations, and costs the entity cannot
|
||||
tell apart between satisfied and unsatisfied obligations.
|
||||
→ B-37 item 8 (with 25-7): a cost traceable to one job (25-7(a), (b),
|
||||
(d), (e)) is that job's, whole, on the document's line; a cost that
|
||||
relates to several jobs reaches them only by an allocation on a stated
|
||||
basis (25-7(c)), which the books record as the allocation convention's
|
||||
own entries, never as a percentage on the document; general and
|
||||
administrative cost (25-8) is company overhead, no project's.
|
||||
Reference in new issue
Block a user