refactor: rule references cite bookspec ids

Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5.

Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
swaitsandMuse Wonder 1.0 committed 2026-11-08 19:40:22 -07:00
1 parent 7a177a3cfc
commit 489360f598
221 files changed
+1706 -1580

No files matched your search

+2 -2
View File
@@ -59,7 +59,7 @@ impl AccountType {
/// The longest name a new account (or a rename) may take, in characters:
/// one line that every report prints, as long as the company's own name
/// may be ([`crate::settings::MAX_TEXT`]). The command's bound, never
/// replay's (rules.md B-28): a journaled name of any length replays.
/// replay's (BS-entry-4): a journaled name of any length replays.
pub const MAX_ACCOUNT_NAME: usize = crate::settings::MAX_TEXT;
/// A single account in the chart of accounts.
@@ -151,7 +151,7 @@ impl ChartOfAccounts {
/// Give an account a new name. Only the account must exist: what a
/// new name may be is the command's to check
/// ([`crate::Ledger::rename_account`]), never replay's (rules.md B-28).
/// ([`crate::Ledger::rename_account`]), never replay's (BS-entry-4).
pub fn set_name(&mut self, id: AccountId, name: &str) -> Result<(), LedgerError> {
let a = self
.accounts
+2 -2
View File
@@ -44,7 +44,7 @@ pub fn interval_start(d: NaiveDate, interval: Interval) -> NaiveDate {
/// `[start, end]` split on calendar interval boundaries, first and last
/// pieces clipped to the range. Empty when `end < start`. Never panics:
/// an interval that would end past chrono's last day ends at `end`
/// (rules.md B-28: books an earlier version wrote may hold such dates).
/// (BS-entry-4: books an earlier version wrote may hold such dates).
pub fn intervals(
start: NaiveDate,
end: NaiveDate,
@@ -264,7 +264,7 @@ mod tests {
}
/// At chrono's last day (books an earlier version wrote may hold it):
/// the last interval ends there, never a panic (rules.md B-28).
/// the last interval ends there, never a panic (BS-entry-4).
#[test]
fn intervals_reach_chronos_last_day() {
let y = NaiveDate::MAX.year();
+20 -20
View File
@@ -9,7 +9,7 @@
//! * `receive_payment`: Dr Cash, Cr A/R.
//! * `pay_bill`: Dr A/P, Cr Cash.
//!
//! A document keeps no figure of its own (plan P4b, D-45; rules.md B-38):
//! A document keeps no figure of its own (plan P4b, D-45; BS-arap-2):
//! every ledger line on a receivables or payables account carries the
//! document it belongs to ([`DocTag`]), and what is paid and still owed,
//! and the document's status, are read from those lines that stand
@@ -29,7 +29,7 @@ use serde::{Deserialize, Serialize};
/// The most days a payment term may run: ten years, far beyond any trade
/// term, and short of the calendar's end for every document date the
/// books can hold (B-39).
/// books can hold (BS-arap-3).
pub const MAX_TERMS_DAYS: u16 = 3_650;
/// Opaque customer handle.
@@ -198,12 +198,12 @@ pub enum DocStatus {
Paid,
/// Nothing owed, the last of it written off (S7).
WrittenOff,
/// Its own entry doesn't stand: reversed (B-9), number kept.
/// Its own entry doesn't stand: reversed (BS-ledger-5), number kept.
Void,
/// Less than nothing owed: more paid against it than it is for, a
/// credit balance owed back (to the customer on an invoice, by the
/// vendor on a bill). Only in books an earlier version left out of
/// bounds (B-38 INVARIANT 2); never a receivable or a payable, so
/// bounds (BS-arap-2 INVARIANT 2); never a receivable or a payable, so
/// never aged.
Overpaid,
/// Its own entry stands but carries no line tagged with it (an older
@@ -263,7 +263,7 @@ pub struct DocState {
impl DocState {
/// It owes less than nothing or more than its total: books an earlier
/// version left out of bounds (B-38 INVARIANT 2; plan P4b.14 item 3),
/// version left out of bounds (BS-arap-2 INVARIANT 2; plan P4b.14 item 3),
/// which the control check lists for attention.
pub fn out_of_bounds(&self) -> bool {
self.outstanding < Decimal::ZERO || self.outstanding > self.total
@@ -275,7 +275,7 @@ impl DocState {
/// ```text
/// GOAL: one status from the ledger's figures, whatever happened to the
/// document, its payments and their reversals.
/// SOURCE: docs/spec/rules.md B-38; plan/served.md P4b.3 ("Status as of D");
/// SOURCE: BS-arap-2; plan/served.md P4b.3 ("Status as of D");
/// ASC 310-10 (a credit balance is not a receivable).
/// INVARIANTS:
/// 1. Void exactly when its own entry doesn't stand (`origin_stands`
@@ -426,7 +426,7 @@ impl PaymentDetails {
}
}
/// One document a settlement applies to (plan P4b S6; rules.md B-42): the
/// One document a settlement applies to (plan P4b S6; BS-arap-6): the
/// cash paid on it, the early-payment discount taken off it, and why a
/// discount outside its terms was taken anyway.
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -456,7 +456,7 @@ pub struct Fee {
pub vendor: Option<VendorId>,
}
/// Everything one settlement needs (plan P4b S6; rules.md B-42): its date,
/// Everything one settlement needs (plan P4b S6; BS-arap-6): its date,
/// description, deposit account, the party every document belongs to, the
/// applications, and the processor's fee when one was withheld.
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -484,7 +484,7 @@ pub struct SettleParams {
/// when it is a control line ([`Application`]'s payment or discount).
pub type SettlementRow = (crate::AccountId, crate::Side, Decimal, Option<DocTag>);
/// How a document's payment terms count their days (rules.md B-39; plan
/// How a document's payment terms count their days (BS-arap-3; plan
/// P4b S4.1): from the document's date, from the end of its month, or a
/// date the parties agreed.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -514,11 +514,11 @@ pub struct EarlyDiscount {
}
/// Payment terms: one due date, and the early-payment discount open
/// before it (rules.md B-39; plan P4b S4.1, A-2, A-8).
/// before it (BS-arap-3; plan P4b S4.1, A-2, A-8).
///
/// ```text
/// GOAL: terms give one due date and one discount date, exactly.
/// SOURCE: docs/spec/rules.md B-39; plan/served.md 8.3.13 (B-39);
/// SOURCE: BS-arap-3; plan/served.md 8.3.13 (BS-arap-3);
/// CONVENTION: standard trade-terms notation; UCC §2-310(a) for
/// goods; for services, the contract.
/// INVARIANTS:
@@ -976,7 +976,7 @@ pub struct DocumentLine {
/// Line amount (positive).
pub amount: Decimal,
/// The project (a class) the line's revenue or cost belongs to, if
/// any (rules.md B-37): the posted entry's revenue or expense line for
/// any (BS-statement-5): the posted entry's revenue or expense line for
/// it carries the tag; the receivable or payable line never does.
/// Documents journaled before the `document_line_projects` feature
/// have none.
@@ -1035,7 +1035,7 @@ pub struct Invoice {
pub entry_id: u64,
/// The number it was issued under ("INV-0007"), from
/// [`crate::Ledger::next_invoice_number`]; stored at issue, never
/// recomputed, kept by a void (A-2, B-40). None on a legacy invoice:
/// recomputed, kept by a void (A-2, BS-arap-4). None on a legacy invoice:
/// it is shown as "Invoice {id}" and never counted.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub number: Option<String>,
@@ -1061,7 +1061,7 @@ pub struct Invoice {
/// The sum of a document's lines; refused (TooLargeToCompute), never a
/// panic, past exact arithmetic. A document is restored from its journal
/// line as written (rules.md B-28), so its lines are bounded only by what
/// line as written (BS-entry-4), so its lines are bounded only by what
/// the version that wrote it checked.
pub fn document_total(lines: &[DocumentLine], what: &str) -> Result<Decimal, LedgerError> {
crate::kernel::total_of(lines, |l| l.amount)
@@ -1082,9 +1082,9 @@ pub type DocumentPartKey = (Option<crate::AccountId>, Option<crate::ClassId>);
/// GOAL: a document's lines post to their accounts and count toward their
/// projects, and a document whose lines name neither posts exactly
/// as before.
/// SOURCE: docs/spec/rules.md B-37 item 3 (job costing: the revenue and
/// SOURCE: BS-statement-5 item 3 (job costing: the revenue and
/// direct costs identified with one job) and item 8 (an
/// invoice's or bill's line names its project); B-39 and plan
/// invoice's or bill's line names its project); BS-arap-3 and plan
/// P4b S4.1 A-10 (every bill line names its account).
/// INVARIANTS:
/// 1. The parts sum to the document's total (conservation), and each
@@ -1166,7 +1166,7 @@ pub struct Bill {
/// The auto-posted journal entry.
pub entry_id: u64,
/// The vendor's own invoice number, when given: what a duplicate
/// check reads (B-40; [`crate::Ledger::check_vendor_ref`]).
/// check reads (BS-arap-4; [`crate::Ledger::check_vendor_ref`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub vendor_ref: Option<String>,
/// The day we received the bill, when it differs from its date.
@@ -1198,7 +1198,7 @@ impl Bill {
/// Validate document lines: at least one, all positive amounts, each in a
/// journal line's range, and a quantity and unit price that multiply to
/// the amount exactly (plan P4b S4.1). For new documents; replay restores
/// them as journaled (rules.md B-28).
/// them as journaled (BS-entry-4).
pub fn validate_lines(lines: &[DocumentLine]) -> Result<(), LedgerError> {
if lines.is_empty() {
return Err(LedgerError::EmptyDocumentLines);
@@ -1251,7 +1251,7 @@ pub fn validate_lines(lines: &[DocumentLine]) -> Result<(), LedgerError> {
/// Validate that due date is not before the document date, and both are
/// in the calendar the books keep (P0 review round 3, S1). For new
/// documents; replay restores them as journaled (rules.md B-28).
/// documents; replay restores them as journaled (BS-entry-4).
pub fn validate_due_date(date: NaiveDate, due_date: NaiveDate) -> Result<(), LedgerError> {
crate::calendar::check(date)?;
crate::calendar::check(due_date)?;
@@ -1354,7 +1354,7 @@ pub struct AgingDocument {
///
/// ```text
/// GOAL: say how overdue a balance is, as of a date.
/// SOURCE: docs/spec/rules.md B-18 (bucket edges: CONVENTION, ASC
/// SOURCE: BS-arap-1 (bucket edges: CONVENTION, ASC
/// 326-20-55-38 illustrative; due today is Current: DECISION,
/// owner 2026-10-13).
/// INVARIANTS:
+16 -16
View File
@@ -11,7 +11,7 @@
//! — and postings go through the normal entry machinery, so every
//! accounting invariant holds.
//!
//! Two figures of accumulated depreciation, never confused (rules.md B-15 rule 8):
//! Two figures of accumulated depreciation, never confused (BS-asset-1 rule 8):
//! what the schedule says is due through a date
//! ([`accumulated_scheduled_through`]) and what the books carry, the runs
//! posted and not reversed ([`crate::Ledger::accumulated_posted`]). Book
@@ -72,7 +72,7 @@ pub struct Asset {
pub id: AssetId,
/// What it is, e.g. "2023 Sprinter van".
pub description: String,
/// The day it was placed in service: depreciation starts here (B-15).
/// The day it was placed in service: depreciation starts here (BS-asset-1).
/// The day the company acquired it is its acquisition entry's
/// ([`crate::Ledger::asset_acquired_date`]), never later than this.
#[serde(rename = "purchase_date")]
@@ -274,7 +274,7 @@ pub struct AssetBasis {
/// The §704(c) method chosen for it, if chosen (contributions only).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sec704c_method: Option<Sec704cMethod>,
/// Who gave the facts, when, and on what (rules.md B-29).
/// Who gave the facts, when, and on what (BS-ledger-9).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source: Option<crate::settings::Source>,
}
@@ -334,7 +334,7 @@ impl AssetBasis {
}
/// The checks every journaled `asset.basis_set` passed, which replay
/// applies (rules.md B-28): the facts fit the rule and none is
/// applies (BS-entry-4): the facts fit the rule and none is
/// negative. No bound on size or places.
pub fn check_journaled(&self) -> Result<(), String> {
if self.rule == BasisRule::Purchase {
@@ -365,7 +365,7 @@ impl AssetBasis {
/// written (the rule through 2026-10-16), for a record with no value
/// at contribution: a purchase takes no contributor basis; a
/// contribution needs one, non-negative, in cents at most. Replay of
/// that event applies exactly these (rules.md B-28).
/// that event applies exactly these (BS-entry-4).
pub fn check_legacy_journaled(&self) -> Result<(), String> {
use BasisRule::*;
match (self.rule, self.contributor_adjusted_basis) {
@@ -610,7 +610,7 @@ struct MonthLine {
///
/// ```text
/// GOAL: how much of an asset's cost has been used up, month by month.
/// SOURCE: docs/spec/rules.md B-15 (straight line; salvage never
/// SOURCE: BS-asset-1 (straight line; salvage never
/// depreciated; partial months by days; ASC 360-10-35-4: cost less
/// salvage over the useful life "in a systematic and rational
/// manner", as equitably as possible to the periods served);
@@ -642,7 +642,7 @@ struct MonthLine {
/// either side of one).
/// 7. NEVER panics: a figure that can't be computed (a life past
/// chrono's last day, amounts past exact arithmetic) is refused
/// (rules.md B-28).
/// (BS-entry-4).
/// SCENARIOS:
/// 1. IF $12,000 over 12 months from Jan 1, through Jun 15:
/// - SHOULD end with June at 500.00 (15 of 30 days), accumulated
@@ -743,7 +743,7 @@ fn schedule_months(asset: &Asset, through: NaiveDate) -> Result<Vec<MonthLine>,
/// (inclusive), exact to the minor unit ([`depreciation_schedule`]): the
/// tools' `accumulated_scheduled_through`. What the books carry is
/// [`crate::Ledger::accumulated_posted`]; the two agree once every month
/// due is posted (rules.md B-15 rule 8).
/// due is posted (BS-asset-1 rule 8).
pub fn accumulated_scheduled_through(
asset: &Asset,
as_of: NaiveDate,
@@ -758,7 +758,7 @@ pub fn accumulated_scheduled_through(
/// the schedule's own book value (as [`ScheduleLine::book_value`]), never
/// what the books carry, which is cost less
/// [`crate::Ledger::accumulated_posted`] (the register's and the tools'
/// `book_value`, rules.md B-24).
/// `book_value`, BS-asset-3).
pub fn scheduled_book_value(asset: &Asset, as_of: NaiveDate) -> Result<Decimal, LedgerError> {
asset
.cost
@@ -795,9 +795,9 @@ pub struct PostedRun {
/// GOAL: the catch-up rule reads the books as they stood at each month
/// end: a run reversed after its month ended still carried that
/// month, so running the month again would carry it twice.
/// SOURCE: docs/spec/rules.md B-9 (a mistake is corrected by an opposite
/// entry, dated when it is made), B-10 (reversing the reversal
/// re-instates), B-15 (the catch-up rule).
/// SOURCE: BS-ledger-5 (a mistake is corrected by an opposite
/// entry, dated when it is made), BS-ledger-6 (reversing the reversal
/// re-instates), BS-asset-1 (the catch-up rule).
/// INVARIANTS:
/// 1. Through any month's end, the effects sum to what the runs' entries
/// and their reversals dated on or before it carry in the asset's
@@ -1010,7 +1010,7 @@ fn cumulatives(
/// SOURCE: plan/served.md P3 "Settled in design" (2026-10-20): a month of
/// depreciation skipped is caught up in the month the run is made
/// (an immaterial miss; a material one is restated, ASC 250, a
/// correction for a human and the CPA); docs/spec/rules.md B-15.
/// correction for a human and the CPA); BS-asset-1.
/// INVARIANTS:
/// 1. amount = catch_up_room for the month: kernel::catch_up over the
/// month ends M from this month's through the latest month an effect
@@ -1124,11 +1124,11 @@ pub struct DisposalAmounts {
/// Whether an asset can be disposed of for `proceeds`: it is active and
/// the proceeds aren't negative. The checks every journaled
/// disposal passed, so replaying one never depends on a figure (rules.md
/// B-28). The date's floor, the day the company acquired the asset, needs
/// disposal passed, so replaying one never depends on a figure (
/// BS-entry-4). The date's floor, the day the company acquired the asset, needs
/// its acquisition entry, so the ledger checks it for new disposals only
/// (`Ledger::dispose_asset`): a disposal may fall on the in-service date
/// (one day held, accrual being inclusive, B-15), or before it once the
/// (one day held, accrual being inclusive, BS-asset-1), or before it once the
/// asset is acquired (nothing accrued yet).
pub fn check_disposal(asset: &Asset, proceeds: Money) -> Result<(), LedgerError> {
if asset.status != AssetStatus::Active {
+5 -5
View File
@@ -1,4 +1,4 @@
//! The audit's statements checks (plan P8; rules.md B-45): the books,
//! The audit's statements checks (plan P8; BS-ledger-13): the books,
//! read as an auditor would, through a date, as a list of findings.
//!
//! ```text
@@ -7,8 +7,8 @@
//! reproducible and its workpaper hashes the same twice.
//! SOURCE: IRS Pub. 583 (records that support entries); Rev. Proc. 98-25
//! §5.01 (the relationship between the records and the books must
//! be demonstrable); docs/spec/rules.md B-6 to B-14 (the
//! statements), B-38 (control accounts), B-43 (evidence);
//! be demonstrable); BS-statement-1 to BS-statement-3 (the
//! statements), BS-arap-2 (control accounts), BS-entry-5 (evidence);
//! DECISION D-9 (the audit and its bar), D-53 (a run, not a job).
//! INVARIANTS:
//! 1. Pure: reads the ledger and the facts [`AuditInput`] hands in,
@@ -668,7 +668,7 @@ fn settings_problems(problems: &[String]) -> Vec<Finding> {
}
// ---------------------------------------------------------------------------
// Scope, method and the attestation bar (rules.md B-45; D-9)
// Scope, method and the attestation bar (BS-ledger-13; D-9)
// ---------------------------------------------------------------------------
/// What an audit covers.
@@ -761,7 +761,7 @@ impl Effort {
}
/// How an attestation was made, as the client says (self-reported: the
/// books record the claim, never prove it; rules.md B-45).
/// books record the claim, never prove it; BS-ledger-13).
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
pub struct Method {
/// The model that checked, as it names itself.
+7 -7
View File
@@ -94,7 +94,7 @@ pub(crate) fn fiscal_year_unclamped(md: (u32, u32), d: NaiveDate) -> (NaiveDate,
/// the CPA package's year, and every default period derive from.
/// SOURCE: IRS Pub. 538 (docs/spec/sources/irs-periods-and-methods.md):
/// "A tax year is an annual accounting period for keeping records
/// and reporting income and expenses"; rules.md B-28 (no date
/// and reporting income and expenses"; BS-entry-4 (no date
/// outside the calendar).
/// INVARIANTS:
/// 1. For d in the calendar: FIRST_DAY <= result <= d, and d is before
@@ -108,7 +108,7 @@ pub fn fiscal_year_start_on(md: (u32, u32), d: NaiveDate) -> NaiveDate {
fiscal_year_start_unclamped(md, d).max(FIRST_DAY)
}
/// What an omitted date means, by the kind of report (rules.md B-30): the
/// What an omitted date means, by the kind of report (BS-period-3): the
/// text every tool description and date parameter shows, so none can say
/// other than [`PeriodDefaults`] does.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -152,13 +152,13 @@ pub const YEAR_DOC: &str =
"Calendar year. Omitted: this calendar year (1099s and party totals count by calendar year).";
/// The defaults an omitted date takes, today, under the company's fiscal
/// year: the one rule (rules.md B-30) the report tools, the viewer and
/// year: the one rule (BS-period-3) the report tools, the viewer and
/// the tool descriptions share. Built by [`period_defaults`].
///
/// ```text
/// GOAL: one meaning for "no dates", everywhere: a report asked for
/// without dates covers this fiscal year so far.
/// SOURCE: rules.md B-30; IRS Pub. 538 ("an annual accounting period for
/// SOURCE: BS-period-3; IRS Pub. 538 ("an annual accounting period for
/// keeping records and reporting income and expenses"); 26 U.S.C.
/// §6041(a) ("in any calendar year") and §6041A(a)(2) ("during
/// such calendar year") for the calendar-year counts; DECISION
@@ -251,7 +251,7 @@ impl PeriodDefaults {
/// The days in a month of a year chrono holds, without stepping to the
/// next month, so chrono's last month (December 262142, whose next month
/// chrono can't hold) has its 31 days too (rules.md B-28: a schedule an
/// chrono can't hold) has its 31 days too (BS-entry-4: a schedule an
/// earlier version accepted is computed, never a panic).
pub fn days_in_month(year: i32, month: u32) -> u32 {
match month {
@@ -290,7 +290,7 @@ pub struct SpanPart {
/// ```text
/// GOAL: cut a span of days (an asset's life, a schedule's coverage) into
/// the calendar months it touches, for proration by days.
/// SOURCE: docs/spec/rules.md B-15, B-16; kernel::prorate_by_days.
/// SOURCE: BS-asset-1, BS-prepaid-1; kernel::prorate_by_days.
/// INVARIANTS:
/// 1. The parts' days sum to the span's days; every part has 1 to its
/// month's days (a valid kernel::MonthPart), and only the last is
@@ -567,7 +567,7 @@ mod tests {
);
}
/// The descriptions say what the resolver does (B-30), in the words
/// The descriptions say what the resolver does (BS-period-3), in the words
/// every tool shows.
#[test]
fn the_descriptions_name_the_rule() {
+15 -15
View File
@@ -1,4 +1,4 @@
//! The statement of cash flows (rules.md B-14), by the direct method: each
//! The statement of cash flows (BS-statement-3), by the direct method: each
//! entry that moved cash, in the section of the accounts it settled, gross;
//! the reconciliation of net income to operating cash as a separate
//! schedule; and the investing and financing activities no cash settled,
@@ -77,7 +77,7 @@ pub enum OperatingClass {
/// (e) Interest paid.
InterestPaid,
/// (f) Income taxes paid. No tax category marks an entity-level income
/// tax yet, so nothing is filed here (rules.md B-14 rule 5).
/// tax yet, so nothing is filed here (BS-statement-3 rule 5).
IncomeTaxesPaid,
/// (g) Other operating cash payments.
OtherPayments,
@@ -178,7 +178,7 @@ pub struct CashFlowLine {
/// The cash, + in.
pub amount: Decimal,
/// Of `amount`, what a member or a lender paid or received for the
/// company with no cash account moving (rules.md B-14 rule 11, D-42):
/// company with no cash account moving (BS-statement-3 rule 11, D-42):
/// a constructive receipt or payment. Zero for most lines.
pub on_behalf: Decimal,
/// Codes of this kind's accounts the entry moved, sorted.
@@ -295,7 +295,7 @@ pub struct OperatingReconciliation {
pub net_cash_from_operating: Decimal,
}
/// The footing check (rules.md B-14 rule 9).
/// The footing check (BS-statement-3 rule 9).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CashFlowFooting {
/// Operating + investing + financing.
@@ -344,7 +344,7 @@ pub struct CashFlowWarning {
pub message: String,
}
/// The statement of cash flows, direct method (rules.md B-14).
/// The statement of cash flows, direct method (BS-statement-3).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CashFlowStatement {
/// Period start, inclusive.
@@ -440,7 +440,7 @@ pub enum RoleList {
Investing,
}
/// A contradiction among the cash flow account roles (rules.md B-14 rule
/// A contradiction among the cash flow account roles (BS-statement-3 rule
/// 2): the statement refuses rather than guess.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RoleProblem {
@@ -546,7 +546,7 @@ impl RoleProblem {
}
}
/// Every contradiction among the cash flow account roles (rules.md B-14
/// Every contradiction among the cash flow account roles (BS-statement-3
/// rule 2), in a fixed order. Codes the chart lacks are the caller's to
/// report. The one check behind both the statement's refusal and the
/// settings' problems, so the two never drift apart.
@@ -554,7 +554,7 @@ impl RoleProblem {
/// ```text
/// GOAL: the statement's account roles partition the chart, so every
/// account is in exactly one section.
/// SOURCE: rules.md B-14 rule 2 (ASC 230-10-45-10: every cash receipt and
/// SOURCE: BS-statement-3 rule 2 (ASC 230-10-45-10: every cash receipt and
/// payment is investing, financing or operating).
/// INVARIANTS:
/// 1. Cash and investing accounts MUST be assets; financing accounts
@@ -639,7 +639,7 @@ pub fn role_problems(
out
}
/// rules.md B-14 rule 9, on its own so the check is tested directly (it
/// BS-statement-3 rule 9, on its own so the check is tested directly (it
/// cannot fail on posted entries): the sections sum to the change in
/// cash, or nothing is produced.
pub fn foot(sections_sum: Decimal, net_change: Decimal) -> Result<CashFlowFooting, LedgerError> {
@@ -977,8 +977,8 @@ impl<'a> Roles<'a> {
}
}
/// The liabilities that hold distributions declared by `end` (rules.md
/// B-14 rule 2), among the accounts `open` leaves to be placed: each
/// The liabilities that hold distributions declared by `end` (
/// BS-statement-3 rule 2), among the accounts `open` leaves to be placed: each
/// credited, in the posted entries dated on or before `end` (closes and
/// reversals aside), only by entries whose debits are all to equity (Dr
/// Distributions / Cr Distributions Payable; a corporation's Dr Retained
@@ -1031,7 +1031,7 @@ type KindOrder = (u8, u8, String);
/// so the payment is an investing outflow (ASC 230-10-45-13(c)). A bill
/// posts to the general-expenses control today, so this is empty until a
/// bill can carry an equipment line (P4b S4). A bill's payments are the
/// entries whose payables line carries it (rules.md B-38).
/// entries whose payables line carries it (BS-arap-2).
#[derive(Default)]
struct BillSplits {
/// By (entry, line index): the investing part of that payables line,
@@ -1741,15 +1741,15 @@ fn codes<'p>(
Ok(out.into_iter().collect())
}
/// The statement of cash flows for a period, direct method (rules.md
/// B-14).
/// The statement of cash flows for a period, direct method (
/// BS-statement-3).
///
/// ```text
/// GOAL: the statement of cash flows for a period: each entry's cash by
/// section and kind, the noncash investing and financing activities,
/// and net income reconciled to operating cash; footing exactly or
/// not at all.
/// SOURCE: rules.md B-14 (ASC 230-10-10-1 cash receipts and payments;
/// SOURCE: BS-statement-3 (ASC 230-10-10-1 cash receipts and payments;
/// 45-4, 45-5 what cash is; 45-7, 45-26 gross; 45-10 the three
/// sections; 45-12 to 45-17 what each holds; 45-24 reconciles
/// beginning and ending cash; 45-25 the
+6 -6
View File
@@ -10,7 +10,7 @@
//! on drafts only; posted entries are immutable, so their classes are frozen.
//!
//! A class is also a project: the class with its facts ([`ProjectFacts`]:
//! what it is, where it stands, who it is for; rules.md B-37). Every class
//! what it is, where it stands, who it is for; BS-statement-5). Every class
//! is one; a class an earlier version wrote has the default facts.
use chrono::NaiveDate;
@@ -28,7 +28,7 @@ pub struct Class {
pub name: String,
}
/// Where a project stands (rules.md B-37).
/// Where a project stands (BS-statement-5).
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
)]
@@ -85,7 +85,7 @@ impl ProjectStatus {
}
}
/// What kind of work a project is (rules.md B-37): it decides the
/// What kind of work a project is (BS-statement-5): it decides the
/// accounting questions its costs raise.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub enum ProjectKind {
@@ -141,7 +141,7 @@ pub const MAX_LINKS: usize = 8;
/// One link: one line of text ([`crate::settings::line_text`]'s length
/// and control-character rules) with no full TIN as a web address holds
/// one ([`crate::settings::holds_printed_tin_in_link`]: a printed SSN or
/// EIN is refused, a store listing's `id284882215` is not; rules.md B-26).
/// EIN is refused, a store listing's `id284882215` is not; BS-partner-2).
fn link_text(l: &str) -> Result<String, String> {
use crate::settings::{MAX_TEXT, holds_printed_tin_in_link, line_text};
// line_text's TIN rule is a plain text's, so it sees the link with
@@ -167,13 +167,13 @@ fn link_text(l: &str) -> Result<String, String> {
/// GOAL: say what a project is, where it stands and who it is for, in
/// the few facts a job cost sheet carries, without a project
/// manager's sprawl (no budgets, estimates or percent complete).
/// SOURCE: docs/spec/rules.md B-37; DECISION (owner, 2026-10-21: "Projects
/// SOURCE: BS-statement-5; DECISION (owner, 2026-10-21: "Projects
/// are entities too and can have name, description, whatever
/// other metadata"); job-order costing (a job cost sheet: the
/// job, its customer, its dates).
/// INVARIANTS:
/// 1. No field holds a full taxpayer identification number
/// (settings::line_text / long_text, rules.md B-26).
/// (settings::line_text / long_text, BS-partner-2).
/// 2. ended_on only when the project is finished or abandoned, and
/// never before started_on.
/// 3. The party, if any, is in the directory (archived allowed).
+2 -2
View File
@@ -40,7 +40,7 @@
//! 4. Decision and open-item ids are allocated in order and journaled;
//! a decision supersedes at most one live decision; an item resolves
//! once.
//! 5. Replay takes what was journaled (rules.md B-28): text limits and
//! 5. Replay takes what was journaled (BS-entry-4): text limits and
//! chart checks are for new commands only.
//! 6. No text holds a full TIN (settings INVARIANT 4).
//! ```
@@ -273,7 +273,7 @@ pub struct NewDecision {
pub supersedes: Option<u64>,
/// The rule or document it rests on, if any.
pub citation: Option<String>,
/// The projects (classes) it is about, if any (rules.md B-37).
/// The projects (classes) it is about, if any (BS-statement-5).
pub projects: Vec<crate::ClassId>,
}
+26 -26
View File
@@ -55,7 +55,7 @@ pub enum LedgerError {
TooLargeToCompute(String),
/// An amount finer than its currency's smallest unit (ISO 4217 minor
/// units): no one can pay a fraction of a cent (rules.md B-3).
/// units): no one can pay a fraction of a cent (BS-ledger-1).
#[error(
"amount {amount} {currency} has more than {places} decimal places; round it to the {currency} minor unit first"
)]
@@ -505,7 +505,7 @@ pub enum LedgerError {
end: String,
},
/// The statement of cash flows would not foot (rules.md B-14 rule 9):
/// The statement of cash flows would not foot (BS-statement-3 rule 9):
/// an engine error, never output. It cannot happen on balanced books
/// (Lean `cashflow_sections_sum_to_cash_change`); if it does, the
/// engine is wrong, and nothing is shown rather than a wrong figure.
@@ -523,13 +523,13 @@ pub enum LedgerError {
},
/// The cash flow statement's account roles (cash, financing, investing)
/// contradict each other or the chart (rules.md B-14 rule 2). The text
/// contradict each other or the chart (BS-statement-3 rule 2). The text
/// names the setting and says what to change.
#[error("cash flow account roles: {0}")]
CashFlowRoles(String),
/// A report period given only a start, after today: an omitted end is
/// today (rules.md B-30), so the period would end before it starts.
/// today (BS-period-3), so the period would end before it starts.
#[error(
"invalid date range: start {start} is after the end, which defaults to today ({today}): pass end"
)]
@@ -608,12 +608,12 @@ pub enum LedgerError {
/// A document line's quantity and unit price don't multiply to its
/// amount, or only one of the two is given: the engine never rounds
/// one (plan P4b S4.1; rules.md B-39).
/// one (plan P4b S4.1; BS-arap-3).
#[error("{0}")]
LineArithmetic(String),
/// A document line is on an account that kind of document can't post
/// to (plan P4b S4.1, A-10; rules.md B-39): a role account, a cash
/// to (plan P4b S4.1, A-10; BS-arap-3): a role account, a cash
/// account, or a type the document's side doesn't take.
#[error("account {code} \"{name}\" cannot take {kind} line: {why}")]
DocumentLineAccount {
@@ -628,8 +628,8 @@ pub enum LedgerError {
},
/// A vendor's invoice number (normalized) already names a standing
/// bill of that vendor, and no duplicate reason was given (rules.md
/// B-40).
/// bill of that vendor, and no duplicate reason was given (
/// BS-arap-4).
#[error(
"vendor invoice number '{vendor_ref}' is already on another standing bill of this vendor; \
give duplicate_reason when it really is a second bill"
@@ -642,7 +642,7 @@ pub enum LedgerError {
},
/// An invoice number already names an invoice: numbers are never
/// reused (rules.md B-40, A-2).
/// reused (BS-arap-4, A-2).
#[error("invoice number '{0}' is already used; numbers are never reused")]
DuplicateInvoiceNumber(String),
@@ -654,7 +654,7 @@ pub enum LedgerError {
/// An early-payment discount needs net days to be open before: it
/// can't be given with due-on-receipt, end-of-month or custom terms
/// (rules.md B-39).
/// (BS-arap-3).
#[error(
"an early-payment discount needs net terms with a fixed number of days; it can't be given with due-on-receipt, end-of-month or custom terms"
)]
@@ -662,7 +662,7 @@ pub enum LedgerError {
/// `invoicing.first_number` asked to move after a numbered invoice
/// exists: the series has begun, and a number is never reused or
/// renumbered (rules.md B-40, A-2). The store's check lands with the
/// renumbered (BS-arap-4, A-2). The store's check lands with the
/// invoice numbers it reads (P4b S4.3).
#[error(
"invoicing.first_number is locked: a numbered invoice already exists, so the series has begun and its numbers are never reused"
@@ -695,13 +695,13 @@ pub enum LedgerError {
SettlementMixedKinds(String),
/// A settlement's documents don't all belong to the one party it
/// names (rules.md B-42 INVARIANT 1).
/// names (BS-arap-6 INVARIANT 1).
#[error("{0} is not {1}'s: a settlement covers one party only")]
SettlementPartiesDiffer(String, u64),
/// A discount needs a reason: none is stated in the document's terms,
/// or it is larger than its terms allow, or it is taken after the
/// discount date (rules.md B-42 INVARIANT 2).
/// discount date (BS-arap-6 INVARIANT 2).
#[error(
"{doc}: the discount of {discount} needs a reason ({because}); pass discount_reason with the payment"
)]
@@ -751,7 +751,7 @@ pub enum LedgerError {
/// A settlement's figures can't be exact: the cash and discounts
/// don't cover the applications, or the fee leaves a negative deposit
/// (rules.md B-42 INVARIANT 1).
/// (BS-arap-6 INVARIANT 1).
#[error("{0}")]
InvalidSettlement(String),
@@ -761,7 +761,7 @@ pub enum LedgerError {
InvalidPayment(String),
/// Receivables or payables can't move while their account holds a
/// balance (rules.md B-23, B-38): that balance is the documents', and
/// balance (BS-ledger-8, BS-arap-2): that balance is the documents', and
/// a hand entry moving it is refused by the control guard; it moves
/// with its documents (plan P4b S7).
#[error(
@@ -781,7 +781,7 @@ pub enum LedgerError {
},
/// Receivables or payables can't move to an account holding lines
/// that are no document's (rules.md B-38 INVARIANT 1): they would
/// that are no document's (BS-arap-2 INVARIANT 1): they would
/// become hand lines on a control account.
#[error(
"account {code} \"{name}\" holds lines no invoice or bill carries (entry {entry} first), \
@@ -814,7 +814,7 @@ pub enum LedgerError {
},
/// A line on a receivables or payables control account carries no
/// document (rules.md B-23, B-38): the control account must always
/// document (BS-ledger-8, BS-arap-2): the control account must always
/// equal its documents, so only the document commands post there.
#[error(
"account {account} is a control account (its balance is its invoices or bills): {at} can't be posted there by hand. Use books.create_invoice, books.receive_payment, books.create_bill or books.pay_bill; to void a document, books.reverse_entry of its entry"
@@ -828,14 +828,14 @@ pub enum LedgerError {
},
/// A reversal or payment would leave a document owing less than nothing
/// or more than its total at some date (rules.md B-38 INVARIANT 2): the
/// or more than its total at some date (BS-arap-2 INVARIANT 2): the
/// message says which document, when, and what to reverse first.
#[error("{0}")]
DocumentBounds(String),
/// A reversal is dated before the entry it reverses (rules.md B-9,
/// A reversal is dated before the entry it reverses (BS-ledger-5,
/// D-73): a correction comes after what it corrects, for every kind of
/// entry. New commands only; replay never refuses (B-28).
/// entry. New commands only; replay never refuses (BS-entry-4).
#[error("entry {entry} is dated {original}: its reversal can't be dated before it, on {date}")]
ReversalBeforeOriginal {
/// The entry reversed.
@@ -852,12 +852,12 @@ pub enum LedgerError {
/// A draft's state or discard was refused: the message says why (a
/// note or reason that breaks the books' text rule, no reason given).
/// Plan P4, rules.md B-43.
/// Plan P4, BS-entry-5.
#[error("{0}")]
InvalidDraft(String),
/// A void invoice can't be recorded as sent: it was never a document
/// the customer should have received (plan P4b S5, B-38).
/// the customer should have received (plan P4b S5, BS-arap-2).
#[error("invoice {0} is void: a void invoice was never sent")]
DocumentVoid(u64),
@@ -866,8 +866,8 @@ pub enum LedgerError {
/// books' text rule). Plan P4b S5.
#[error("{0}")]
InvalidSend(String),
/// A bad debt can't be written off on cash-basis books (rules.md
/// B-41 INVARIANT 3; IRC §166(a); Treas. Reg. §1.166-1(e)): the
/// A bad debt can't be written off on cash-basis books (
/// BS-arap-5 INVARIANT 3; IRC §166(a); Treas. Reg. §1.166-1(e)): the
/// invoice was never counted as income, so there is no basis to
/// deduct.
#[error(
@@ -937,11 +937,11 @@ pub enum LedgerError {
UnknownClass(u32),
/// Another class (project) already has this name, ignoring capitals
/// (rules.md B-37).
/// (BS-statement-5).
#[error("a project named {0:?} already exists: names are unique, ignoring capitals")]
DuplicateClassName(String),
/// A project's facts the books can't take (rules.md B-37): the reason.
/// A project's facts the books can't take (BS-statement-5): the reason.
#[error("{0}")]
InvalidProject(String),
+4 -4
View File
@@ -121,7 +121,7 @@ impl Annotation {
}
// ---------------------------------------------------------------------------
// The evidence gate (plan P4, I-5, D-47; rules.md B-43)
// The evidence gate (plan P4, I-5, D-47; BS-entry-5)
// ---------------------------------------------------------------------------
/// What posted an entry that the ledger's own state doesn't otherwise say:
@@ -196,7 +196,7 @@ impl Policy {
}
/// Total debits of the entry (one side of the balanced entry). A
/// draft's lines are as journaled, of any size (rules.md B-28): a
/// draft's lines are as journaled, of any size (BS-entry-4): a
/// total past exact arithmetic is refused (TooLargeToCompute), never
/// a panic.
pub fn entry_debits(entry: &JournalEntry) -> Result<Decimal, LedgerError> {
@@ -355,14 +355,14 @@ impl Policy {
}
/// Whether `entry` needs evidence before it posts: the one function that
/// decides (plan P4 step 2, I-5, D-47; rules.md B-43). The store's gate,
/// decides (plan P4 step 2, I-5, D-47; BS-entry-5). The store's gate,
/// the server's previews and digest, the viewer and Needs attention all
/// call it.
///
/// ```text
/// GOAL: one answer, from what the ledger knows, to "does this entry need
/// a receipt".
/// SOURCE: docs/spec/rules.md B-43; IRS Pub. 583 (supporting documents);
/// SOURCE: BS-entry-5; IRS Pub. 583 (supporting documents);
/// DECISION D-47 (a reversal's evidence is its original's, D-12);
/// DECISION (owner: the threshold, strictly greater than, 2026-10-12).
/// INVARIANTS:
+8 -8
View File
@@ -383,14 +383,14 @@ pub fn apply_decision(decisions: &mut Vec<Dated1099>, new: Dated1099) -> Applied
}
/// The checks a new 1099 decision passes before it is recorded (replay
/// skips them: rules.md B-28): the decision ([`Decision1099::check`]),
/// skips them: BS-entry-4): the decision ([`Decision1099::check`]),
/// its source, its date in the books' calendar, and that a dated decision
/// records a change. Returns what recording it would do.
///
/// ```text
/// GOAL: no dated decision silently leaves the vendor's earlier payments
/// undecided.
/// SOURCE: DECISION D-40 (owner, 2026-10-20); docs/spec/rules.md B-19.
/// SOURCE: DECISION D-40 (owner, 2026-10-20); BS-1099-1.
/// SCENARIOS:
/// 1. IF `new` is dated, would be recorded, and no decision other than
/// undetermined is in force at any time before its date: SHOULD
@@ -428,7 +428,7 @@ pub fn check_new_decision(decisions: &[Dated1099], new: &Dated1099) -> Result<Ap
///
/// ```text
/// GOAL: the dollar amount at which a vendor's payments become reportable.
/// SOURCE: docs/spec/rules.md B-19 (26 U.S.C. §6041(a), (h), §6041A(a)(2),
/// SOURCE: BS-1099-1 (26 U.S.C. §6041(a), (h), §6041A(a)(2),
/// Pub. L. 119-21 §70433(f): payments made after December 31,
/// 2025; sources/irs-1099-thresholds.md,
/// sources/irs-1099-payment-method.md).
@@ -604,7 +604,7 @@ pub struct PaymentAccounts {
/// GOAL: a payment line's role comes from what the books record, and a
/// line whose method isn't recorded is never presumed a card's
/// unless only a card pays through its account.
/// SOURCE: docs/spec/rules.md B-19 (P3 review R2); DECISION D-40 (a bank
/// SOURCE: BS-1099-1 (P3 review R2); DECISION D-40 (a bank
/// payment with no method recorded counts).
/// INVARIANTS (first match wins):
/// 1. Cash: one of the books' cash accounts.
@@ -868,7 +868,7 @@ fn bounds(
/// settings), entries dated after `through` left out.
///
/// ```text
/// SOURCE: docs/spec/rules.md B-19 (26 U.S.C. §6041(a): payments made in
/// SOURCE: BS-1099-1 (26 U.S.C. §6041(a): payments made in
/// the year; Treas. Reg. §1.6041-1(a)(1)(iv): card and network
/// payments go on Form 1099-K; §1.6041-1(e)(1): the company is the
/// payor when a member pays its bill; §1.6041-3: payees no return
@@ -876,7 +876,7 @@ fn bounds(
/// crate::shares (an entry with several parties, each with their
/// share; DECISION, owner, 2026-10-15); DECISION D-40 (owner,
/// 2026-10-20: dated decisions; a bank payment with no method
/// recorded counts); B-33 (a worksheet as of a day).
/// recorded counts); BS-statement-4 (a worksheet as of a day).
/// DEFINITIONS:
/// buckets(e): kernel::payment_bucket per line (role from `sources` and
/// the instruments' accounts; tag from Ledger::entry_instrument),
@@ -888,7 +888,7 @@ fn bounds(
/// sources.financing), what the shares resolve against (the MCP server
/// checks them with the same).
/// target(e): crate::shares::target(e, money).amount: what the shares
/// split (rules.md B-35); a reversal's is its original's negated.
/// split (BS-partner-3); a reversal's is its original's negated.
/// INVARIANTS:
/// 1. Refuses when `sources.cash` is empty (name the books' cash
/// accounts; never every asset: P3 review R5), and, with no
@@ -899,7 +899,7 @@ fn bounds(
/// makes a worksheet as of a day: the payments from January 1
/// through it (§6041(a) and §6041A(a)(2) count what is paid "in any
/// calendar year"; a CPA package as of June 30 shows the year to
/// date, rules.md B-33).
/// date, BS-statement-4).
/// 3. An entry naming at most one party: the vendor's amounts are
/// buckets(e).
/// 4. An entry naming several parties (one of them the vendor's party,
+1 -1
View File
@@ -15,7 +15,7 @@
//! ```text
//! GOAL: every payment's method is recorded once, plainly, so the 1099
//! worksheet never guesses whether a payment was by card.
//! SOURCE: docs/spec/rules.md B-19 (Treas. Reg. §1.6041-1(a)(1)(iv),
//! SOURCE: BS-1099-1 (Treas. Reg. §1.6041-1(a)(1)(iv),
//! §1.6050W-1(b)(1), (b)(3), (c)(3); Instructions for Form 1099-K:
//! automated clearing houses are not payment networks;
//! sources/irs-1099-payment-method.md); plan/served.md 4.9, 5.2.
+2 -2
View File
@@ -24,8 +24,8 @@ pub enum EntryStatus {
}
/// Where a draft entry stands (plan P4, `drafts_v2`): still being built,
/// or finished and waiting on the document that supports it (rules.md
/// B-43). Meaningful while the entry is a draft; a posted entry keeps
/// or finished and waiting on the document that supports it (
/// BS-entry-5). Meaningful while the entry is a draft; a posted entry keeps
/// the state it had and nothing reads it.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum DraftState {
+3 -3
View File
@@ -7,7 +7,7 @@
//! beginning capital, contributions (cash and property separately),
//! their share of income, distributions, ending capital.
//! SOURCE: Form 1065 Schedule K-1 instructions, Item L ("Partner's capital
//! account analysis", on the partnership's books); B-13;
//! account analysis", on the partnership's books); BS-partner-1;
//! DECISION (owner, 2026-10-15): the CPA package carries a K-1
//! worksheet per member.
//! INVARIANTS:
@@ -37,7 +37,7 @@
//! (kernel::apportion, ties to the earlier member): each takes at
//! most its own credit, and the split depends on the order the
//! members are given only for a tied leftover cent (never on line
//! order). Joint property is joint (B-13's
//! order). Joint property is joint (BS-partner-1's
//! shares, the house convention that joint funds are 50/50).
//! 5. k1_detail's lines explain each row: per member, its cash lines
//! sum to contributions_cash, its property lines to
@@ -434,7 +434,7 @@ mod tests {
(a, Side::Credit, "1000"),
]);
// A hand line on receivables: only books an earlier version wrote
// hold one now (the control guard, rules.md B-38), so replayed.
// hold one now (the control guard, BS-arap-2), so replayed.
crate::parties::replaying(|| post(&[(ar, Side::Debit, "200"), (b, Side::Credit, "200")]));
post(&[(exp, Side::Debit, "50"), (b, Side::Credit, "50")]);
let members = [
+47 -47
View File
@@ -27,7 +27,7 @@ pub trait Amount: Copy + Ord {
fn from_u32(n: u32) -> Option<Self>;
/// `self * rhs`, or `None` when it cannot be represented exactly.
///
/// A quantity times a unit price (a document line, B-39) is the one
/// A quantity times a unit price (a document line, BS-arap-3) is the one
/// use: it never rounds.
fn checked_mul(self, rhs: Self) -> Option<Self>;
/// `self / rhs` exactly, or `None` when `rhs` is zero or the quotient
@@ -38,8 +38,8 @@ pub trait Amount: Copy + Ord {
/// [`Decimal`] dollars), ties away from zero; never a negative zero.
/// `None` when `rhs` is zero or the quotient cannot be represented.
///
/// The one use is a tax category's deductible amount (rules.md B-32,
/// B-21), whose shares are added exactly and rounded once, never
/// The one use is a tax category's deductible amount (BS-ledger-11,
/// BS-entry-3), whose shares are added exactly and rounded once, never
/// share by share.
fn checked_div_round_cent(self, rhs: Self) -> Option<Self>;
/// `self` rounded to a whole multiple of `step`, in `mode`; `None`
@@ -330,7 +330,7 @@ pub fn net<T: Amount>(lines: impl IntoIterator<Item = (Side, T)>) -> Option<T> {
/// ```text
/// GOAL: an early-payment discount never takes more than its percentage
/// says, in exact money.
/// SOURCE: docs/spec/rules.md B-39 INVARIANT 2, B-42; plan/served.md
/// SOURCE: BS-arap-3 INVARIANT 2, BS-arap-6; plan/served.md
/// 8.3.13; CHOICE: the gross method, A-8 (the discount is
/// booked when taken, never estimated).
/// INVARIANTS:
@@ -360,14 +360,14 @@ pub struct Settlement<T> {
pub deposit: T,
}
/// The arithmetic of a settlement (rules.md B-42; plan P4b S6): each
/// The arithmetic of a settlement (BS-arap-6; plan P4b S6): each
/// document's cash and discount, and the processor's fee withheld from the
/// cash that reaches the bank.
///
/// ```text
/// GOAL: a settlement is exact: what the documents are settled by is the
/// cash plus the discounts, and the deposit is the cash less the fee.
/// SOURCE: docs/spec/rules.md B-42; plan/served.md 8.3.6, 8.3.13 (B-42);
/// SOURCE: BS-arap-6; plan/served.md 8.3.6, 8.3.13 (BS-arap-6);
/// CONVENTION; DECISION: the gross method (A-8) and the fee's
/// gross presentation (A-4).
/// INVARIANTS:
@@ -412,7 +412,7 @@ pub fn settle<T: Amount>(cash: &[T], discounts: &[T], fee: T) -> Option<Settleme
/// ```text
/// GOAL: a line's quantity times its unit price is the amount it posts,
/// to the last decimal place.
/// SOURCE: docs/spec/rules.md B-39; plan/served.md 8.3.4 ("kernel::
/// SOURCE: BS-arap-3; plan/served.md 8.3.4 ("kernel::
/// line_amount(q, u) == amount exactly").
/// INVARIANTS:
/// 1. Some(p) gives p = quantity x unit_price exactly.
@@ -431,8 +431,8 @@ pub fn line_amount<T: Amount>(quantity: T, unit_price: T) -> Option<T> {
/// ```text
/// GOAL: a category's deductible amount is its exact shares added and
/// rounded once, never a sum of rounded shares.
/// SOURCE: docs/spec/rules.md B-32 (CHOICE: owner, 2026-11-07, D-67) and
/// B-21 (Form 1065 instructions: "include cents when adding the
/// SOURCE: BS-ledger-11 (CHOICE: owner, 2026-11-07, D-67) and
/// BS-entry-3 (Form 1065 instructions: "include cents when adding the
/// amounts and round off only the total"); plan/served.md 10.1.
/// INVARIANTS:
/// 1. On Some(a), a is the exact sum S = Σ(book_i × percent_i ÷ 100)
@@ -579,7 +579,7 @@ pub fn credit_line<T: Amount>(credit: T) -> Option<(Side, T)> {
}
// ---------------------------------------------------------------------------
// 1099 payments: where each payment line goes (rules.md B-19)
// 1099 payments: where each payment line goes (BS-1099-1)
// ---------------------------------------------------------------------------
/// A line's role in a payment to a vendor, from its account.
@@ -646,7 +646,7 @@ impl Bucket {
/// GOAL: every payment line to a vendor counts toward its 1099, is a card
/// or payment-network payment (Form 1099-K), or is unknown; never
/// guessed.
/// SOURCE: docs/spec/rules.md B-19 (Treas. Reg. §1.6041-1(a)(1)(iv): a
/// SOURCE: BS-1099-1 (Treas. Reg. §1.6041-1(a)(1)(iv): a
/// transaction reportable under §6050W is not reported under
/// §6041; §1.6041-1(e)(1): a member writing a check at the
/// company's direction doesn't make the member the payor;
@@ -693,7 +693,7 @@ pub fn split_payment<T: Amount>(lines: &[(Option<Bucket>, Side, T)]) -> Option<[
/// ```text
/// GOAL: a card bill paid from the bank, a member reimbursed, or a loan
/// paid down never counts toward a vendor's 1099.
/// SOURCE: docs/spec/rules.md B-19 (26 U.S.C. §6041(a): payments made to
/// SOURCE: BS-1099-1 (26 U.S.C. §6041(a): payments made to
/// the payee; P3 review R1, 2026-10-20).
/// INVARIANTS:
/// 1. The buckets' sum P is kept exactly.
@@ -758,8 +758,8 @@ pub fn plug_last<T: Amount>(whole: T, parts: &mut [T]) -> Option<()> {
/// ```text
/// GOAL: split a whole into parts, each a whole number of units where
/// possible, summing to the whole exactly, without favoring anyone.
/// SOURCE: docs/spec/rules.md B-13 (shares: 26 U.S.C. §704(a); cent
/// rounding: DECISION, owner 2026-10-13), B-21 (exact totals).
/// SOURCE: BS-partner-1 (shares: 26 U.S.C. §704(a); cent
/// rounding: DECISION, owner 2026-10-13), BS-entry-3 (exact totals).
/// INVARIANTS:
/// 1. MUST make the parts sum to `whole` exactly.
/// 2. MUST change each part by zero or one unit (the first in order
@@ -835,7 +835,7 @@ pub fn apportion<T: Amount>(whole: T, parts: &mut [T], remainders: &[T], unit: T
/// ```text
/// GOAL: members' running totals that never drift a unit from their
/// exact shares, whatever earlier closes did.
/// SOURCE: docs/spec/rules.md B-13 (shares: 26 U.S.C. §704(a); capital
/// SOURCE: BS-partner-1 (shares: 26 U.S.C. §704(a); capital
/// accounts carry the allocations: Treas. Reg.
/// §1.704-1(b)(2)(iv)(b); cent rounding: DECISION, owner
/// 2026-10-13; counted from the first close: D-10, 2026-10-16).
@@ -880,7 +880,7 @@ pub fn apportion_cumulative<T: Amount>(
Some(())
}
/// Where a line falls on the statement of cash flows (rules.md B-14 rule
/// Where a line falls on the statement of cash flows (BS-statement-3 rule
/// 2): a cash account, or one of the three sections.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Flow {
@@ -895,8 +895,8 @@ pub enum Flow {
}
impl Flow {
/// The three sections, in the order cash is applied to them (rules.md
/// B-14 rule 3): operating, investing, financing.
/// The three sections, in the order cash is applied to them (
/// BS-statement-3 rule 3): operating, investing, financing.
pub const SECTIONS: [Flow; 3] = [Flow::Operating, Flow::Investing, Flow::Financing];
}
@@ -938,7 +938,7 @@ pub fn take<T: Amount>(remaining: T, movement: T) -> Option<T> {
/// ```text
/// GOAL: split an entry's cash among the parts it settled, without
/// inventing or losing any.
/// SOURCE: rules.md B-14 rule 3 (ASC 230-10-50-5: only the cash portion
/// SOURCE: BS-statement-3 rule 3 (ASC 230-10-50-5: only the cash portion
/// of a part-cash transaction is a cash flow; the order is a
/// CONVENTION, the ASC is silent).
/// INVARIANTS:
@@ -965,7 +965,7 @@ pub fn apply_cash<T: Amount>(cash: T, movements: &[T], applied: &mut [T]) -> Opt
(remaining == T::ZERO).then_some(())
}
/// An entry's cash flows (rules.md B-14 rule 3): the net movement of its
/// An entry's cash flows (BS-statement-3 rule 3): the net movement of its
/// cash lines, applied to the sections moving against it in the order
/// operating, investing, financing, each up to its own movement; what is
/// left of a section's movement is the part no cash settled. `None` when
@@ -1036,7 +1036,7 @@ fn credits_and_debits<T: Amount>(movements: &[T]) -> Option<(T, T)> {
}
/// Which way money a member or a lender handled for the company went
/// (rules.md B-14 rule 11, D-42).
/// (BS-statement-3 rule 11, D-42).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum OnBehalf {
/// Paid for the company: sources credited (borrowed, contributed)
@@ -1058,8 +1058,8 @@ impl OnBehalf {
}
/// What a member or a lender paid, or received, for the company with no
/// cash account moving: a constructive receipt and disbursement (rules.md
/// B-14 rule 11, D-42). `sources` are what is left unsettled of the
/// cash account moving: a constructive receipt and disbursement (
/// BS-statement-3 rule 11, D-42). `sources` are what is left unsettled of the
/// entry's kinds that can pay or receive for the company (a financing
/// liability, a member's equity), `uses` of the kinds they can pay or
/// receive for, each debit-positive. [`OnBehalf::Paid`]: `amount =
@@ -1075,7 +1075,7 @@ impl OnBehalf {
/// GOAL: show money a member or lender handled for the company as the
/// company's own, borrowed (or contributed) and spent, without
/// inventing or losing a cent.
/// SOURCE: rules.md B-14 rule 11 (D-42; ASC 230 is silent, PwC Viewpoint
/// SOURCE: BS-statement-3 rule 11 (D-42; ASC 230 is silent, PwC Viewpoint
/// FSP 6.9.3.1, Deloitte DART Roadmap 7.2, BDO Blueprint 3.4).
/// INVARIANTS:
/// 1. The parts net to zero: Σ from + Σ to = 0, so the entry's cash
@@ -1108,7 +1108,7 @@ pub fn constructive<T: Amount>(
}
/// How much of an entry is an exchange inside investing and financing
/// that no cash settled (rules.md B-14 rule 7, ASC 230-10-50-4: debt
/// that no cash settled (BS-statement-3 rule 7, ASC 230-10-50-4: debt
/// converted to equity, one asset traded for another). `debits` and
/// `credits` are the net debits and net credits of the entry's investing
/// and financing balance-sheet accounts (each account netted first; both
@@ -1123,7 +1123,7 @@ pub fn exchanged<T: Amount>(debits: T, credits: T, inflow: T, outflow: T) -> Opt
Some(d.min(c).max(T::ZERO))
}
/// Which way an entry moved value with its parties (rules.md B-35).
/// Which way an entry moved value with its parties (BS-partner-3).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Direction {
/// The company paid the party, or gave it value: a line on the
@@ -1172,7 +1172,7 @@ impl Direction {
}
/// What an entry's parties split, and what of it counts in their totals
/// (rules.md B-35).
/// (BS-partner-3).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PartyTarget<T> {
/// The whole, signed as a line on the parties' own account would be
@@ -1216,7 +1216,7 @@ fn least<T: Amount>(a: T, b: T) -> T {
if a < b { a } else { b }
}
/// What an entry's parties split and what of it counts (rules.md B-35
/// What an entry's parties split and what of it counts (BS-partner-3
/// item 3, every case but a close and a reversal, which the caller
/// handles: a close is its parties' own-account movement with direction
/// neither, a reversal is [`reverse_target`] of its original's).
@@ -1227,7 +1227,7 @@ fn least<T: Amount>(a: T, b: T) -> T {
/// money or as property, so a property contribution and its
/// reversal never read alike, and a promise is never counted as if
/// it were paid.
/// SOURCE: rules.md B-35 (B-2 signs; DECISION, owner, 2026-10-20: a
/// SOURCE: BS-partner-3 (BS-entry-2 signs; DECISION, owner, 2026-10-20: a
/// member's entry counts what moved their capital, money is cash,
/// cards, the members' financing and loans, and a liability credit
/// never counts as paying that liability's own creditor; Helvering
@@ -1321,7 +1321,7 @@ pub fn party_target<T: Amount>(
})
}
/// A reversal's target from its original's (rules.md B-35 item 3; B-9: a
/// A reversal's target from its original's (BS-partner-3 item 3; BS-ledger-5: a
/// correction is the opposite entry): every amount negated (never to a
/// negative zero), paid and received swapped. An involution. `None` past
/// the type's range.
@@ -1495,10 +1495,10 @@ fn round_to_unit<T: Units>(num: T, den: T, unit: T) -> Option<T> {
/// GOAL: how much of a total a span of days has used up by a given day,
/// each day of a month bearing the same share, the whole total
/// reached on the span's last day and never before.
/// SOURCE: docs/spec/rules.md B-15 (straight line, partial months by days;
/// SOURCE: BS-asset-1 (straight line, partial months by days;
/// ASC 360-10-35-4: "systematic and rational", as equitably as
/// possible to the periods served), B-16 (daily schedules, D-11),
/// B-21 (exact totals).
/// possible to the periods served), BS-prepaid-1 (daily schedules, D-11),
/// BS-entry-3 (exact totals).
/// INVARIANTS (W = months × MONTH_L, m = part.month_days, d = part.days):
/// 1. Not the last part: round(total × (before + k × MONTH_L / m) / W):
/// the monthly rate total/months times the days held over the days
@@ -1520,8 +1520,8 @@ fn round_to_unit<T: Units>(num: T, den: T, unit: T) -> Option<T> {
/// W), or any product overflows:
/// - SHOULD return None
/// - NEVER panic
/// BECAUSE a figure the books can't compute is refused (rules.md
/// B-28), and symbolic parts are not a calendar.
/// BECAUSE a figure the books can't compute is refused (
/// BS-entry-4), and symbolic parts are not a calendar.
/// 2. IF 12,000.00 over 12 months from Jan 1, through Dec 15 (the last
/// part, 31 days, before = 11 months):
/// - SHOULD be 11,000.00 + 1,000.00 × 15/31 = 11,483.87
@@ -1584,7 +1584,7 @@ pub fn prorated_through<T: Units>(
/// ```text
/// GOAL: one month's posting of a span spread by day (depreciation,
/// daily prepaid and deferred-revenue schedules).
/// SOURCE: docs/spec/rules.md B-15, B-16 (D-11), B-21; plan/served.md P3
/// SOURCE: BS-asset-1, BS-prepaid-1 (D-11), BS-entry-3; plan/served.md P3
/// defect 9 (one shared prorate_by_days, Kani: parts sum to the
/// total, each is days × rate within one unit, the last absorbs
/// the remainder).
@@ -1651,7 +1651,7 @@ pub fn prorate_by_days<T: Units>(
/// SOURCE: plan/served.md P3 "Settled in design" (2026-10-20): a month of
/// depreciation skipped is caught up in the month the run is made
/// (an immaterial miss; a material one is restated, ASC 250);
/// docs/spec/rules.md B-15.
/// BS-asset-1.
/// INVARIANTS:
/// 1. The result is >= 0.
/// 2. Whenever every posted[i] <= scheduled[i], posted[i] + result <=
@@ -1707,7 +1707,7 @@ pub fn catch_ups<T: Amount>(scheduled: &[T], posted: &[T], out: &mut [T]) -> Opt
/// ```text
/// GOAL: a disposal clears exactly what the schedule says was used up
/// through its day, whatever the runs posted.
/// SOURCE: docs/spec/rules.md B-15 (a disposed asset depreciates through
/// SOURCE: BS-asset-1 (a disposed asset depreciates through
/// its disposal day); Ledger::dispose_asset INVARIANT 1 (gain =
/// proceeds − book value at the disposal date).
/// ```
@@ -1737,7 +1737,7 @@ pub struct BasisFigures<T> {
/// ```text
/// GOAL: the three tax figures of an asset, each named for what it is,
/// from one function the register, the tools and the viewer share.
/// SOURCE: docs/spec/rules.md B-25: IRC §1012(a) (cost); IRC §723 (the
/// SOURCE: BS-asset-4: IRC §1012(a) (cost); IRC §723 (the
/// contributor's adjusted basis carries over); Treas. Reg.
/// §1.168(i)-4(b)(1) (property converted from personal use: "the
/// lesser of its fair market value or its adjusted depreciable
@@ -1782,12 +1782,12 @@ pub fn basis_figures<T: Amount>(
}
/// A project's unrecovered cost from its tagged revenue and expenses to
/// date: what it would take to be repaid in full (rules.md B-37 item 4).
/// date: what it would take to be repaid in full (BS-statement-5 item 4).
///
/// ```text
/// GOAL: the "if repaid" figure of work done on spec, from one function
/// the tools, the viewer and bookspec share.
/// SOURCE: docs/spec/rules.md B-37 item 4 (ASC 450-30-25-1: a hoped-for
/// SOURCE: BS-statement-5 item 4 (ASC 450-30-25-1: a hoped-for
/// payment is a gain contingency, never recorded before it is
/// received; so this is a figure, never a receivable).
/// INVARIANTS:
@@ -1826,7 +1826,7 @@ pub enum Bounds {
/// ```text
/// GOAL: one definition of "a document is never overpaid and never owes
/// more than it is for", at every date, not only at the end.
/// SOURCE: docs/spec/rules.md B-38 INVARIANT 2 (0 <= outstanding(d, D)
/// SOURCE: BS-arap-2 INVARIANT 2 (0 <= outstanding(d, D)
/// <= total(d) at every D); plan/served.md P4b.3 (Bounds).
/// INVARIANTS:
/// 1. Within exactly when every prefix sum of `deltas` is within
@@ -1873,7 +1873,7 @@ fn out_of_bounds<T: Amount>(total: T, running: T) -> Option<(T, bool)> {
/// GOAL: a command never puts a document out of bounds, yet books an
/// earlier version left out of bounds (a void under a payment that
/// stands) take the step that mends them.
/// SOURCE: docs/spec/rules.md B-38 INVARIANT 2, B-28 (replay accepts what
/// SOURCE: BS-arap-2 INVARIANT 2, BS-entry-4 (replay accepts what
/// was written; the bound is the commands'); plan/served.md
/// P4b.14 item 3 (the remedy: reverse the payment).
/// INVARIANTS:
@@ -1918,7 +1918,7 @@ pub fn bounds_kept<T: Amount>(total: T, before: &[T], after: &[T]) -> Bounds {
mod tests {
use super::*;
/// rules.md B-14 rule 3, by hand. Equipment 1,000 for 300 cash and a
/// BS-statement-3 rule 3, by hand. Equipment 1,000 for 300 cash and a
/// 700 note: investing takes the 300, the note's 700 and the rest of
/// the equipment's are the noncash part.
#[test]
@@ -1964,7 +1964,7 @@ mod tests {
assert_eq!(apply_cash(10, &[-3], &mut out), None);
}
/// The exchange measure (rules.md B-14 rule 7) on the review's
/// The exchange measure (BS-statement-3 rule 7) on the review's
/// hand-checked cases.
#[test]
fn exchanged_matches_the_hand_checked_cases() {
@@ -1986,7 +1986,7 @@ mod tests {
assert_eq!(exchanged(1000i64, 1000, 1000, 1000), Some(0));
}
/// rules.md B-14 rule 11 (D-42), by hand.
/// BS-statement-3 rule 11 (D-42), by hand.
#[test]
fn constructive_pays_and_receives_for_the_company() {
use OnBehalf::{Paid, Received};
@@ -2339,7 +2339,7 @@ mod tests {
assert!(!i64::MIN.in_line_range());
}
/// B-9: a reversal flips every side and keeps accounts and amounts, so
/// BS-ledger-5: a reversal flips every side and keeps accounts and amounts, so
/// with the original it nets every account to zero.
#[test]
fn a_reversal_flips_every_line_and_nets_to_zero() {
+2 -2
View File
@@ -54,7 +54,7 @@ use rust_decimal::Decimal;
/// from ISO 4217), and its CHOICE BS-ledger-14
/// "book-in-the-smallest-unit" (the owner, 2026-10-13: book in
/// the smallest unit, half away from zero); wanderbooks
/// docs/spec/claims/ledger.md B-3 states the same pick. The
/// docs/spec/claims/ledger.md BS-ledger-1 states the same pick. The
/// rounding itself is kernel::round_step (BS-ledger-1,
/// BS-entry-3); owner decision D-69 (the laws live once, in
/// bookspec's Lean).
@@ -102,7 +102,7 @@ pub fn fx_booked<T: Amount>(foreign: T, rate: T, step: T, mode: Rounding) -> Opt
/// [`fx_booked`] at a currency's minor unit, on `Decimal`: the spelling
/// `Ledger::add_line_fx` books through. A currency ISO 4217 gives no
/// minor unit (gold, SDRs) books the exact product, as `round_minor`
/// has always done (B-3). The result's scale is the pre-kernel
/// has always done (BS-ledger-1). The result's scale is the pre-kernel
/// computation's: `round_places` keeps an amount already at or under
/// the minor places unchanged, and otherwise carries exactly the minor
/// places (a booked 1.50 prints "1.50", never "1.5000").
+19 -19
View File
@@ -12,54 +12,54 @@
//! `docs/spec/rules.md`):
//!
//! * a line's signed amount is `+amount` for a debit, `-amount` for a credit
//! (B-2);
//! (BS-entry-2);
//! * an entry is acceptable when it has two or more lines, every amount is
//! positive and in range, and its debits equal its credits exactly (B-1,
//! B-2, B-21);
//! * an acceptable entry nets to zero, account by account summed (B-1);
//! positive and in range, and its debits equal its credits exactly (BS-entry-1,
//! BS-entry-2, BS-entry-3);
//! * an acceptable entry nets to zero, account by account summed (BS-entry-1);
//! * a reversal flips every side, so it is acceptable exactly when the
//! original is, and the two together net every account to zero (B-9);
//! original is, and the two together net every account to zero (BS-ledger-5);
//! * an account's balance is its movement read on its normal side, so the
//! balances satisfy the accounting equation whenever movements net to
//! zero (B-5, B-7);
//! zero (BS-ledger-3, BS-statement-2);
//! * a trial balance puts each movement in exactly one column, so its
//! columns differ by the net of all movements (B-6);
//! * a closing line zeroes the account it closes (B-11);
//! columns differ by the net of all movements (BS-statement-1);
//! * a closing line zeroes the account it closes (BS-period-1);
//! * a payment to a vendor splits, line by line, into what counts toward
//! its 1099, what a card or payment network paid, and what is unknown,
//! and money moved between the company's own sources nets out (B-19);
//! and money moved between the company's own sources nets out (BS-1099-1);
//! * an early-payment discount never exceeds its stated percentage of the
//! total, and a document line's amount is exactly its quantity times its
//! unit price, neither rounded (B-39);
//! unit price, neither rounded (BS-arap-3);
//! * an allocation's parts sum to the whole, to the last unit, by largest
//! remainder (B-13);
//! remainder (BS-partner-1);
//! * a cumulative allocation hands out exactly the new amount, and leaves
//! each running total one allocation of everything allocated, so it never
//! drifts a unit from its exact share (B-13);
//! drifts a unit from its exact share (BS-partner-1);
//! * an entry's cash is applied to the sections of the statement of cash
//! flows moving against it, in a fixed order, each up to its own
//! movement: the parts sum to the entry's cash, what no cash settled sums
//! to zero, and a reversal's parts are the original's negated (B-14);
//! to zero, and a reversal's parts are the original's negated (BS-statement-3);
//! * what a member or lender paid or received for the company, with no
//! cash account moving, is split among the kinds it settled, netting to
//! zero, and mirrored by a reversal (B-14 rule 11);
//! zero, and mirrored by a reversal (BS-statement-3 rule 11);
//! * a party's part of an entry is signed as a line on the party's own
//! account would be, a reversal's is its original's negated, and what of
//! it counts as money or as property never exceeds it (B-35);
//! * a span prorated by days (depreciation, B-15; daily schedules, B-16)
//! it counts as money or as property never exceeds it (BS-partner-3);
//! * a span prorated by days (depreciation, BS-asset-1; daily schedules, BS-prepaid-1)
//! splits into parts that sum to its total, each but the last its days
//! times the monthly rate within one unit, the last the remainder;
//! * a catch-up run brings the books to the schedule without ever carrying
//! more than it says at a month end already posted (B-15), and a
//! more than it says at a month end already posted (BS-asset-1), and a
//! disposal trues what the books carry up or down to the schedule;
//! * an asset's basis figures follow from its basis rule and facts: the
//! §723 basis is the contributor's adjusted basis, the depreciable basis
//! the cost, that basis, or the lesser of it and fair market value, and
//! the §704(c) built-in gain is fair market value less the §723 basis
//! (B-25);
//! (BS-asset-4);
//! * a tax category's deductible amount adds its accounts' exact shares and
//! rounds once to the cent, half away from zero, never share by share
//! (B-32, B-21).
//! (BS-ledger-11, BS-entry-3).
//!
//! The kernel is a module directory so each kernel-sweep unit adds its
//! arithmetic in a file of its own (`fx`, `round`, `allocate`, `total`,
+6 -6
View File
@@ -14,7 +14,7 @@ use rust_decimal::Decimal;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Rounding {
/// Nearest multiple; an exact half rounds away from zero
/// (2.5 -> 3, -2.5 -> -3). The FX booking rule (B-3).
/// (2.5 -> 3, -2.5 -> -3). The FX booking rule (BS-ledger-1).
HalfAwayFromZero,
/// Nearest multiple; an exact half rounds to the even multiple
/// (2.5 -> 2, 3.5 -> 4). Rust's `Decimal::round_dp`.
@@ -30,12 +30,12 @@ pub enum Rounding {
/// ```text
/// GOAL: one rounding primitive: money is rounded to a whole multiple of a
/// unit, once, with the mode named at the call.
/// SOURCE: docs/spec/claims/ledger.md B-3 (a ledger in one money holds no
/// SOURCE: docs/spec/claims/ledger.md BS-ledger-1 (a ledger in one money holds no
/// fractions of its smallest unit; FX books the base currency's
/// minor unit, half away from zero), claims/entry.md B-21 (exact
/// minor unit, half away from zero), claims/entry.md BS-entry-3 (exact
/// amounts in the books; round only where a rule says to), and
/// claims/ledger.md B-32; the call sites' own rules (B-13, B-14,
/// B-15, B-16, B-19, B-35, B-36, B-37); owner decision D-69 (the
/// claims/ledger.md BS-ledger-11; the call sites' own rules (BS-partner-1, BS-statement-3,
/// BS-asset-1, BS-prepaid-1, BS-1099-1, BS-partner-3, BS-partner-4, BS-statement-5); owner decision D-69 (the
/// laws live once, in bookspec's Lean).
/// INVARIANTS:
/// 1. Some(r) is a whole multiple of step: r = n x step for an integer
@@ -96,7 +96,7 @@ pub fn round_places(amount: Decimal, places: u32, mode: Rounding) -> Option<Deci
/// `amount` rounded to whole `currency` minor units in `mode`: cents for
/// USD, whole yen for JPY, thousandths for KWD. A currency ISO 4217 gives
/// no minor unit (gold, SDRs) is returned exactly, as the FX booking rule
/// has always done (B-3).
/// has always done (BS-ledger-1).
pub fn round_minor(amount: Decimal, currency: Currency, mode: Rounding) -> Option<Decimal> {
match currency.minor_units() {
Some(places) => round_places(amount, places, mode),
+5 -5
View File
@@ -3,7 +3,7 @@
//! The sum of a collection of money figures, in one place. A raw `Decimal`
//! `+`, `+=` or `.sum()` panics at `Decimal::MAX`; these return `None`
//! instead, so the caller can refuse with `TooLargeToCompute` and never
//! crash a book (rules.md B-28: a replayed journal line is accepted "of
//! crash a book (BS-entry-4: a replayed journal line is accepted "of
//! any size", so a restored figure is the realistic path to the edge).
//! The signed sum of `(Side, amount)` lines is [`super::net`] and the pair
//! of columns [`super::totals`]; they were here first and stay the one
@@ -17,8 +17,8 @@ use super::Amount;
/// ```text
/// GOAL: a book's or report's total is the exact sum of its figures, or
/// refused; no total is ever rounded, wrapped or a crash.
/// SOURCE: docs/spec/rules.md B-21 (amounts are exact; rounding is
/// confined to returns), B-28 (replayed lines are accepted "of any
/// SOURCE: BS-entry-3 (amounts are exact; rounding is
/// confined to returns), BS-entry-4 (replayed lines are accepted "of any
/// size"; no input may reach a panic); bookspec BS-entry-3,
/// BS-entry-4; CONVENTION.
/// INVARIANTS:
@@ -49,7 +49,7 @@ pub fn total<T: Amount>(values: impl IntoIterator<Item = T>) -> Option<T> {
/// ```text
/// GOAL: the sum of a mapped field (a row's amount, a member's share) is
/// the exact sum of the mapping, or refused.
/// SOURCE: docs/spec/rules.md B-21, B-28; bookspec BS-entry-3,
/// SOURCE: BS-entry-3, BS-entry-4; bookspec BS-entry-3,
/// BS-entry-4; CONVENTION.
/// INVARIANTS:
/// 1. total_of(items, f) = total(f(item) for item in items), exactly.
@@ -69,7 +69,7 @@ pub fn total_of<T: Amount, I>(
/// ```text
/// GOAL: the sum of a derived figure (a column's contributions less its
/// distributions) is exact, or refused.
/// SOURCE: docs/spec/rules.md B-21, B-28; bookspec BS-entry-3,
/// SOURCE: BS-entry-3, BS-entry-4; bookspec BS-entry-3,
/// BS-entry-4; CONVENTION.
/// INVARIANTS:
/// 1. total_try(items, f) = Some(Σ f(item)) exactly when every f(item)
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -63,7 +63,7 @@ impl Currency {
/// code ISO 4217 gives none (gold, SDRs), the most a line may carry
/// (kernel::MAX_LINE_SCALE). Every posted amount is then a whole number
/// of the unit split to, so no member's running share is ever a unit
/// from exact (rules.md B-13); split to cents, a finer amount's
/// from exact (BS-partner-1); split to cents, a finer amount's
/// leftover fraction would all go to one member.
pub fn allocation_places(&self) -> u32 {
self.minor_units().unwrap_or(crate::kernel::MAX_LINE_SCALE)
@@ -156,7 +156,7 @@ impl Money {
/// The exact sum of some figures ([`crate::kernel::total`]), or
/// `TooLargeToCompute` naming `what` when a running sum cannot be held:
/// the engine's way to total a column without a raw `.sum()` that would
/// panic at `Decimal::MAX` (rules.md B-21, B-28).
/// panic at `Decimal::MAX` (BS-entry-3, BS-entry-4).
pub fn sum_exact(
values: impl IntoIterator<Item = Decimal>,
what: &str,
@@ -213,7 +213,7 @@ impl fmt::Debug for Money {
/// GOAL: depreciation and daily schedules round to the currency's own
/// smallest unit (cents, whole yen, thousandths of a dinar), never a
/// fixed two places.
/// SOURCE: docs/spec/rules.md B-3 (no fraction of the minor unit; ISO 4217,
/// SOURCE: BS-ledger-1 (no fraction of the minor unit; ISO 4217,
/// sources/iso-4217.md).
/// INVARIANTS:
/// 1. amount = units × 10^-scale exactly; unit = 10^(scale − minor).
+22 -22
View File
@@ -32,7 +32,7 @@
//! not placeholders, payables or payroll withholdings: what the
//! company owes that party itself on (a card's issuer, a loan's
//! lender, a member for what the members advanced). A credit to one
//! never counts as paying that party (rules.md B-35; DECISION, owner,
//! never counts as paying that party (BS-partner-3; DECISION, owner,
//! 2026-10-20).
//! ```
@@ -305,7 +305,7 @@ impl Party {
/// GOAL: one answer to "which TIN is on file for them?" wherever the
/// books show a last four (defect 11: the directory showed a
/// member's as missing because it read W-9 facts only).
/// SOURCE: rules.md B-26 (Treas. Reg. §301.6109-4(a): a truncated TIN
/// SOURCE: BS-partner-2 (Treas. Reg. §301.6109-4(a): a truncated TIN
/// shows its last four); INVARIANT 2a (DECISION, owner,
/// 2026-10-15: the two never disagree, so either answers).
/// SCENARIOS:
@@ -321,7 +321,7 @@ impl Party {
/// ```
pub fn tin_last4(&self) -> Option<&str> {
// Exactly four digits or nothing, however the facts were built
// (the setters check it; this never shows more, B-26).
// (the setters check it; this never shows more, BS-partner-2).
let four = |s: &str| s.len() == 4 && s.chars().all(|c| c.is_ascii_digit());
self.tin
.as_ref()
@@ -596,9 +596,9 @@ std::thread_local! {
/// ```text
/// GOAL: books an earlier version wrote open, forever, however a later
/// version widens what reads as a full TIN.
/// SOURCE: rules.md B-28 ("Replay accepts every line an earlier version
/// SOURCE: BS-entry-4 ("Replay accepts every line an earlier version
/// accepted": the bounds are the commands', never replay's);
/// B-26 (no full TIN in the books).
/// BS-partner-2 (no full TIN in the books).
/// INVARIANTS:
/// 1. Within it, a text is refused only if P2's detector
/// ([`journaled_tin_runs`]) refuses it: every name, reason and fact
@@ -625,8 +625,8 @@ pub fn replaying<T>(f: impl FnOnce() -> T) -> T {
/// Whether a journaled line is being replayed now ([`replaying`]): the
/// rules a later version added that refuse new work (the control guard,
/// a document's bounds, rules.md B-38) never refuse a line an earlier
/// version accepted (B-28).
/// a document's bounds, BS-arap-2) never refuse a line an earlier
/// version accepted (BS-entry-4).
pub fn is_replaying() -> bool {
REPLAYING.with(std::cell::Cell::get)
}
@@ -681,7 +681,7 @@ fn journaled_tin_runs(chars: &[char]) -> Vec<(usize, usize)> {
/// `text` with every run [`has_full_tin`] finds masked: each of its
/// digits becomes `•`, separators kept. For refusals that quote what they
/// were given, so no error echoes a full TIN (docs/spec/rules.md B-26).
/// were given, so no error echoes a full TIN (BS-partner-2).
pub fn redact_full_tins(text: &str) -> std::borrow::Cow<'_, str> {
let mut chars: Vec<char> = text.chars().collect();
let runs = full_tin_runs(&chars);
@@ -828,7 +828,7 @@ impl PartyField {
];
/// Whether `field` is a field this version knows. A `party.updated`
/// naming another was written by a newer version (rules.md B-27).
/// naming another was written by a newer version (BS-format-1).
pub fn known_field(field: &str) -> bool {
Self::FIELDS.contains(&field)
}
@@ -850,7 +850,7 @@ impl PartyField {
}
}
/// Which of a party's totals to report (rules.md B-35 item 4). Not the
/// Which of a party's totals to report (BS-partner-3 item 4). Not the
/// books' accounting method (`books.accounting_basis`): party totals count
/// what moved, whichever method the books keep.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
@@ -928,7 +928,7 @@ impl Activity {
}
}
/// The accounts [`entry_flow`] reads money from (rules.md B-35, defect
/// The accounts [`entry_flow`] reads money from (BS-partner-3, defect
/// 24): the cash accounts (every asset account but receivables when none
/// are given), and the money liabilities: the cards ([`card_accounts`]),
/// what the members advanced and loans (`books.financing_accounts`).
@@ -949,8 +949,8 @@ impl MoneyAccounts {
/// what the company owes a party itself never counts as paying it (a
/// fee charged on its own card, interest added to its own loan,
/// equipment bought on its own note, a distribution still owed to a
/// member), and a debit to it is what the money paid for (rules.md
/// B-35; DECISION, owner, 2026-10-20).
/// member), and a debit to it is what the money paid for (
/// BS-partner-3; DECISION, owner, 2026-10-20).
pub fn for_parties(
&self,
ledger: &crate::Ledger,
@@ -981,8 +981,8 @@ impl MoneyAccounts {
/// ```text
/// GOAL: a card is known from what the books record, and a promise (a
/// gift card sold) or a member's own card is never the company's.
/// SOURCE: rules.md B-35 item 5 (DECISION, owner, 2026-10-20: money is
/// cash, cards, the members' financing and loans), B-19 (payment
/// SOURCE: BS-partner-3 item 5 (DECISION, owner, 2026-10-20: money is
/// cash, cards, the members' financing and loans), BS-1099-1 (payment
/// methods, plan P3 defect 12).
/// INVARIANTS:
/// 1. When the books record a business-card payment method: exactly
@@ -1148,7 +1148,7 @@ pub fn entry_flow(
) -> Result<EntryFlow, crate::LedgerError> {
use crate::Side;
use rust_decimal::Decimal;
// A draft's lines are as journaled, of any size (rules.md B-28): every
// A draft's lines are as journaled, of any size (BS-entry-4): every
// sum is checked, and one past exact arithmetic is refused.
let too_large =
|| crate::LedgerError::TooLargeToCompute(format!("entry {}'s money flow", entry.id()));
@@ -1256,14 +1256,14 @@ pub fn entry_flow(
/// The money an entry moved with the parties it names, and what for,
/// read as party figures read it: a reversal's is exactly its original's
/// negated (B-9), never re-read from its own lines; and a liability owed
/// negated (BS-ledger-5), never re-read from its own lines; and a liability owed
/// to a party named is not money for the entry
/// ([`MoneyAccounts::for_parties`]).
///
/// ```text
/// GOAL: what a party's entry paid for, right for reversals too.
/// SOURCE: rules.md B-9 ("a mistake is corrected by an opposite entry"),
/// B-35.
/// SOURCE: BS-ledger-5 ("a mistake is corrected by an opposite entry"),
/// BS-partner-3.
/// INVARIANTS:
/// 1. An entry reversing none: entry_flow of its lines, with
/// money.for_parties(the parties of `shares`).
@@ -1327,8 +1327,8 @@ pub fn activity(
/// get from them?" for the MCP server and the viewer alike, right
/// when an entry was with several parties, for property as well as
/// money, and for reversals.
/// SOURCE: docs/parties-and-attachments.md (Parties, Shares); rules.md
/// B-35 (DECISION, owner, 2026-10-15 and 2026-10-20).
/// SOURCE: docs/parties-and-attachments.md (Parties, Shares);
/// BS-partner-3 (DECISION, owner, 2026-10-15 and 2026-10-20).
/// INVARIANTS:
/// 1. entries: every entry Ledger::entry_parties names the party in
/// (hand tags, vendor tags, bills and their payments, invoices and
@@ -1376,7 +1376,7 @@ pub fn activity_with(
}
let shares = ledger.entry_parties(id);
// The target first: an entry that counts nothing is never
// unresolved for shares that don't fit it (rules.md B-35 item 4).
// unresolved for shares that don't fit it (BS-partner-3 item 4).
let Ok(t) = crate::shares::target(ledger, id, shares, money) else {
a.unresolved.insert(id);
continue;
+1 -1
View File
@@ -86,7 +86,7 @@ pub type PayoutPlanLine = (AccountId, Side, Decimal, Option<ClassId>);
/// collected; fees debit expense accounts), and the payout reconciles to
/// the cent.
/// A zero deposit (fees and adjustments ate the sales exactly) has no
/// deposit line: every planned line is positive (B-2, docs/spec/rules.md).
/// deposit line: every planned line is positive (BS-entry-2, docs/spec/rules.md).
pub fn payout_plan(
payout: &Payout,
chart: &ChartOfAccounts,
+2 -2
View File
@@ -50,7 +50,7 @@ impl PayrollLine {
/// Gross minus all employee withholdings and deductions. Must be >= 0:
/// you cannot withhold more than the employee earned. Refused
/// (TooLargeToCompute), never a panic, past exact arithmetic: a run is
/// restored as journaled (rules.md B-28).
/// restored as journaled (BS-entry-4).
pub fn net_pay(&self) -> Result<Decimal, LedgerError> {
[
self.federal_withholding,
@@ -133,7 +133,7 @@ pub fn validate_payroll_lines(lines: &[PayrollLine]) -> Result<(), LedgerError>
/// Every amount of every line no larger than a journal line may be
/// (kernel::MAX_LINE_AMOUNT, ten decimal places), so net pay and the run's
/// totals are exact (P0 review round 3, S1). For new runs only: replay
/// restores a run as journaled (rules.md B-28).
/// restores a run as journaled (BS-entry-4).
pub fn check_payroll_ranges(lines: &[PayrollLine]) -> Result<(), LedgerError> {
for line in lines {
for amount in [
+9 -9
View File
@@ -56,7 +56,7 @@ pub enum CloseTo {
/// gives a member their share of everything closed to the members so
/// far, to the currency's minor unit, less what earlier closes gave
/// them, so no member is ever a minor unit from their exact share
/// (rules.md B-13; D-10). What new closes are made with; the books
/// (BS-partner-1; D-10). What new closes are made with; the books
/// journal it as [`CloseTo::MembersCumulative`].
Members(Vec<MemberClose>),
/// [`CloseTo::Members`] as journaled: the count of members closes
@@ -130,7 +130,7 @@ pub fn allocate(
/// [`allocate`], refusing with `TooLargeToCompute` instead of panicking
/// when a share of `amount` is beyond exact arithmetic (a replayed close
/// carries a journaled amount of any size, rules.md B-28). The same split,
/// carries a journaled amount of any size, BS-entry-4). The same split,
/// to the cent, for every amount [`allocate`] accepts.
pub fn try_allocate(
amount: rust_decimal::Decimal,
@@ -177,7 +177,7 @@ pub fn allocate_last_absorbs(
/// [`allocate_last_absorbs`], refusing with `TooLargeToCompute` instead of
/// panicking when `amount × share` or the plug is beyond exact arithmetic
/// (replay of a legacy close with a huge journaled amount, rules.md B-28).
/// (replay of a legacy close with a huge journaled amount, BS-entry-4).
/// The same split, to the cent, for every amount [`allocate_last_absorbs`]
/// accepts: this is the frozen rule, only its overflow now an error.
pub fn try_allocate_last_absorbs(
@@ -205,22 +205,22 @@ pub fn try_allocate_last_absorbs(
/// ([`crate::Currency::allocation_places`]) instead of cents, less what
/// earlier closes gave each member (`given`, in the order of `shares`).
/// Each member's running total is then one split of the running total
/// (rules.md B-13; [`crate::kernel::apportion_cumulative`]). A loss is
/// (BS-partner-1; [`crate::kernel::apportion_cumulative`]). A loss is
/// the negation of the same gain: it splits |total| against `given`
/// negated, then negates.
///
/// ```text
/// GOAL: no member's running share of earnings is ever a minor unit from
/// their exact share, whatever earlier closes gave them.
/// SOURCE: docs/spec/rules.md B-13 (26 U.S.C. §704(a); Treas. Reg.
/// SOURCE: BS-partner-1 (26 U.S.C. §704(a); Treas. Reg.
/// §1.704-1(b)(2)(iv)(b); largest remainder: DECISION, owner
/// 2026-10-13; from the first close: D-10); B-3 (the minor unit).
/// 2026-10-13; from the first close: D-10); BS-ledger-1 (the minor unit).
/// INVARIANTS:
/// 1. The parts MUST sum to total − Σ given exactly.
/// 2. given[i] + part[i] MUST be member i's largest-remainder split of
/// total to `places` (ties to the earlier member): one split.
/// 3. So when total is a whole number of units of `places` (every posted
/// line is at its currency's allocation_places: its minor unit, B-3,
/// line is at its currency's allocation_places: its minor unit, BS-ledger-1,
/// or for a currency without one the finest a line carries),
/// |given[i] + part[i] − total × share[i]| is under one unit (Lean
/// allocW_drift, cumulative_drift; Kani
@@ -326,7 +326,7 @@ pub struct Period {
/// What a close under the run rule ([`CloseTo::MembersRun`], journaled
/// `"cumulative"`) allocated, once closed that way. Only those closes
/// have one: its serialized form is what earlier versions wrote, and
/// stays so (rules.md B-28). Every members close's split, under any
/// stays so (BS-entry-4). Every members close's split, under any
/// rule, is [`Period::members_closed`].
#[serde(default)]
pub member_close: Option<MemberCloseRecord>,
@@ -415,7 +415,7 @@ impl Period {
/// Validate a period's date range before creation.
/// [`validate_period_order`], and both ends inside the calendar the books
/// keep (crate::calendar; P0 review round 3, S1). For new periods; replay
/// checks only the order (rules.md B-28).
/// checks only the order (BS-entry-4).
pub fn validate_period_range(start: NaiveDate, end: NaiveDate) -> Result<(), LedgerError> {
crate::calendar::check(start)?;
crate::calendar::check(end)?;
+20 -20
View File
@@ -460,7 +460,7 @@ fn closing_entry_balances() {
}
// ---------------------------------------------------------------------------
// 1099 payments (rules.md B-19)
// 1099 payments (BS-1099-1)
// ---------------------------------------------------------------------------
fn any_role() -> kernel::PayRole {
@@ -485,7 +485,7 @@ fn any_tag() -> kernel::Tag {
}
}
/// `kernel::payment_bucket` is the B-19 table, all 16 cases: a tag naming
/// `kernel::payment_bucket` is the BS-1099-1 table, all 16 cases: a tag naming
/// the line's account decides (card or network: Card; otherwise Counts);
/// else the role does, and with no tag naming its account a financing line
/// never counts and a card account's line is always Card.
@@ -726,7 +726,7 @@ fn apportion_cumulative_is_exact() {
/// `cumulative_drift` carry any weights and any amounts).
const DRIFT: i64 = 1 << 12;
/// **Bounded drift** (rules.md B-13) for members with these integer
/// **Bounded drift** (BS-partner-1) for members with these integer
/// weights (shares w_i / W, W their sum): a cumulative members close,
/// modelled as `periods::allocate_cumulative` runs it at whole minor units
/// (unit 1), hands out exactly its net, and leaves every member's running
@@ -968,7 +968,7 @@ fn apply_cash_mirrors() {
/// An accepted entry always has cash flows, and they explain its cash
/// exactly: the sections' cash sums to the entry's cash, and what no cash
/// settled (each section's movement plus its cash) sums to zero
/// (rules.md B-14 rules 3 and 9: the statement foots, entry by entry).
/// (BS-statement-3 rules 3 and 9: the statement foots, entry by entry).
#[kani::proof]
#[kani::unwind(5)]
fn entry_flows_sum_to_cash() {
@@ -1043,7 +1043,7 @@ fn entry_flows_are_bounded() {
/// A reversal's cash flows are its original's, negated, part by part:
/// what lets an entry and its reversal in one period drop out of the
/// statement together (rules.md B-14 rule 6). End to end, on entries of
/// statement together (BS-statement-3 rule 6). End to end, on entries of
/// up to two lines: at three (`NF`) one run went past half an hour at
/// four jobs on a busy machine (2026-10-21), so three lines are proved in
/// two halves, `entry_movements_of_a_reversal_mirror` and
@@ -1227,8 +1227,8 @@ fn any_way() -> kernel::OnBehalf {
}
}
/// What a member or a lender paid or received for the company (rules.md
/// B-14 rule 11, D-42) invents and loses nothing: the parts net to zero,
/// What a member or a lender paid or received for the company (
/// BS-statement-3 rule 11, D-42) invents and loses nothing: the parts net to zero,
/// so an entry's flows still sum to its cash; each part settles its own
/// movement toward zero, never past it; and as much is settled as can be.
#[kani::proof]
@@ -1276,7 +1276,7 @@ fn constructive_nets_to_zero() {
/// The other way, minus the sources and minus the uses give minus the
/// parts: a reversal of a payment made on the company's behalf mirrors it
/// (rules.md B-14 rule 6), so the two drop out together.
/// (BS-statement-3 rule 6), so the two drop out together.
#[kani::proof]
#[kani::unwind(4)]
fn constructive_mirrors() {
@@ -1300,7 +1300,7 @@ fn constructive_mirrors() {
}
// ---------------------------------------------------------------------------
// A party's part of an entry (rules.md B-35)
// A party's part of an entry (BS-partner-3)
// ---------------------------------------------------------------------------
/// The inputs `kernel::party_target` reads, any in range: a capital
@@ -1320,7 +1320,7 @@ fn any_party_inputs() -> (Option<(i64, i64)>, i64, i64, i64) {
(capital, any_amount(), any_amount(), debits)
}
/// B-35 items 1-4: the direction is the sign of what counts (paid above
/// BS-partner-3 items 1-4: the direction is the sign of what counts (paid above
/// zero, received below), neither exactly when nothing counts; cash and
/// in kind each carry the whole's sign and together never exceed it; a
/// money target is all cash; a contribution counts all of itself; a
@@ -1374,7 +1374,7 @@ fn party_target_direction_is_its_sign() {
);
}
/// B-35 item 3 and B-9: the target is odd. Negating the lines negates the
/// BS-partner-3 item 3 and BS-ledger-5: the target is odd. Negating the lines negates the
/// capital movement, the money net and the own-account movement, and the
/// property comes from the other side, so it keeps its size: the result
/// is the original's reverse_target, whenever it isn't the debits fallback
@@ -1409,7 +1409,7 @@ fn party_target_is_odd() {
);
}
/// B-9: reversing a reversal gives the original back, and reverse_target
/// BS-ledger-5: reversing a reversal gives the original back, and reverse_target
/// never panics: past the range it refuses.
#[kani::proof]
fn reverse_target_is_an_involution() {
@@ -1438,7 +1438,7 @@ fn reverse_target_is_an_involution() {
}
// ---------------------------------------------------------------------------
// Proration by days (depreciation, B-15; daily schedules, B-16)
// Proration by days (depreciation, BS-asset-1; daily schedules, BS-prepaid-1)
// ---------------------------------------------------------------------------
/// Most month parts the proration harnesses explore.
@@ -1687,7 +1687,7 @@ fn prorated_through_refuses_malformed_input() {
}
// ---------------------------------------------------------------------------
// Catching up and truing up (B-15)
// Catching up and truing up (BS-asset-1)
// ---------------------------------------------------------------------------
/// A catch-up run posts max(0, min gap), never negative, and never carries
@@ -1753,7 +1753,7 @@ fn true_up_reaches_the_target() {
kani::cover!(down > 0, "depreciation past the day, credited back");
}
/// `kernel::basis_figures` (rules.md B-25), for every rule and every
/// `kernel::basis_figures` (BS-asset-4), for every rule and every
/// cost, adjusted basis and value within the bounds: a purchase
/// depreciates from cost with no §723 basis or built-in gain; a
/// contribution's §723 basis is the adjusted basis and its built-in gain
@@ -1797,7 +1797,7 @@ fn basis_figures_laws() {
);
}
/// `kernel::unrecovered_cost` (rules.md B-37 item 4), for every revenue
/// `kernel::unrecovered_cost` (BS-statement-5 item 4), for every revenue
/// and expense a line could carry: never below zero; the shortfall when
/// expenses exceed revenue, else zero; never above max(expenses, 0) when
/// revenue isn't negative (expenses may be negative: a reimbursement
@@ -1819,7 +1819,7 @@ fn unrecovered_cost_laws() {
kani::cover!(u == 0 && revenue > expenses, "repaid, and more");
}
/// `kernel::running_bounds` (rules.md B-38 INVARIANT 2; the bounds every
/// `kernel::running_bounds` (BS-arap-2 INVARIANT 2; the bounds every
/// document command and reversal checks), for every total and every
/// sequence of up to `N` dated movements a line could carry: it says
/// Within exactly when every running balance is in `0 ..= total`, and
@@ -1859,7 +1859,7 @@ fn bounds_check_matches_definition() {
}
/// `kernel::bounds_kept` (the check every document command and reversal
/// runs, rules.md B-38 INVARIANT 2): on books in bounds at every date it
/// runs, BS-arap-2 INVARIANT 2): on books in bounds at every date it
/// is the definition (`running_bounds` of the books after the step); and
/// whenever it says Within, no running balance after the step is further
/// outside `0 ..= total` than before it, so a step that mends books an
@@ -1996,7 +1996,7 @@ fn line_amount_is_exact() {
}
// ---------------------------------------------------------------------------
// Tax categories (B-32)
// Tax categories (BS-ledger-11)
// ---------------------------------------------------------------------------
/// `n / 100` rounded half away from zero: the reference for the one
@@ -2013,7 +2013,7 @@ fn round_cent(n: i64) -> Option<i64> {
}
}
/// `kernel::deductible_amount` (rules.md B-32, B-21; CHOICE, owner
/// `kernel::deductible_amount` (BS-ledger-11, BS-entry-3; CHOICE, owner
/// 2026-11-07, D-67) over up to three accounts in exact range: the exact
/// sum of the shares (`book × percent ÷ 100`) rounded once to the nearest
/// cent, ties away from zero; never the sum of per-account roundings; and
+20 -20
View File
@@ -47,7 +47,7 @@ impl TrialBalance {
///
/// ```text
/// GOAL: the trial balance over every posted entry (see trial_balance_as_of).
/// SOURCE: docs/spec/rules.md B-6; R-7.
/// SOURCE: BS-statement-1; R-7.
/// INVARIANTS:
/// 1. MUST equal trial_balance_as_of on or after the last entry's date.
/// 2. MUST balance (total debits == total credits).
@@ -63,7 +63,7 @@ pub fn trial_balance(ledger: &Ledger) -> TrialBalance {
/// ```text
/// GOAL: every account's balance, in a debit or a credit column, from the
/// posted entries dated on or before `as_of`.
/// SOURCE: docs/spec/rules.md B-6 (Pacioli ch. 36; IRS Pub. 583); R-7, R-9b.
/// SOURCE: BS-statement-1 (Pacioli ch. 36; IRS Pub. 583); R-7, R-9b.
/// INVARIANTS:
/// 1. MUST have total debits equal total credits, for any books built
/// through the Ledger commands.
@@ -191,7 +191,7 @@ pub struct ClassProfitAndLoss {
/// ```text
/// GOAL: a profit and loss per class (department, location, job), plus the
/// unclassified lines.
/// SOURCE: docs/spec/rules.md B-14; R-? Tracking classes.
/// SOURCE: BS-statement-3; R-? Tracking classes.
/// INVARIANTS:
/// 1. The per-class P&Ls (with unclassified) MUST sum to the whole P&L,
/// account by account (conservation).
@@ -452,7 +452,7 @@ fn statement_lines(
/// ```text
/// GOAL: revenue, expenses, and net income for the entries dated from
/// `start` through `end` (both inclusive), optionally one class's lines.
/// SOURCE: docs/spec/rules.md B-14, B-11; R-9.
/// SOURCE: BS-statement-3, BS-period-1; R-9.
/// INVARIANTS:
/// 1. MUST count only revenue and expense accounts, a line per account
/// with its normal-side amount, and net income = revenue - expenses.
@@ -533,7 +533,7 @@ fn profit_and_loss_counted(
))
}
/// A project's figures (rules.md B-37 item 3): the period's statement and
/// A project's figures (BS-statement-5 item 3): the period's statement and
/// months, and its figures to date.
#[derive(Clone, Debug)]
pub struct ProjectFigures {
@@ -563,7 +563,7 @@ impl ProjectFigures {
}
/// A project's figures to date: every posted revenue and expense line
/// tagged to it through `through`, whatever its dates (rules.md B-37).
/// tagged to it through `through`, whatever its dates (BS-statement-5).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProjectToDate {
/// The last day counted.
@@ -592,7 +592,7 @@ pub struct ProjectToDate {
impl ProjectToDate {
/// Revenue less expenses: the project's contribution before overhead
/// (rules.md B-37 item 7), since only its own tagged lines count.
/// (BS-statement-5 item 7), since only its own tagged lines count.
pub fn net(&self) -> Decimal {
self.revenue - self.expenses
}
@@ -611,11 +611,11 @@ impl ProjectToDate {
}
/// Contribution as a percent of revenue, to one place (half to even), or
/// `None` without revenue to divide by (rules.md B-37 item 7).
/// `None` without revenue to divide by (BS-statement-5 item 7).
///
/// ```text
/// GOAL: one margin the tools and the viewer print alike.
/// SOURCE: docs/spec/rules.md B-37 item 7 (revenue less the costs traced
/// SOURCE: BS-statement-5 item 7 (revenue less the costs traced
/// to the project, fixed and variable alike: Garrison's segment
/// margin, as a ratio; not Horngren's variable-cost contribution
/// margin; a presentation choice, not GAAP).
@@ -650,7 +650,7 @@ pub const PROJECT_MONTHS: u32 = 240;
/// ```text
/// GOAL: what a project earned and cost, from one function the tools, the
/// viewer and bookspec share, so their figures never drift.
/// SOURCE: docs/spec/rules.md B-37 item 3 (job costing), B-11, B-14.
/// SOURCE: BS-statement-5 item 3 (job costing), BS-period-1, BS-statement-3.
/// INVARIANTS:
/// 1. MUST be profit_and_loss_for_period with the project's class: only
/// revenue and expense lines tagged to it, closing entries left out.
@@ -748,7 +748,7 @@ pub fn project_to_date(
/// Every entry with a line tagged to the project (drafts included),
/// newest first (by date, then id), with its project amount: its tagged
/// revenue lines less its tagged expense lines, each on its normal side.
/// A tagged balance-sheet line counts zero (rules.md B-37 item 3).
/// A tagged balance-sheet line counts zero (BS-statement-5 item 3).
pub fn project_entries(ledger: &Ledger, id: ClassId) -> Vec<(crate::EntryId, Decimal)> {
let mut out: Vec<(NaiveDate, crate::EntryId, Decimal)> = Vec::new();
for eid in 1..ledger.next_entry_id() {
@@ -796,7 +796,7 @@ pub fn project_entries(ledger: &Ledger, id: ClassId) -> Vec<(crate::EntryId, Dec
///
/// ```text
/// GOAL: assets, liabilities, and equity as of a date, a line per account.
/// SOURCE: docs/spec/rules.md B-7 (CON 8 ¶E62), B-11; R-8.
/// SOURCE: BS-statement-2 (CON 8 ¶E62), BS-period-1; R-8.
/// INVARIANTS:
/// 1. MUST balance: assets = liabilities + equity + current earnings,
/// exactly.
@@ -917,7 +917,7 @@ pub struct GeneralLedger {
/// ```text
/// GOAL: every posting from `start` through `end`, by account in code
/// order, with running balances.
/// SOURCE: docs/spec/rules.md B-6; R-9a (the QuickBooks general ledger).
/// SOURCE: BS-statement-1; R-9a (the QuickBooks general ledger).
/// INVARIANTS:
/// 1. Each account MUST show its beginning balance (entries before
/// `start`), every posting in the range in date order, and an ending
@@ -1147,8 +1147,8 @@ pub fn cancelled_in_span(
/// GOAL: each member's capital roll-forward for a partnership over a
/// period: beginning, contributions, allocated net income, distributions,
/// ending; with a total.
/// SOURCE: docs/spec/rules.md B-13 (26 U.S.C. §704(a); Treas. Reg.
/// §1.704-1(b)(2)(iv)(b); Form 1065 Schedule M-2; D-38), B-11;
/// SOURCE: BS-partner-1 (26 U.S.C. §704(a); Treas. Reg.
/// §1.704-1(b)(2)(iv)(b); Form 1065 Schedule M-2; D-38), BS-period-1;
/// R-9c.
/// INVARIANTS:
/// 1. Each row MUST roll forward exactly: beginning + contributions +
@@ -1182,7 +1182,7 @@ pub fn cancelled_in_span(
/// 5. An entry dated `start` is period activity, not beginning capital.
/// 6. An entry and its reversal both dated in the span cancel
/// ([`cancelled_in_span`]): neither is a contribution or a
/// distribution, since the correction undoes the original (B-9: "it
/// distribution, since the correction undoes the original (BS-ledger-5: "it
/// is just as if you had written nothing"). A reversal whose original
/// is outside the span counts by side, like any entry.
/// SCENARIOS:
@@ -1501,7 +1501,7 @@ pub fn snapshot(ledger: &Ledger) -> Result<serde_json::Value, LedgerError> {
}
// ---------------------------------------------------------------------------
// Cash flow statement (direct method, rules.md B-14): see `crate::cashflow`.
// Cash flow statement (direct method, BS-statement-3): see `crate::cashflow`.
// ---------------------------------------------------------------------------
pub use crate::cashflow::{
@@ -1700,8 +1700,8 @@ pub fn register_row(
/// GOAL: one list of everything the company owns as a fixed asset: what,
/// which label, cost, depreciation due and posted, book value, tax
/// figures, and whether the books agree.
/// SOURCE: docs/spec/rules.md B-15 (depreciation), B-24 (the register
/// reconciles to the books), B-25 (tax figures beside book);
/// SOURCE: BS-asset-1 (depreciation), BS-asset-3 (the register
/// reconciles to the books), BS-asset-4 (tax figures beside book);
/// DECISION (owner, 2026-10-15): a fully featured asset register.
/// INVARIANTS:
/// 1. Rows: the assets acquired on or before as_of
@@ -1726,7 +1726,7 @@ pub fn register_row(
/// 5. Each row's tax fields are the asset's (Asset::basis_figures),
/// never re-derived here.
/// 6. NEVER panics: a contributor basis is as journaled, of any size
/// (rules.md B-28), and a total past exact arithmetic, or a schedule
/// (BS-entry-4), and a total past exact arithmetic, or a schedule
/// that can't be computed, is refused (TooLargeToCompute,
/// DateOutOfRange).
/// ```
+3 -3
View File
@@ -30,7 +30,7 @@ use chrono::NaiveDate;
pub struct DatedRule {
/// Plain name, e.g. "1099 reporting threshold".
pub name: &'static str,
/// Its entry in docs/spec/rules.md, e.g. "B-19".
/// Its entry in docs/spec/rules.md, e.g. "BS-1099-1".
pub catalog: &'static str,
/// The vendored official text it comes from (a path in this repo,
/// for the people who update the rule).
@@ -61,11 +61,11 @@ impl DatedRule {
}
}
/// The 1099-NEC / 1099-MISC reporting threshold (rules.md B-19): $600 for
/// The 1099-NEC / 1099-MISC reporting threshold (BS-1099-1): $600 for
/// payments through 2025, $2,000 in 2026, then indexed for inflation.
pub const THRESHOLD_1099: DatedRule = DatedRule {
name: "1099 reporting threshold",
catalog: "B-19",
catalog: "BS-1099-1",
source: "docs/spec/sources/irs-1099-thresholds.md",
authority: "26 U.S.C. §6041(a) and (h) and the IRS's yearly figure in the Instructions for Forms 1099-MISC and 1099-NEC (https://www.irs.gov/instructions/i1099mec)",
known_through: 2026,
+6 -6
View File
@@ -47,7 +47,7 @@ pub enum ScheduleKind {
/// How a schedule spreads its total over the time it covers.
///
/// ```text
/// SOURCE: docs/spec/rules.md B-16; plan/served.md D-11 (new schedules
/// SOURCE: BS-prepaid-1; plan/served.md D-11 (new schedules
/// daily, "matching depreciation"; existing ones stay
/// monthly_even), D-37 (owner, 2026-10-20: confirmed; an
/// equal-months schedule starts on the 1st of a month, for
@@ -173,7 +173,7 @@ pub const EXACT_LIMIT: Decimal =
/// 2. NEVER panics: a schedule an earlier version journaled whose months
/// run past chrono's last day is refused with DateOutOfRange, and one
/// whose amounts exact arithmetic can't hold with TooLargeToCompute
/// (rules.md B-28). `months` is at least 1 (validate_schedule_shape).
/// (BS-entry-4). `months` is at least 1 (validate_schedule_shape).
/// 3. NEVER rounds silently: a total of EXACT_LIMIT or more is refused
/// with TooLargeToCompute. Below it every amount in cents, and every
/// sum of them (none exceeds the total), fits Decimal's 28 significant
@@ -232,7 +232,7 @@ pub fn amortization_plan(
/// ```text
/// GOAL: recognize a prepaid expense, or earn deferred revenue, as each
/// day it covers passes.
/// SOURCE: docs/spec/rules.md B-16 (ASC 606-10-25-23: revenue as the
/// SOURCE: BS-prepaid-1 (ASC 606-10-25-23: revenue as the
/// obligation is satisfied; ASC 340-10-05-4: a prepaid is used up
/// over the time it covers); plan/served.md D-11, D-37.
/// INVARIANTS:
@@ -381,7 +381,7 @@ fn month_first(d: NaiveDate) -> NaiveDate {
/// [`validate_schedule`] without the total's range and minor-unit checks
/// added on 2026-10-13 or the calendar bound added in P0: the checks every
/// journaled `schedule.registered` passed when it was written, for
/// replaying journals written before them (rules.md B-28).
/// replaying journals written before them (BS-entry-4).
pub fn validate_schedule_shape(
new: &NewSchedule,
chart: &ChartOfAccounts,
@@ -585,7 +585,7 @@ pub fn validate_recurring(new: &NewRecurring, chart: &ChartOfAccounts) -> Result
/// The checks every journaled `recurring.registered` passed when it was
/// written (the rule through 2026-10-16): at least two lines, positive
/// amounts, postable accounts, balanced, and an end not before the start.
/// Replay applies exactly these (rules.md B-28). Sums too large for exact
/// Replay applies exactly these (BS-entry-4). Sums too large for exact
/// arithmetic are refused (TooLargeToCompute), never a panic.
pub fn validate_recurring_journaled(
new: &NewRecurring,
@@ -668,7 +668,7 @@ mod tests {
/// A schedule an earlier version journaled, at chrono's last month or
/// with Decimal's largest total: its plan is computed where it can be,
/// refused where it can't, never a panic (rules.md B-28).
/// refused where it can't, never a panic (BS-entry-4).
#[test]
fn plans_at_the_edges_are_computed_or_refused() {
assert_eq!(month_end(NaiveDate::MAX), NaiveDate::MAX);
+5 -5
View File
@@ -22,7 +22,7 @@
//! must hold together ([`Settings::check_whole`]), or none is made.
//! 3. Replay takes any value of the right shape ([`shape`]): a check a
//! later version tightens never makes older books unreadable
//! (rules.md B-28).
//! (BS-entry-4).
//! 4. A setting never holds a full TIN, except the company's own EIN
//! (`company.ein`, decided 2026-10-16, D-5): nine digits standing
//! alone, bare or printed the way an SSN or EIN is (3-2-4 or 2-7,
@@ -142,7 +142,7 @@ pub enum Kind {
/// A positive whole number (a day count, the first invoice number).
Count,
/// Payment terms, in their one canonical spelling ([`crate::Terms`],
/// rules.md B-39).
/// BS-arap-3).
Terms,
/// Payment methods (A-3): a list of `{kind, label, lines, link?, qr?}`.
PaymentMethods,
@@ -633,7 +633,7 @@ impl Company {
}
/// `policy.require_tax_category`: whether a revenue or expense account
/// must map to a line of the return (rules.md B-32; DECISION, owner,
/// must map to a line of the return (BS-ledger-11; DECISION, owner,
/// 2026-10-20: warn by default; a company may refuse).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum TaxCategoryPolicy {
@@ -723,7 +723,7 @@ pub fn holds_printed_tin(text: &str) -> bool {
/// EIN (2-7) forms count as there, but a bare run of nine digits joined
/// to a letter or to the URL punctuation `/ = ? & #` does not: it is an
/// id in a path or query (an app store listing's `id284882215`), not a
/// TIN someone wrote down (rules.md B-26).
/// TIN someone wrote down (BS-partner-2).
pub fn holds_printed_tin_in_link(text: &str) -> bool {
printed_tin(text, true)
}
@@ -1936,7 +1936,7 @@ mod tests {
assert_eq!(s.get("company.name").unwrap().seq, 7);
}
/// policy.require_tax_category (rules.md B-32): warn or refuse, one
/// policy.require_tax_category (BS-ledger-11): warn or refuse, one
/// spelling each ("required" and "require" are refuse), nothing else
/// ("off" is no value: the warning is the floor); unset is warn.
#[test]
+7 -7
View File
@@ -18,11 +18,11 @@
//! transaction is with both members, each with their share, and
//! shares can be apportioned explicitly ("do you allow for
//! controlled apportioning?" Yes). docs/parties-and-attachments.md
//! "Shares". rules.md B-35 (the sign, direction and money of a
//! "Shares". BS-partner-3 (the sign, direction and money of a
//! part; DECISION, owner, 2026-10-20: a member's entry counts what
//! moved their capital).
//! DEFINITIONS:
//! target (target(), rules.md B-35 item 3): what the shares split,
//! target (target(), BS-partner-3 item 3): what the shares split,
//! signed debit-positive as a line on the parties' own account would
//! be (positive: the company paid or gave; negative: it received),
//! with its direction (paid, received, neither) and what of it moved
@@ -188,7 +188,7 @@ pub struct PartyMember {
///
/// For new shares: [`check_shares_journaled`], and no amount larger than a
/// line may be (kernel::MAX_LINE_AMOUNT; P0 review round 3, S1). Replay
/// checks only [`check_shares_journaled`] (rules.md B-28).
/// checks only [`check_shares_journaled`] (BS-entry-4).
pub fn check_shares(shares: &[PartyShare], known: impl Fn(PartyId) -> bool) -> Result<(), String> {
check_shares_journaled(shares, known)?;
for s in shares {
@@ -207,7 +207,7 @@ pub fn check_shares(shares: &[PartyShare], known: impl Fn(PartyId) -> bool) -> R
/// The checks every journaled `entry.parties_set` passed when it was
/// written (the rule through 2026-10-16): [`check_shares`] without the
/// amount's upper bound. Replay applies exactly these, so books an earlier
/// version wrote always open (rules.md B-28).
/// version wrote always open (BS-entry-4).
pub fn check_shares_journaled(
shares: &[PartyShare],
known: impl Fn(PartyId) -> bool,
@@ -304,7 +304,7 @@ fn split_first(magnitude: Decimal, weights: &[Decimal]) -> Option<Vec<Decimal>>
}
/// What an entry's shares split, and what of it counts (the module's
/// DEFINITIONS: target; rules.md B-35).
/// DEFINITIONS: target; BS-partner-3).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Target {
/// The whole, signed debit-positive as a line on the parties' own
@@ -318,7 +318,7 @@ pub struct Target {
pub in_kind: Decimal,
/// Which side the parts count on in a party's totals: the direction
/// of the entry's root original (itself, unless it is a reversal), so
/// a reversal nets what it reverses (B-35 item 4).
/// a reversal nets what it reverses (BS-partner-3 item 4).
pub counts_as: Direction,
}
@@ -356,7 +356,7 @@ impl Resolved {
/// checked; they cover the whole reversal chain (Ledger::set_entry_parties
/// INVARIANT 5). Refused (TooLargeToCompute), never a panic, when a sum is
/// past exact arithmetic: a draft's lines are as journaled, of any size
/// (rules.md B-28).
/// (BS-entry-4).
pub fn target(
ledger: &Ledger,
id: EntryId,
+2 -2
View File
@@ -400,7 +400,7 @@ pub fn check_category(
/// no postings, so nothing of its own reaches the return).
///
/// ```text
/// GOAL: the accounts a tax category is for (rules.md B-32).
/// GOAL: the accounts a tax category is for (BS-ledger-11).
/// SOURCE: IRS Pub. 583, "Your books must show your gross income, as well
/// as your deductions and credits"; Rev. Proc. 98-25 §5.01, a
/// relationship between "the amounts ... by account and the
@@ -540,7 +540,7 @@ struct CategoryBuild {
/// Build the tax summary for `[start, end]`, closing entries excluded (like
/// the P&L). Each category's deductible amount is the exact sum of its
/// accounts' shares (book × deductible percent ÷ 100), rounded once to
/// the cent, half away from zero (B-21: "round off only the total"); the
/// the cent, half away from zero (BS-entry-3: "round off only the total"); the
/// book amounts stay exact. The share arithmetic is
/// [`crate::kernel::deductible_amount`], so Kani proves the one rounding.
pub fn tax_summary(
+10 -10
View File
@@ -72,7 +72,7 @@
//! 2. IF a fixed asset is in service during the span:
//! - SHOULD leave the tax net income open, with the book depreciation
//! posted in the span
//! BECAUSE tax depreciation is the CPA's (rules.md B-15, B-25).
//! BECAUSE tax depreciation is the CPA's (BS-asset-1, BS-asset-4).
//! 3. IF nothing but cash comes in and goes out:
//! - SHOULD still leave the tax net income open, the book share known
//! BECAUSE income "as figured for tax purposes" is the return's.
@@ -89,9 +89,9 @@ use rust_decimal::Decimal;
/// `[start, end]`: its lines on the asset's depreciation expense account,
/// debit-positive (the depreciation still due through the disposal day,
/// or, negative, what the month's run posted past it, credited back:
/// rules.md B-15 rule 5). With the runs
/// BS-asset-1 rule 5). With the runs
/// (`Ledger::depreciation_posted_between`) it is the asset's depreciation
/// expense in the span, the P&L's and the cash flow's (B-14 rule 8).
/// expense in the span, the P&L's and the cash flow's (BS-statement-3 rule 8).
/// The disposal entry is the posted entry dated the disposal day that
/// credits the asset's cost account by its cost (`Store::dispose_asset`
/// posts it so).
@@ -215,7 +215,7 @@ pub enum Open {
pub enum Note {
/// Property contributed in `entry` to a prepaid account (the balance
/// account of a prepaid-expense schedule: a service contract the
/// member handed over, B-13) with no fixed asset for it: its §723
/// member handed over, BS-partner-1) with no fixed asset for it: its §723
/// basis is taken as its book amount, this member's share `book`
/// (DECISION, P3 review 2026-10-21: the contract's carryover basis is
/// what the books recorded for it; the CPA to confirm).
@@ -342,7 +342,7 @@ fn too_large() -> LedgerError {
}
/// A running split of amounts among members, one split at a time, each
/// by its own weights (B-36, the odd cent as D-38 settles it): each
/// by its own weights (BS-partner-4, the odd cent as D-38 settles it): each
/// member's running total is rounded afresh from their exact running
/// total, so it never drifts a cent from it, and tied cents don't pile up
/// on one member. The worksheet keeps one per set of members with weight
@@ -354,8 +354,8 @@ fn too_large() -> LedgerError {
/// distributed is a cent or more from their exact share, however
/// many entries it is summed over; three equal odd-cent properties
/// contributed 50/50 leave the members one cent apart, never three.
/// SOURCE: rules.md B-36 (shared within each entry as its book value is),
/// B-13 (cent rounding by largest remainder: DECISION, owner
/// SOURCE: BS-partner-4 (shared within each entry as its book value is),
/// BS-partner-1 (cent rounding by largest remainder: DECISION, owner
/// 2026-10-13); DECISION D-38 (owner, 2026-10-20: odd cents
/// everywhere alike, cumulative largest remainder), here for the
/// tax basis by the owner's ask, 2026-10-22 (kernel::
@@ -552,7 +552,7 @@ impl RunningSplit {
/// it is rounded to the cent ([`RunningSplit`] INVARIANT 4).
const EXACT_PLACES: u32 = 10;
/// The four amounts an entry's members share (B-36): the property's
/// The four amounts an entry's members share (BS-partner-4): the property's
/// built-in gain, its property without a basis, its prepaid at book (each
/// by the members' property in it) and the property it distributes (by
/// what each took).
@@ -632,14 +632,14 @@ fn entry_wholes(
Ok(out)
}
/// Every entry's parts of the amounts it splits (B-36 with D-38), from
/// Every entry's parts of the amounts it splits (BS-partner-4 with D-38), from
/// the books' first entry through `end`, whatever span the worksheet is
/// asked for, so an entry's cents are the same in every span it is in.
///
/// ```text
/// GOAL: odd cents that run (RunningSplit) and never touch a member who
/// has no part in the entry, nor change with the span asked for.
/// SOURCE: rules.md B-36; DECISION D-38; Form 1065 Item L (a partner's
/// SOURCE: BS-partner-4; DECISION D-38; Form 1065 Item L (a partner's
/// capital contributed is the basis of the property that partner
/// contributed).
/// INVARIANTS: