accounting_core/
lib.rs

1//! # Accounting Core
2//!
3//! A comprehensive accounting library providing double-entry bookkeeping,
4//! GST calculations, and financial reporting capabilities.
5//!
6//! ## Features
7//!
8//! - **Double-entry bookkeeping**: Complete transaction validation and balance tracking
9//! - **Account management**: Support for Assets, Liabilities, Equity, Income, and Expense accounts
10//! - **Paginated responses**: Efficient pagination for large datasets with comprehensive metadata
11//! - **GST calculations**: Indian GST compliance with CGST/SGST/IGST support
12//! - **Financial reporting**: Balance sheets, income statements, and trial balance generation
13//! - **Reconciliation**: Bank statement and payment gateway reconciliation
14//! - **Storage abstraction**: Database-agnostic design with trait-based storage
15//!
16//! ## Quick Start
17//!
18//! ```rust
19//! use accounting_core::{Ledger, AccountType, PaginationOption, PaginationParams};
20//! use accounting_core::utils::memory_storage::MemoryStorage;
21//! use bigdecimal::BigDecimal;
22//! use chrono::NaiveDate;
23//!
24//! # #[tokio::main]
25//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//! // Create a ledger with in-memory storage (for production, use a database storage)
27//! let storage = MemoryStorage::new();
28//! let mut ledger = Ledger::new(storage);
29//!
30//! // Create a cash account
31//! let cash_account = ledger.create_account(
32//!     "cash".to_string(),
33//!     "Cash Account".to_string(),
34//!     AccountType::Asset,
35//!     None,
36//! ).await?;
37//!
38//! // List all accounts with pagination (default: page 1, 50 items per page)
39//! let pagination = PaginationParams::new(1, 50)?;
40//! let result = ledger.list_accounts(PaginationOption::Paginated(pagination)).await?;
41//! let accounts = result.to_paginated_response();
42//! println!("Total accounts: {}, Current page: {} of {}",
43//!          accounts.total_count,
44//!          accounts.page,
45//!          accounts.total_pages);
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! ## Pagination Support
51//!
52//! The library provides comprehensive pagination support for both accounts and transactions:
53//!
54//! ### Basic Pagination
55//!
56//! ```rust
57//! use accounting_core::{Ledger, PaginationOption, PaginationParams, AccountType};
58//! use accounting_core::utils::memory_storage::MemoryStorage;
59//!
60//! # #[tokio::main]
61//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
62//! let storage = MemoryStorage::new();
63//! let ledger = Ledger::new(storage);
64//!
65//! // Get first page with 10 accounts per page
66//! let pagination = PaginationParams::new(1, 10)?;
67//! let result = ledger.list_accounts(PaginationOption::Paginated(pagination)).await?;
68//! let result = result.to_paginated_response();
69//!
70//! println!("Page {} of {} (showing {} of {} total accounts)",
71//!          result.page,
72//!          result.total_pages,
73//!          result.items.len(),
74//!          result.total_count);
75//!
76//! // Check if there are more pages
77//! if result.has_next {
78//!     let next_page = PaginationParams::new(2, 10)?;
79//!     let next_result = ledger.list_accounts(PaginationOption::Paginated(next_page)).await?;
80//!     // Process next page...
81//! }
82//! # Ok(())
83//! # }
84//! ```
85//!
86//! ### Filtered Pagination
87//!
88//! ```rust
89//! use accounting_core::{Ledger, PaginationOption, PaginationParams, AccountType};
90//! use accounting_core::utils::memory_storage::MemoryStorage;
91//! use chrono::NaiveDate;
92//!
93//! # #[tokio::main]
94//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
95//! let storage = MemoryStorage::new();
96//! let ledger = Ledger::new(storage);
97//!
98//! // Get only Asset accounts with pagination
99//! let pagination = PaginationParams::new(1, 20)?;
100//! let assets = ledger.list_accounts_by_type(AccountType::Asset, PaginationOption::Paginated(pagination)).await?;
101//!
102//! // Get transactions for a specific date range with pagination
103//! let start_date = NaiveDate::from_ymd_opt(2024, 1, 1);
104//! let end_date = NaiveDate::from_ymd_opt(2024, 12, 31);
105//! let transactions = ledger.get_transactions(start_date, end_date, PaginationOption::Paginated(pagination)).await?;
106//!
107//! // Get transactions for a specific account with pagination
108//! let account_txns = ledger.get_account_transactions(
109//!     "cash",
110//!     start_date,
111//!     end_date,
112//!     PaginationOption::Paginated(pagination)
113//! ).await?;
114//! # Ok(())
115//! # }
116//! ```
117//!
118//! ### Pagination Metadata
119//!
120//! All paginated responses include comprehensive metadata for building user interfaces:
121//!
122//! ```rust
123//! # use accounting_core::{Ledger, PaginationOption, PaginationParams};
124//! # use accounting_core::utils::memory_storage::MemoryStorage;
125//! # #[tokio::main]
126//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
127//! # let storage = MemoryStorage::new();
128//! # let ledger = Ledger::new(storage);
129//! let pagination = PaginationParams::new(2, 10)?;
130//! let response = ledger.list_accounts(PaginationOption::Paginated(pagination)).await?;
131//! let result = response.to_paginated_response();
132//!
133//! // Access pagination metadata
134//! println!("Current page: {}", result.page);           // 2
135//! println!("Page size: {}", result.page_size);         // 10
136//! println!("Total items: {}", result.total_count);     // e.g., 25
137//! println!("Total pages: {}", result.total_pages);     // e.g., 3
138//! println!("Has next page: {}", result.has_next);      // true
139//! println!("Has previous page: {}", result.has_previous); // true
140//!
141//! // Use metadata to build navigation
142//! if result.has_previous {
143//!     println!("Previous page available");
144//! }
145//! if result.has_next {
146//!     println!("Next page available");
147//! }
148//! # Ok(())
149//! # }
150//! ```
151//!
152//! ## Examples
153//!
154//! Check out the comprehensive examples in the `examples/` directory:
155//!
156//! - `pagination_demo.rs` - Complete pagination functionality walkthrough
157//! - `api_pagination_patterns.rs` - REST API and GraphQL integration patterns
158//! - `web_integration.rs` - Web framework integration examples
159
160pub mod ledger;
161pub mod reconciliation;
162pub mod tax;
163pub mod traits;
164pub mod types;
165pub mod utils;
166
167// Re-export commonly used types
168pub use ledger::*;
169pub use tax::gst::*;
170pub use traits::*;
171pub use types::*;
172
173// Re-export transaction patterns for convenience
174pub use ledger::transaction::patterns;