Skip to content

Commit

Permalink
chore: change ChartOfAccounts gql query to new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 16, 2025
1 parent 5289e12 commit 1cc77c6
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 45 deletions.
121 changes: 121 additions & 0 deletions lana/admin-server/src/graphql/chart_of_accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use async_graphql::*;

use lana_app::chart_of_accounts::chart::*;

#[derive(SimpleObject)]
pub struct ChartOfAccounts {
name: String,
categories: ChartCategories,
}

impl From<ChartOfAccountsProjection> for ChartOfAccounts {
fn from(projection: ChartOfAccountsProjection) -> Self {
ChartOfAccounts {
name: projection.name,
categories: ChartCategories {
assets: ChartCategory {
name: projection.assets.name,
account_code: projection.assets.encoded_path,
control_accounts: projection
.assets
.children
.into_iter()
.map(ChartControlAccount::from)
.collect(),
},
liabilities: ChartCategory {
name: projection.liabilities.name,
account_code: projection.liabilities.encoded_path,
control_accounts: projection
.liabilities
.children
.into_iter()
.map(ChartControlAccount::from)
.collect(),
},
equity: ChartCategory {
name: projection.equity.name,
account_code: projection.equity.encoded_path,
control_accounts: projection
.equity
.children
.into_iter()
.map(ChartControlAccount::from)
.collect(),
},
revenues: ChartCategory {
name: projection.revenues.name,
account_code: projection.revenues.encoded_path,
control_accounts: projection
.revenues
.children
.into_iter()
.map(ChartControlAccount::from)
.collect(),
},
expenses: ChartCategory {
name: projection.expenses.name,
account_code: projection.expenses.encoded_path,
control_accounts: projection
.expenses
.children
.into_iter()
.map(ChartControlAccount::from)
.collect(),
},
},
}
}
}

#[derive(SimpleObject)]
pub struct ChartCategories {
assets: ChartCategory,
liabilities: ChartCategory,
equity: ChartCategory,
revenues: ChartCategory,
expenses: ChartCategory,
}

#[derive(SimpleObject)]
pub struct ChartCategory {
name: String,
account_code: String,
control_accounts: Vec<ChartControlAccount>,
}

#[derive(SimpleObject)]
pub struct ChartControlAccount {
name: String,
account_code: String,
control_sub_accounts: Vec<ChartControlSubAccount>,
}

impl From<ControlAccountProjection> for ChartControlAccount {
fn from(projection: ControlAccountProjection) -> Self {
ChartControlAccount {
name: projection.name,
account_code: projection.encoded_path,
control_sub_accounts: projection
.children
.into_iter()
.map(ChartControlSubAccount::from)
.collect(),
}
}
}

#[derive(SimpleObject)]
pub struct ChartControlSubAccount {
name: String,
account_code: String,
}

impl From<ControlSubAccountProjection> for ChartControlSubAccount {
fn from(projection: ControlSubAccountProjection) -> Self {
ChartControlSubAccount {
name: projection.name,
account_code: projection.encoded_path,
}
}
}
2 changes: 1 addition & 1 deletion lana/admin-server/src/graphql/financials/balance_sheet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::*;

use super::chart_of_accounts::*;
use super::category::*;
use crate::graphql::account::*;

#[derive(SimpleObject)]
Expand Down
2 changes: 1 addition & 1 deletion lana/admin-server/src/graphql/financials/cash_flow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::*;

use super::chart_of_accounts::*;
use super::category::*;
use crate::graphql::account::*;

#[derive(SimpleObject)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@ use async_graphql::*;
use super::account_set::*;
use crate::graphql::account::*;

#[derive(SimpleObject)]
pub struct ChartOfAccounts {
name: String,
categories: Vec<StatementCategory>,
}

impl From<lana_app::ledger::account_set::LedgerChartOfAccounts> for ChartOfAccounts {
fn from(chart_of_accounts: lana_app::ledger::account_set::LedgerChartOfAccounts) -> Self {
ChartOfAccounts {
name: chart_of_accounts.name,
categories: chart_of_accounts
.categories
.into_iter()
.map(StatementCategory::from)
.collect(),
}
}
}

