refactor(core): percentages and ratios in the kernel
A project's contribution margin is its net as a percent of revenue: the exact ratio times 100, rounded once to the place the page prints (one place, half to even), and none when there is no revenue to divide by. The same computation was hand-written in reports; it is now kernel::percent_of, division first as the call site always did, so the figures, the scale and the None on a non-positive revenue do not move. The government's part of an operating payment is an amount split a : b: the government side rounded once to the currency's places, half to even, the rest exact, the two summing to the payment (BS-statement-3 statement 8). U3 had already routed the share through kernel::share_of; U6 names the whole split as kernel::split_ratio, which builds on share_of and round_step, and cashflow::split_part calls it. The old party-shares refusal on the shares' own sum is kept. The percentage's rules come from BS-statement-5 statement 2 (a project's net is revenue less expenses) and wanderbooks' WB-statement-7 (the margin as a percent of revenue), and BS-entry-3 (round only where a rule says to); the split's from BS-statement-3 statement 8, BS-partner-1 and BS-entry-3. Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
1 parent
7a5cb6873a
commit
a70099daae
3 files changed
+136
-21
No files matched your search
@@ -627,14 +627,10 @@ impl ProjectToDate {
|
||||
/// 3. NEVER panics: None when the quotient can't be represented.
|
||||
/// ```
|
||||
pub fn contribution_margin_pct(contribution: Decimal, revenue: Decimal) -> Option<Decimal> {
|
||||
if revenue <= Decimal::ZERO {
|
||||
return None;
|
||||
}
|
||||
let mut x = crate::kernel::round_places(
|
||||
contribution
|
||||
.checked_div(revenue)?
|
||||
.checked_mul(Decimal::ONE_HUNDRED)?,
|
||||
1,
|
||||
let mut x = crate::kernel::percent_of(
|
||||
contribution,
|
||||
revenue,
|
||||
Decimal::new(1, 1),
|
||||
crate::kernel::Rounding::HalfToEven,
|
||||
)?;
|
||||
// Display padding only: the margin always prints its one place.
|
||||
|
||||
Reference in new issue
Block a user