BudgetService

Struct BudgetService 

Source
pub struct BudgetService<'a> { /* private fields */ }
Expand description

Service for budget management

Implementations§

Source§

impl<'a> BudgetService<'a>

Source

pub fn new(storage: &'a Storage) -> Self

Create a new budget service

Source

pub fn assign_to_category( &self, category_id: CategoryId, period: &BudgetPeriod, amount: Money, ) -> EnvelopeResult<BudgetAllocation>

Assign funds to a category for a period

Source

pub fn add_to_category( &self, category_id: CategoryId, period: &BudgetPeriod, amount: Money, ) -> EnvelopeResult<BudgetAllocation>

Add to a category’s budget for a period

Source

pub fn move_between_categories( &self, from_category_id: CategoryId, to_category_id: CategoryId, period: &BudgetPeriod, amount: Money, ) -> EnvelopeResult<()>

Move funds between categories for a period

Source

pub fn get_allocation( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<BudgetAllocation>

Get the allocation for a category in a period

Source

pub fn get_category_summary( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<CategoryBudgetSummary>

Get budget summary for a category in a period

Source

pub fn calculate_category_activity( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<Money>

Calculate activity (spending) for a category in a period

Source

pub fn calculate_income_for_period( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Money>

Calculate total income for a period (sum of all positive transactions)

Source

pub fn get_available_to_budget( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Money>

Calculate Available to Budget for a period

Available to Budget = Total On-Budget Balances - Total Budgeted for current + prior periods

Source

pub fn get_expected_income(&self, period: &BudgetPeriod) -> Option<Money>

Get expected income for a period (if set)

Source

pub fn is_over_expected_income( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Option<Money>>

Check if total budgeted exceeds expected income

Returns Some(overage_amount) if over budget, None otherwise

Source

pub fn get_remaining_to_budget_from_income( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Option<Money>>

Get remaining amount that can be budgeted based on expected income

Returns the difference between expected income and total budgeted. Positive = room to budget more, Negative = over-budgeted

Source

pub fn get_budget_overview( &self, period: &BudgetPeriod, ) -> EnvelopeResult<BudgetOverview>

Get a complete budget overview for a period

Source

pub fn get_allocation_history( &self, category_id: CategoryId, ) -> EnvelopeResult<Vec<BudgetAllocation>>

Get all allocations for a category (history)

Source

pub fn get_carryover( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<Money>

Calculate the carryover amount for a category going into a specific period

This is the “Available” balance from the previous period, which includes:

  • Budgeted amount
  • Previous carryover
  • Activity (spending)
Source

pub fn apply_rollover( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<BudgetAllocation>

Apply rollover from the previous period to a category’s allocation

This should be called when entering a new period to carry forward any surplus or deficit from the previous period.

Source

pub fn apply_rollover_all( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Vec<BudgetAllocation>>

Apply rollover for all categories for a period

This calculates and sets the carryover amount for every category based on their Available balance from the previous period.

Source

pub fn get_overspent_categories( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Vec<CategoryBudgetSummary>>

Get a list of overspent categories for a period

Source

pub fn set_target( &self, category_id: CategoryId, amount: Money, cadence: TargetCadence, ) -> EnvelopeResult<BudgetTarget>

Create or update a budget target for a category

Source

pub fn update_target( &self, target_id: BudgetTargetId, amount: Option<Money>, cadence: Option<TargetCadence>, ) -> EnvelopeResult<BudgetTarget>

Update an existing budget target

Source

pub fn get_target( &self, category_id: CategoryId, ) -> EnvelopeResult<Option<BudgetTarget>>

Get the active target for a category

Source

pub fn get_suggested_budget( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<Option<Money>>

Get the suggested budget amount for a category based on its target

Source

pub fn delete_target(&self, target_id: BudgetTargetId) -> EnvelopeResult<bool>

Delete a target

Source

pub fn remove_target(&self, category_id: CategoryId) -> EnvelopeResult<bool>

Remove target for a category

Source

pub fn get_all_targets(&self) -> EnvelopeResult<Vec<BudgetTarget>>

Get all active targets

Source

pub fn auto_fill_from_target( &self, category_id: CategoryId, period: &BudgetPeriod, ) -> EnvelopeResult<Option<BudgetAllocation>>

Auto-fill budget for a category based on its target

Source

pub fn auto_fill_all_targets( &self, period: &BudgetPeriod, ) -> EnvelopeResult<Vec<BudgetAllocation>>

Auto-fill budgets for all categories with targets

Auto Trait Implementations§

§

impl<'a> Freeze for BudgetService<'a>

§

impl<'a> RefUnwindSafe for BudgetService<'a>

§

impl<'a> Send for BudgetService<'a>

§

impl<'a> Sync for BudgetService<'a>

§

impl<'a> Unpin for BudgetService<'a>

§

impl<'a> UnwindSafe for BudgetService<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.