refuse hand entries (P4b S1, part A) Plan P4b (D-45), slice S1, the engine half: rules.md B-38. - ledger-core: every receivables or payables line carries its document (Ledger.line_docs: DocRef, Movement, DocTag), written by the document commands in the step that posts it, derived on replay from the existing document events (the role's account as it stood then; payments by the ordinal rule), copied onto a reversal's mirror. Ledger::stands_on; doc_state / invoice_state / bill_state (total, paid, outstanding, status Open/Partial/Paid/WrittenOff/Void, overdue days) as of any day; ar_aging / ap_aging read them, so reversed payments and voids are right. The control guard (add_line, add_line_fx, post_entry, register_recurring) refuses untagged lines on receivables/payables, exempting a reversal's mirror of a legacy line; replay never refuses. Bounds (kernel::running_bounds, bounds_kept) on payments and reversals; a document reversal never dated before its entry; deposit/payer accounts must be cash-like and hold no role. New API: receive_payment_with / pay_bill_with (PaymentDetails: instrument, reference), void_document / check_void_document, control_check, payments_recorded, standing_payments, replay_reverse_entry. Invoice.amount_paid/status remain only as derived caches for the MCP layer until part B. cashflow bill_splits reads payments from the tags. - ledger-store: journal feature document_standing (D-39 gated) for a payment accepted only because an earlier one was reversed; receive_payment_with / pay_bill_with (instrument journaled as entry.instrument_set, reference in the description), void_document; replay uses replay_reverse_entry; schema 15 drops the projection's amount_paid/status. Fixture p4-arap-before + golden figures written by the version before S1, adjudicated in arap_standing.rs. - ledger-gui: party card, cash "coming up" and company owed totals read doc_state as of today (late from the derived state). - Lean Documents.lean (control_agrees and friends); Kani bounds_check_matches_definition, bounds_kept_is_the_definition_on_books_in_bounds; rules B-38, B-18/B-23 amended; bookspec `older = true` for legacy hand lines; tests that hand-post to 1200/2000 post as replay or renumbered. Review fixes (both reviews of part A): - control_role_of guards only an account the role is assigned to or one holding its documents' lines (a chart's own 1200 Equipment or card at 2000 is free until a document posts there); payment accounts check other roles by holds_role (type-checked). The MCP tests that failed on the guard (oracle_mcp, spec_projects) pass unchanged. - standing_payments leaves out reversals (sorted, deduped); replayed tags match the movement's side; payments_recorded counts every payment event (tagged or not, Ledger.payment_events) and refuses overflow. - The record caches settled (paid + discounted + written off) and owed (Invoice/Bill.owed, never serialized): a void never reads as paid. - assign_role: receivables/payables refuse moving onto an account with untagged lines (RoleAccountHasHandLines) and, on their control account holding a balance, say DocumentRoleHoldsBalance (no hand entry named); B-23 reworded. The reversal-mirror exemption only takes a hand line off (even chain depth); putting it back is refused. - DocStatus Overpaid and Unattached; aging leaves out credit balances; ControlCheck.attention lists out-of-bounds and unattached documents. - stands_on counts a chain in order; indexes (doc_index, doc_accounts, order_pos, reversed_by) keep the derived figures linear. - Viewer reads a post-dated document as of its own date; one state per row. bounds_kept's side-crossing documented as intended. - Tests: ten new spec_documents scenarios, stronger proptests, store proptest arap_props (live = replay = snapshot at every date, closed months), fuzz ops void/payments with details, a GUI post-dated test; Lean Step.assign / Step.release with unattached_zero kept; model limits stated in docs/testing.md and B-38. Review fixes (CPA and engineering lenses): only an assigned role's account or one holding document lines is a control account (a chart's own 1200 asset stays free); a role can't move onto untagged lines or off document lines (Lean Step.assign); a void's cache never reads as paid; no Decimal sum panics; per-document indexes keep figures linear; a replayed tag matches its side; the feature gate counts payment events; a payment's reversal is never listed as standing; an overpaid document has its own status; the viewer keeps post-dated documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3gXMVt7XJPi6ens1or9Dj
185 lines
5.4 KiB
TOML
185 lines
5.4 KiB
TOML
# 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-cli `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"
|
|
older = true
|
|
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"
|
|
older = true
|
|
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"
|