#[derive(SimpleObject)]
pub struct StatementCategory {
name: String,
Expand Down
3 changes: 1 addition & 2 deletions lana/admin-server/src/graphql/financials/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
mod account_set;
mod balance_sheet;
mod cash_flow;
mod chart_of_accounts;
mod category;
mod profit_and_loss;
mod shareholder_equity;
mod trial_balance;

pub use account_set::*;
pub use balance_sheet::*;
pub use cash_flow::*;
pub use chart_of_accounts::*;
pub use profit_and_loss::*;
pub use shareholder_equity::*;
pub use trial_balance::*;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::*;

use super::chart_of_accounts::*;
use super::category::*;
use crate::graphql::account::*;

#[derive(SimpleObject)]
Expand Down
1 change: 1 addition & 0 deletions lana/admin-server/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod approval_process;
mod approval_rules;
mod audit;
mod authenticated_subject;
mod chart_of_accounts;
mod committee;
mod credit_facility;
mod customer;
Expand Down
31 changes: 28 additions & 3 deletions lana/admin-server/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,34 @@ type CashFlowStatement {
categories: [StatementCategory!]!
}

type ChartCategories {
assets: ChartCategory!
liabilities: ChartCategory!
equity: ChartCategory!
revenues: ChartCategory!
expenses: ChartCategory!
}

type ChartCategory {
name: String!
accountCode: String!
controlAccounts: [ChartControlAccount!]!
}

type ChartControlAccount {
name: String!
accountCode: String!
controlSubAccounts: [ChartControlSubAccount!]!
}

type ChartControlSubAccount {
name: String!
accountCode: String!
}

type ChartOfAccounts {
name: String!
categories: [StatementCategory!]!
categories: ChartCategories!
}

type Collateral {
Expand Down Expand Up @@ -941,8 +966,8 @@ type Query {
document(id: UUID!): Document
trialBalance(from: Timestamp!, until: Timestamp): TrialBalance
offBalanceSheetTrialBalance(from: Timestamp!, until: Timestamp): TrialBalance
chartOfAccounts: ChartOfAccounts
offBalanceSheetChartOfAccounts: ChartOfAccounts
chartOfAccounts: ChartOfAccounts!
offBalanceSheetChartOfAccounts: ChartOfAccounts!
balanceSheet(from: Timestamp!, until: Timestamp): BalanceSheet
profitAndLossStatement(from: Timestamp!, until: Timestamp): ProfitAndLossStatement
cashFlowStatement(from: Timestamp!, until: Timestamp): CashFlowStatement
Expand Down
51 changes: 38 additions & 13 deletions lana/admin-server/src/graphql/schema.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use async_graphql::{types::connection::*, Context, Object};

use lana_app::app::LanaApp;
use lana_app::{
accounting_init::constants::{CHART_REF, OBS_CHART_REF},
app::LanaApp,
};

use crate::primitives::*;

use super::{
approval_process::*, audit::*, authenticated_subject::*, committee::*, credit_facility::*,
customer::*, dashboard::*, deposit::*, document::*, financials::*, loader::*, policy::*,
price::*, report::*, sumsub::*, terms_template::*, user::*, withdrawal::*,
approval_process::*, audit::*, authenticated_subject::*, chart_of_accounts::*, committee::*,
credit_facility::*, customer::*, dashboard::*, deposit::*, document::*, financials::*,
loader::*, policy::*, price::*, report::*, sumsub::*, terms_template::*, user::*,
withdrawal::*,
};

pub struct Query;
Expand Down Expand Up @@ -414,22 +418,43 @@ impl Query {
Ok(account_summary.map(TrialBalance::from))
}

async fn chart_of_accounts(
&self,
ctx: &Context<'_>,
) -> async_graphql::Result<Option<ChartOfAccounts>> {
async fn chart_of_accounts(&self, ctx: &Context<'_>) -> async_graphql::Result<ChartOfAccounts> {
let reference = CHART_REF.to_string();

let (app, sub) = app_and_sub_from_ctx!(ctx);
let chart_of_accounts = app.ledger().chart_of_accounts(sub).await?;
Ok(chart_of_accounts.map(ChartOfAccounts::from))
let chart_projection = app
.chart_of_accounts()
.list_charts(sub)
.await?
.into_iter()
.find(|p| p.reference == reference)
.expect(&format!(
"Chart of accounts not found for ref {}",
reference
))
.chart();
Ok(ChartOfAccounts::from(chart_projection))
}

async fn off_balance_sheet_chart_of_accounts(
&self,
ctx: &Context<'_>,
) -> async_graphql::Result<Option<ChartOfAccounts>> {
) -> async_graphql::Result<ChartOfAccounts> {
let reference = OBS_CHART_REF.to_string();

let (app, sub) = app_and_sub_from_ctx!(ctx);
let chart_of_accounts = app.ledger().obs_chart_of_accounts(sub).await?;
Ok(chart_of_accounts.map(ChartOfAccounts::from))
let chart_projection = app
.chart_of_accounts()
.list_charts(sub)
.await?
.into_iter()
.find(|p| p.reference == reference)
.expect(&format!(
"Chart of accounts not found for ref {}",
reference
))
.chart();
Ok(ChartOfAccounts::from(chart_projection))
}

async fn balance_sheet(
Expand Down
4 changes: 2 additions & 2 deletions lana/app/src/accounting_init/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(super) const LANA_JOURNAL_CODE: &str = "LANA_BANK_JOURNAL";

pub(super) const CHART_REF: &str = "primary-chart";
pub const CHART_REF: &str = "primary-chart";
pub(super) const CHART_NAME: &str = "Chart of Accounts";

pub(super) const DEPOSITS_CONTROL_ACCOUNT_REF: &str = "deposits";
Expand Down Expand Up @@ -44,7 +44,7 @@ pub(super) const CREDIT_FACILITIES_FEE_INCOME_CONTROL_SUB_ACCOUNT_REF: &str =
pub(super) const CREDIT_FACILITIES_FEE_INCOME_CONTROL_SUB_ACCOUNT_NAME: &str =
"Fixed Term Credit Facilities Fee Income"; // Revenue

pub(super) const OBS_CHART_REF: &str = "off-balance-sheet-chart";
pub const OBS_CHART_REF: &str = "off-balance-sheet-chart";
pub(super) const OBS_CHART_NAME: &str = "Off-Balance-Sheet Chart of Accounts";

pub(super) const CREDIT_FACILITIES_COLLATERAL_CONTROL_ACCOUNT_REF: &str =
Expand Down
2 changes: 1 addition & 1 deletion lana/app/src/accounting_init/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod constants;
pub mod constants;
mod primitives;
mod seed;

Expand Down
8 changes: 6 additions & 2 deletions lana/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct LanaApp {
_jobs: Jobs,
audit: Audit,
authz: Authorization,
chart_of_accounts: ChartOfAccounts,
customers: Customers,
deposits: Deposits,
ledger: Ledger,
Expand All @@ -52,7 +53,6 @@ pub struct LanaApp {
_outbox: Outbox,
governance: Governance,
dashboard: Dashboard,
_chart_of_accounts: ChartOfAccounts,
}

impl LanaApp {
Expand Down Expand Up @@ -153,6 +153,7 @@ impl LanaApp {
_jobs: jobs,
audit,
authz,
chart_of_accounts,
customers,
deposits,
ledger,
Expand All @@ -166,7 +167,6 @@ impl LanaApp {
_outbox: outbox,
governance,
dashboard,
_chart_of_accounts: chart_of_accounts,
})
}

Expand Down Expand Up @@ -209,6 +209,10 @@ impl LanaApp {
self.audit.list(query).await.map_err(ApplicationError::from)
}

pub fn chart_of_accounts(&self) -> &ChartOfAccounts {
&self.chart_of_accounts
}

pub fn deposits(&self) -> &Deposits {
&self.deposits
}
Expand Down
Loading

0 comments on commit 1cc77c6

Please sign in to comment.