Skip to main content

datasynth_core/models/
financial_statements.rs

1//! Financial statement models for period-end reporting.
2
3use chrono::NaiveDate;
4use rust_decimal::Decimal;
5use serde::{Deserialize, Serialize};
6
7/// Type of financial statement.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum StatementType {
11    /// Balance Sheet (Statement of Financial Position)
12    BalanceSheet,
13    /// Income Statement (Profit & Loss)
14    IncomeStatement,
15    /// Cash Flow Statement
16    CashFlowStatement,
17    /// Statement of Changes in Equity
18    ChangesInEquity,
19}
20
21/// Basis of accounting for the statement.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
23#[serde(rename_all = "snake_case")]
24pub enum StatementBasis {
25    /// US GAAP
26    #[default]
27    UsGaap,
28    /// IFRS
29    Ifrs,
30    /// Statutory/local GAAP
31    Statutory,
32}
33
34/// Cash flow category for cash flow statement items.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
36#[serde(rename_all = "snake_case")]
37pub enum CashFlowCategory {
38    /// Operating activities
39    Operating,
40    /// Investing activities
41    Investing,
42    /// Financing activities
43    Financing,
44}
45
46/// A line item on a financial statement.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct FinancialStatementLineItem {
49    /// Line item code (e.g., "BS-CASH", "IS-REV")
50    pub line_code: String,
51    /// Display label
52    pub label: String,
53    /// Statement section (e.g., "Current Assets", "Revenue")
54    pub section: String,
55    /// Sort order within section
56    pub sort_order: u32,
57    /// Current period amount
58    #[serde(with = "rust_decimal::serde::str")]
59    pub amount: Decimal,
60    /// Prior period amount (for comparison)
61    #[serde(default, skip_serializing_if = "Option::is_none")]
62    pub amount_prior: Option<Decimal>,
63    /// Indentation level for display hierarchy
64    pub indent_level: u8,
65    /// Whether this is a subtotal/total line
66    pub is_total: bool,
67    /// GL accounts that roll up to this line
68    pub gl_accounts: Vec<String>,
69}
70
71/// A cash flow item (indirect method).
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct CashFlowItem {
74    /// Item code
75    pub item_code: String,
76    /// Display label
77    pub label: String,
78    /// Cash flow category
79    pub category: CashFlowCategory,
80    /// Amount
81    #[serde(with = "rust_decimal::serde::str")]
82    pub amount: Decimal,
83    /// Prior period amount
84    #[serde(default, skip_serializing_if = "Option::is_none")]
85    pub amount_prior: Option<Decimal>,
86    /// Sort order
87    pub sort_order: u32,
88    /// Is this a subtotal line
89    pub is_total: bool,
90}
91
92/// A complete financial statement.
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct FinancialStatement {
95    /// Unique statement identifier
96    pub statement_id: String,
97    /// Company code
98    pub company_code: String,
99    /// Statement type
100    pub statement_type: StatementType,
101    /// Accounting basis
102    pub basis: StatementBasis,
103    /// Reporting period start
104    pub period_start: NaiveDate,
105    /// Reporting period end
106    pub period_end: NaiveDate,
107    /// Fiscal year
108    pub fiscal_year: u16,
109    /// Fiscal period
110    pub fiscal_period: u8,
111    /// Line items
112    pub line_items: Vec<FinancialStatementLineItem>,
113    /// Cash flow items (only for CashFlowStatement)
114    pub cash_flow_items: Vec<CashFlowItem>,
115    /// Currency
116    pub currency: String,
117    /// Whether this is a consolidated statement
118    pub is_consolidated: bool,
119    /// Preparer ID
120    pub preparer_id: String,
121}