pub trait JournalEntryRepository: Send + Sync {
Show 15 methods
// Required methods
fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn find_by_organization<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_by_expense<'life0, 'async_trait>(
&'life0 self,
expense_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_by_date_range<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn calculate_account_balances<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn calculate_account_balances_for_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_lines_by_account<'life0, 'life1, 'async_trait>(
&'life0 self,
organization_id: Uuid,
account_code: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntryLine>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn validate_balance<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn calculate_account_balances_for_building<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn calculate_account_balances_for_building_and_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn create_manual_entry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
lines: &'life2 [JournalEntryLine],
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn list_entries<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Option<Uuid>,
journal_type: Option<String>,
start_date: Option<DateTime<Utc>>,
end_date: Option<DateTime<Utc>>,
limit: i64,
offset: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_by_id<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_lines_by_entry<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntryLine>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn delete_entry<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Repository port for journal entries (double-entry bookkeeping)
This trait defines operations for managing accounting journal entries inspired by Noalyss’ jrn/jrnx table structure.
Required Methods§
Sourcefn create<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Create a new journal entry with its lines
§Arguments
entry: The journal entry to create (must be balanced)
§Returns
Ok(JournalEntry)with generated IDs and timestampsErr(String)if validation fails or database error
§Database Constraints
- Triggers validate that total debits = total credits
- Foreign keys validate account codes exist
Sourcefn find_by_organization<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_by_organization<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Find all journal entries for an organization
Returns entries ordered by entry_date DESC.
Sourcefn find_by_expense<'life0, 'async_trait>(
&'life0 self,
expense_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_by_expense<'life0, 'async_trait>(
&'life0 self,
expense_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Find journal entries linked to a specific expense
Returns all entries that were auto-generated from this expense.
Sourcefn find_by_date_range<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_by_date_range<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Find journal entries for a date range
Useful for generating period reports (income statement).
Sourcefn calculate_account_balances<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn calculate_account_balances<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Calculate account balances from journal entry lines
This replaces the old method of calculating balances directly from expenses.
§Arguments
organization_id: Organization to calculate for
§Returns
HashMap<account_code, balance>where:- Assets/Expenses: balance = debits - credits
- Liabilities/Revenue: balance = credits - debits
§Example
{
"6100": 5000.0, // Utilities expense
"4110": 1050.0, // VAT recoverable
"4400": -6050.0, // Suppliers payable (negative = liability)
"5500": 6050.0 // Bank (after payment)
}Sourcefn calculate_account_balances_for_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn calculate_account_balances_for_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Calculate account balances for a specific period
Same as calculate_account_balances but filtered by entry_date.
Sourcefn find_lines_by_account<'life0, 'life1, 'async_trait>(
&'life0 self,
organization_id: Uuid,
account_code: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntryLine>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn find_lines_by_account<'life0, 'life1, 'async_trait>(
&'life0 self,
organization_id: Uuid,
account_code: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntryLine>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get all journal entry lines for an account
Useful for displaying account ledgers (grand-livre).
Sourcefn validate_balance<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn validate_balance<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<bool, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Validate that an entry is balanced (debits = credits)
This is a safety check before persisting. Database triggers also enforce this.
Sourcefn calculate_account_balances_for_building<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn calculate_account_balances_for_building<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Calculate account balances for a specific building
Filters journal entries by those linked to expenses/contributions for the building.
Sourcefn calculate_account_balances_for_building_and_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn calculate_account_balances_for_building_and_period<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Uuid,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, f64>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Calculate account balances for a specific building and period
Sourcefn create_manual_entry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
lines: &'life2 [JournalEntryLine],
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn create_manual_entry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
entry: &'life1 JournalEntry,
lines: &'life2 [JournalEntryLine],
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Create a manual journal entry with multiple lines
Sourcefn list_entries<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Option<Uuid>,
journal_type: Option<String>,
start_date: Option<DateTime<Utc>>,
end_date: Option<DateTime<Utc>>,
limit: i64,
offset: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_entries<'life0, 'async_trait>(
&'life0 self,
organization_id: Uuid,
building_id: Option<Uuid>,
journal_type: Option<String>,
start_date: Option<DateTime<Utc>>,
end_date: Option<DateTime<Utc>>,
limit: i64,
offset: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<JournalEntry>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
List journal entries with filters
Sourcefn find_by_id<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_by_id<'life0, 'async_trait>(
&'life0 self,
entry_id: Uuid,
organization_id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<JournalEntry, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Find a journal entry by ID