pub struct RunningBalanceTracker { /* private fields */ }Expand description
Tracks running balances for all accounts across companies.
Implementations§
Source§impl RunningBalanceTracker
impl RunningBalanceTracker
Sourcepub fn new_with_currency_and_framework(
config: BalanceTrackerConfig,
currency: String,
framework: &str,
) -> Self
pub fn new_with_currency_and_framework( config: BalanceTrackerConfig, currency: String, framework: &str, ) -> Self
Creates a new balance tracker with the specified currency and accounting framework.
Sourcepub fn new_with_currency(config: BalanceTrackerConfig, currency: String) -> Self
pub fn new_with_currency(config: BalanceTrackerConfig, currency: String) -> Self
Creates a new balance tracker with the specified currency (defaults to US GAAP).
Sourcepub fn new(config: BalanceTrackerConfig) -> Self
pub fn new(config: BalanceTrackerConfig) -> Self
Creates a new balance tracker (defaults to USD and US GAAP).
Sourcepub fn new_with_framework(config: BalanceTrackerConfig, framework: &str) -> Self
pub fn new_with_framework(config: BalanceTrackerConfig, framework: &str) -> Self
Creates a new balance tracker for a specific accounting framework (defaults to USD).
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Creates a tracker with default configuration (US GAAP).
Sourcepub fn register_account_type(
&mut self,
account_code: &str,
account_type: AccountType,
)
pub fn register_account_type( &mut self, account_code: &str, account_type: AccountType, )
Registers an account type for balance tracking.
Sourcepub fn register_account_types(&mut self, types: &[(String, AccountType)])
pub fn register_account_types(&mut self, types: &[(String, AccountType)])
Registers multiple account types.
Sourcepub fn register_from_chart_prefixes(&mut self, prefixes: &[(&str, AccountType)])
pub fn register_from_chart_prefixes(&mut self, prefixes: &[(&str, AccountType)])
Registers account types from a chart of accounts prefix pattern.
Sourcepub fn initialize_from_snapshot(&mut self, snapshot: &BalanceSnapshot)
pub fn initialize_from_snapshot(&mut self, snapshot: &BalanceSnapshot)
Initializes balances from opening balance snapshot.
Sourcepub fn apply_entry(
&mut self,
entry: &JournalEntry,
) -> Result<(), ValidationError>
pub fn apply_entry( &mut self, entry: &JournalEntry, ) -> Result<(), ValidationError>
Applies a journal entry to the running balances.
Sourcepub fn apply_entries(
&mut self,
entries: &[JournalEntry],
) -> Vec<ValidationError>
pub fn apply_entries( &mut self, entries: &[JournalEntry], ) -> Vec<ValidationError>
Applies a batch of entries.
Sourcepub fn validate_balance_sheet(
&mut self,
company_code: &str,
date: NaiveDate,
entry_id: Option<&str>,
) -> Result<(), ValidationError>
pub fn validate_balance_sheet( &mut self, company_code: &str, date: NaiveDate, entry_id: Option<&str>, ) -> Result<(), ValidationError>
Validates the balance sheet equation for a company.
Sourcepub fn get_snapshot(
&self,
company_code: &str,
as_of_date: NaiveDate,
) -> Option<BalanceSnapshot>
pub fn get_snapshot( &self, company_code: &str, as_of_date: NaiveDate, ) -> Option<BalanceSnapshot>
Gets the current snapshot for a company.
Sourcepub fn get_all_snapshots(&self, as_of_date: NaiveDate) -> Vec<BalanceSnapshot>
pub fn get_all_snapshots(&self, as_of_date: NaiveDate) -> Vec<BalanceSnapshot>
Gets snapshots for all companies.
Sourcepub fn get_balance_changes(
&self,
company_code: &str,
from_date: NaiveDate,
to_date: NaiveDate,
) -> Vec<AccountPeriodActivity>
pub fn get_balance_changes( &self, company_code: &str, from_date: NaiveDate, to_date: NaiveDate, ) -> Vec<AccountPeriodActivity>
Gets balance changes for a period.
Sourcepub fn get_account_balance(
&self,
company_code: &str,
account_code: &str,
) -> Option<&AccountBalance>
pub fn get_account_balance( &self, company_code: &str, account_code: &str, ) -> Option<&AccountBalance>
Gets balance for a specific account.
Sourcepub fn with_tb_anchor(self, anchor: TbAnchorPrior) -> Self
pub fn with_tb_anchor(self, anchor: TbAnchorPrior) -> Self
SP4.1 — Attach a TB anchor prior to this tracker. When set, enables
account_drift() and drift_correction_needed(). Does not change
the existing balance-tracking behaviour — purely additive.
Sourcepub fn set_tb_anchor(&mut self, anchor: TbAnchorPrior)
pub fn set_tb_anchor(&mut self, anchor: TbAnchorPrior)
SP4.1 — Set the TB anchor prior on this tracker (mutable version).
Sourcepub fn account_drift(&self, company_code: &str) -> Vec<(String, f64)>
pub fn account_drift(&self, company_code: &str) -> Vec<(String, f64)>
SP4.1 — Returns the per-account drift (current closing balance − target closing balance) for every account that appears in the TB anchor prior.
Positive drift means the synthetic account balance is higher than the target; negative means it is lower.
Returns an empty Vec when no TB anchor is loaded or no company has
been tracked yet.
Sourcepub fn drift_correction_needed(&self, company_code: &str) -> bool
pub fn drift_correction_needed(&self, company_code: &str) -> bool
SP4.1 / SP5.1 — Returns true when the TB anchor is loaded and any
single account’s absolute drift exceeds 2 × closing_stdev (or a
fallback of 2% of |closing_balance| when stdev is zero), OR the
aggregate absolute drift across all tracked accounts exceeds 0.5% of
total_assets.
Thresholds were tuned to 2σ / 0.5% in SP5.1 (previously 3σ / 1%) so that the drift-correction pass fires on realistic synthetic runs where balances are shaped by priors but not pinned to the corpus median.
Returns false when no TB anchor is loaded (backwards-compatible
behaviour — caller does not emit drift-correction entries).
Sourcepub fn build_drift_correction_je<R: RngExt>(
&self,
company_code: &str,
posting_date: NaiveDate,
rng: &mut R,
) -> Option<JournalEntry>
pub fn build_drift_correction_je<R: RngExt>( &self, company_code: &str, posting_date: NaiveDate, rng: &mut R, ) -> Option<JournalEntry>
SP4.1 W8.1 — Build a balanced drift-correction JE that nudges the most-drifted accounts back toward their TB anchor targets.
The emitted JE:
- Has
document_type = "SA"andsource = Adjustment(period-end style). - Includes at most 8 account lines (the worst drifters), plus one balancing line posted to suspense account “9999” when the selected lines don’t net to zero.
- Always satisfies
total_debit == total_credit(mandatory forapply_entry).
Returns None when no TB anchor is loaded, when no drifts exceed the noise
floor, or when the resulting JE would have fewer than 2 lines.
SP5.1: The net / balancing amount is now computed in Decimal (not f64) so that f64→Decimal precision loss cannot produce an “unbalanced” JE.
Sourcepub fn get_validation_errors(&self) -> &[ValidationError]
pub fn get_validation_errors(&self) -> &[ValidationError]
Gets all validation errors.
Sourcepub fn clear_validation_errors(&mut self)
pub fn clear_validation_errors(&mut self)
Clears validation errors.
Sourcepub fn get_statistics(&self) -> &TrackerStatistics
pub fn get_statistics(&self) -> &TrackerStatistics
Gets tracker statistics.
Sourcepub fn roll_forward(&mut self, _new_period_start: NaiveDate)
pub fn roll_forward(&mut self, _new_period_start: NaiveDate)
Rolls forward balances to a new period.
Auto Trait Implementations§
impl !RefUnwindSafe for RunningBalanceTracker
impl !UnwindSafe for RunningBalanceTracker
impl Freeze for RunningBalanceTracker
impl Send for RunningBalanceTracker
impl Sync for RunningBalanceTracker
impl Unpin for RunningBalanceTracker
impl UnsafeUnpin for RunningBalanceTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.