Skip to main content

datasynth_core/models/
budget.rs

1//! Budget models for financial planning and variance analysis.
2//!
3//! These models represent organizational budgets and their line items,
4//! supporting budget-vs-actual comparison and variance reporting.
5
6use chrono::NaiveDate;
7use rust_decimal::Decimal;
8use serde::{Deserialize, Serialize};
9
10/// Status of a budget through the planning and approval lifecycle.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
12#[serde(rename_all = "snake_case")]
13pub enum BudgetStatus {
14    /// Initial draft, still being prepared
15    #[default]
16    Draft,
17    /// Submitted for management approval
18    Submitted,
19    /// Approved by management
20    Approved,
21    /// Budget has been revised after initial approval
22    Revised,
23    /// Budget period has ended and the budget is closed
24    Closed,
25}
26
27/// An individual line item within a budget, representing a single account/cost center allocation.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct BudgetLineItem {
30    /// Unique line item identifier
31    pub line_id: String,
32    /// Parent budget identifier
33    pub budget_id: String,
34    /// GL account code
35    pub account_code: String,
36    /// GL account name
37    pub account_name: String,
38    /// Department this line applies to
39    pub department: Option<String>,
40    /// Cost center this line applies to
41    pub cost_center: Option<String>,
42    /// Budgeted amount for the period
43    #[serde(with = "rust_decimal::serde::str")]
44    pub budget_amount: Decimal,
45    /// Actual amount recorded for the period
46    #[serde(with = "rust_decimal::serde::str")]
47    pub actual_amount: Decimal,
48    /// Variance (actual - budget)
49    #[serde(with = "rust_decimal::serde::str")]
50    pub variance: Decimal,
51    /// Variance as a percentage of budget
52    pub variance_percent: f64,
53    /// Start of the budget period for this line
54    pub period_start: NaiveDate,
55    /// End of the budget period for this line
56    pub period_end: NaiveDate,
57    /// Free-text notes or explanations for variances
58    pub notes: Option<String>,
59}
60
61/// A budget representing planned financial targets for a fiscal year.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct Budget {
64    /// Unique budget identifier
65    pub budget_id: String,
66    /// Company code this budget belongs to
67    pub company_code: String,
68    /// Fiscal year the budget covers
69    pub fiscal_year: u32,
70    /// Human-readable name of the budget (e.g., "FY2025 Operating Budget")
71    pub name: String,
72    /// Current status of the budget
73    pub status: BudgetStatus,
74    /// Total budgeted amount across all line items
75    #[serde(with = "rust_decimal::serde::str")]
76    pub total_budget: Decimal,
77    /// Total actual amount across all line items
78    #[serde(with = "rust_decimal::serde::str")]
79    pub total_actual: Decimal,
80    /// Total variance across all line items
81    #[serde(with = "rust_decimal::serde::str")]
82    pub total_variance: Decimal,
83    /// Individual budget line items
84    pub line_items: Vec<BudgetLineItem>,
85    /// Person who approved the budget
86    pub approved_by: Option<String>,
87    /// Date the budget was approved
88    pub approved_date: Option<NaiveDate>,
89}