Skip to content

Commit

Permalink
feat: add back embedded statements (#1309)
Browse files Browse the repository at this point in the history
* feat: add first statement (#1289)

* refactor: expand seed into module

* feat: add account_set_id when creating control accounts

* chore: setup core/statements module boilerplate

* chore: add statements entity boilerplate

* refactor: change statement entity to trial_balance_statement

* refactor: use statement entity id as account set id

* feat: add trial balance ledger boilerplate

* refactor: expand accounting_init constants into module

* chore: add Statements to accounting_init

* feat: add 'create_trial_balance_statement' use-case

* chore: add statement actions to rbac

* chore: add 'find_by_reference' function

* feat: create trial balance statements in accounting_init

* feat: add created control-sub-accounts to trial balance

* chore: update cala

* chore: replicate core TrialBalances module in lana app

* refactor: swap core/statements for lana/trial_balances in seed

* chore: remove unused core/statements module

* feat: add trial_balance query function with balances

* refactor: change trial balance query param to name

* refactor: remove currency argument, fetch both usd & btc currencies

* refactor: use Satoshi/UsdCent types in trial_balance ledger

* chore: implement new trial_balance gql query

* chore: clean up lints

* chore: add TrialBalance auth for bank manager

* fix: handle no balance found error

* chore: add control_sub_account to control account cala account set

* chore: re-add off-trial-balance implementation

* refactor: do net calcs in ledger layer

* fix: add relevant facility accounts to off-balance-sheet-trial-balance

* chore: add omnibus accounts to charts and trial_balance

* refactor: switch around Asset/Liabilities designation for facility accounts

* fix: show netDebit Trial Balance frontend

* temp: debug gh actions charts test

* refactor: move statement to lana_app top level

* feat: add profit loss (#1310)

* feat: add profit-and-loss statement boilerplate

* chore: add pl statement line item account sets

* chore: add P&L statement to accounting_init

* chore: map PL statement to graphql types

* fix: do not return new id when control account exists (#1311)

* chore: update cala-ledger (#1314)

---------

Co-authored-by: Vaibhav <[email protected]>

---------

Co-authored-by: Vaibhav <[email protected]>
  • Loading branch information
vindard and thevaibhav-dixit authored Jan 27, 2025
1 parent 2df6cfb commit ca93a08
Show file tree
Hide file tree
Showing 58 changed files with 2,299 additions and 605 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/admin-panel/app/trial-balance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ const TrialBalanceValues: React.FC<TrialBalanceValuesProps> = ({
<Balance
align="end"
currency={currency}
amount={total[currency].closingBalance[layer].credit}
amount={total[currency].closingBalance[layer].netDebit}
/>
</TableCell>
</TableRow>
Expand Down
6 changes: 6 additions & 0 deletions bats/chart-of-accounts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

load "helpers"

PERSISTED_LOG_FILE="chart-of-accounts.e2e-logs"
RUN_LOG_FILE="chart-of-accounts.run.e2e-logs"

setup_file() {
start_server
}

teardown_file() {
stop_server
cp "$LOG_FILE" "$PERSISTED_LOG_FILE"
}

@test "chart-of-accounts: can traverse chart of accounts" {
exec_admin_graphql 'chart-of-accounts'
graphql_output
echo "chart-of-accounts | $(graphql_output)" >> $RUN_LOG_FILE

category_account_code=$(echo "$output" | jq -r \
'.data.chartOfAccounts.categories.assets.accountCode'
Expand Down
63 changes: 48 additions & 15 deletions core/chart-of-accounts/src/chart_of_accounts/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use es_entity::*;
use crate::{
path::*,
primitives::{ChartId, LedgerAccountSetId},
ControlSubAccountDetails,
ControlAccountDetails, ControlSubAccountDetails,
};

pub use super::error::*;
Expand All @@ -25,6 +25,7 @@ pub enum ChartEvent {
audit_info: AuditInfo,
},
ControlAccountAdded {
id: LedgerAccountSetId,
encoded_path: String,
path: ControlAccountPath,
name: String,
Expand Down Expand Up @@ -74,22 +75,34 @@ impl Chart {
pub fn find_control_account_by_reference(
&self,
reference_to_check: String,
) -> Option<ControlAccountPath> {
) -> Option<ControlAccountDetails> {
self.events.iter_all().rev().find_map(|event| match event {
ChartEvent::ControlAccountAdded {
path, reference, ..
} if reference_to_check == *reference => Some(*path),
path,
reference,
id,
name,
..
} if reference_to_check == *reference => Some({
ControlAccountDetails {
path: *path,
account_set_id: *id,
name: name.to_string(),
reference: reference.to_string(),
}
}),
_ => None,
})
}

pub fn create_control_account(
&mut self,
id: LedgerAccountSetId,
category: ChartCategory,
name: String,
reference: String,
audit_info: AuditInfo,
) -> Result<ControlAccountPath, ChartError> {
) -> Result<ControlAccountDetails, ChartError> {
if self
.find_control_account_by_reference(reference.to_string())
.is_some()
Expand All @@ -99,14 +112,20 @@ impl Chart {

let path = self.next_control_account(category)?;
self.events.push(ChartEvent::ControlAccountAdded {
id,
encoded_path: path.path_encode(self.id),
path,
name,
reference,
name: name.to_string(),
reference: reference.to_string(),
audit_info,
});

Ok(path)
Ok(ControlAccountDetails {
path,
account_set_id: id,
name,
reference,
})
}

fn next_control_sub_account(
Expand Down Expand Up @@ -283,8 +302,12 @@ mod tests {
#[test]
fn test_create_control_account() {
let mut chart = init_chart_of_events();
let ControlAccountPath { category, index } = chart
let ControlAccountDetails {
path: ControlAccountPath { category, index },
..
} = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets".to_string(),
"assets".to_string(),
Expand All @@ -300,6 +323,7 @@ mod tests {
let mut chart = init_chart_of_events();
chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets #1".to_string(),
"assets".to_string(),
Expand All @@ -308,6 +332,7 @@ mod tests {
.unwrap();

match chart.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets #2".to_string(),
"assets".to_string(),
Expand All @@ -327,6 +352,7 @@ mod tests {
let mut chart = init_chart_of_events();
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets".to_string(),
"assets".to_string(),
Expand All @@ -345,7 +371,7 @@ mod tests {
} = chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Current Assets".to_string(),
"current-assets".to_string(),
dummy_audit_info(),
Expand All @@ -361,6 +387,7 @@ mod tests {
let mut chart = init_chart_of_events();
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets".to_string(),
"assets".to_string(),
Expand All @@ -370,7 +397,7 @@ mod tests {
chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Current Assets #1".to_string(),
"current-assets".to_string(),
dummy_audit_info(),
Expand All @@ -379,7 +406,7 @@ mod tests {

match chart.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Current Assets #2".to_string(),
"current-assets".to_string(),
dummy_audit_info(),
Expand All @@ -402,15 +429,20 @@ mod tests {

chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"First".to_string(),
"assets-01".to_string(),
dummy_audit_info(),
)
.unwrap();

let ControlAccountPath { category, index } = chart
let ControlAccountDetails {
path: ControlAccountPath { category, index },
..
} = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Second".to_string(),
"assets-02".to_string(),
Expand All @@ -426,6 +458,7 @@ mod tests {
let mut chart = init_chart_of_events();
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Assets".to_string(),
"assets".to_string(),
Expand All @@ -436,7 +469,7 @@ mod tests {
chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"First".to_string(),
"first-asset".to_string(),
dummy_audit_info(),
Expand All @@ -454,7 +487,7 @@ mod tests {
} = chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Second".to_string(),
"second-asset".to_string(),
dummy_audit_info(),
Expand Down
10 changes: 7 additions & 3 deletions core/chart-of-accounts/src/chart_of_accounts/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ mod tests {
{
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Assets,
"Loans Receivable".to_string(),
"loans-receivable".to_string(),
Expand All @@ -174,7 +175,7 @@ mod tests {
chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Fixed Loans Receivable".to_string(),
"fixed-loans-receivable".to_string(),
dummy_audit_info(),
Expand All @@ -189,6 +190,7 @@ mod tests {
{
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Liabilities,
"User Checking".to_string(),
"user-checking".to_string(),
Expand All @@ -198,7 +200,7 @@ mod tests {
chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"User Checking".to_string(),
"sub-user-checking".to_string(),
dummy_audit_info(),
Expand All @@ -213,6 +215,7 @@ mod tests {
{
let control_account = chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Equity,
"Shareholder Equity".to_string(),
"shareholder-equity".to_string(),
Expand All @@ -222,7 +225,7 @@ mod tests {
chart
.create_control_sub_account(
LedgerAccountSetId::new(),
control_account,
control_account.path,
"Shareholder Equity".to_string(),
"sub-shareholder-equity".to_string(),
dummy_audit_info(),
Expand All @@ -237,6 +240,7 @@ mod tests {
{
chart
.create_control_account(
LedgerAccountSetId::new(),
ChartCategory::Revenues,
"Interest Revenue".to_string(),
"interest-revenue".to_string(),
Expand Down
Loading

0 comments on commit ca93a08

Please sign in to comment.