From 38410376b5d209e737f6c410d7a8f33700b25475 Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:27:54 -0400 Subject: [PATCH] chore: start integrating trial_balance gql query --- lana/admin-server/src/graphql/primitives.rs | 18 ++++++++++++ lana/admin-server/src/graphql/schema.rs | 28 +++++++++++-------- lana/app/src/accounting_init/constants/mod.rs | 4 +-- lana/app/src/app/mod.rs | 8 ++++++ 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lana/admin-server/src/graphql/primitives.rs b/lana/admin-server/src/graphql/primitives.rs index 57e30a3d20..2ae4946f05 100644 --- a/lana/admin-server/src/graphql/primitives.rs +++ b/lana/admin-server/src/graphql/primitives.rs @@ -1,3 +1,6 @@ +use lana_app::primitives::Currency; +use serde::{Deserialize, Serialize}; + #[derive(async_graphql::Enum, Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum SortDirection { #[default] @@ -13,3 +16,18 @@ impl From for es_entity::ListDirection { } } } + +#[derive(Serialize, Deserialize, Clone)] +#[serde(transparent)] +pub struct CurrencyCode(Currency); +scalar!(CurrencyCode); +impl From for Currency { + fn from(code: CurrencyCode) -> Self { + code.0 + } +} +impl From for CurrencyCode { + fn from(code: Currency) -> Self { + Self(code) + } +} diff --git a/lana/admin-server/src/graphql/schema.rs b/lana/admin-server/src/graphql/schema.rs index ac2ee4d7bf..63eb70dac4 100644 --- a/lana/admin-server/src/graphql/schema.rs +++ b/lana/admin-server/src/graphql/schema.rs @@ -1,7 +1,7 @@ use async_graphql::{types::connection::*, Context, Object}; use lana_app::{ - accounting_init::constants::{CHART_REF, OBS_CHART_REF}, + accounting_init::constants::{CHART_REF, OBS_CHART_REF, TRIAL_BALANCE_STATEMENT_NAME}, app::LanaApp, }; @@ -10,8 +10,8 @@ use crate::primitives::*; use super::{ 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::*, + loader::*, policy::*, price::*, report::*, sumsub::*, terms_template::*, trial_balance::*, + user::*, withdrawal::*, }; pub struct Query; @@ -394,16 +394,20 @@ impl Query { async fn trial_balance( &self, ctx: &Context<'_>, - from: Timestamp, - until: Option, + currency: CurrencyCode, + // from: Timestamp, + // until: Option, ) -> async_graphql::Result> { - unimplemented!() - // let (app, sub) = app_and_sub_from_ctx!(ctx); - // let account_summary = app - // .ledger() - // .trial_balance(sub, from.into_inner(), until.map(|t| t.into_inner())) - // .await?; - // Ok(account_summary.map(TrialBalance::from)) + let (app, sub) = app_and_sub_from_ctx!(ctx); + let account_summary = app + .trial_balances() + .trial_balance( + sub, + TRIAL_BALANCE_STATEMENT_NAME.to_string(), + currency.into(), + ) + .await?; + Ok(account_summary.map(TrialBalance::from)) } #[allow(unused_variables)] diff --git a/lana/app/src/accounting_init/constants/mod.rs b/lana/app/src/accounting_init/constants/mod.rs index cce872df36..f4408f25a2 100644 --- a/lana/app/src/accounting_init/constants/mod.rs +++ b/lana/app/src/accounting_init/constants/mod.rs @@ -12,6 +12,6 @@ pub(super) const CHART_NAME: &str = "Chart of Accounts"; 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 TRIAL_BALANCE_STATEMENT_NAME: &str = "Trial Balance"; +pub const TRIAL_BALANCE_STATEMENT_NAME: &str = "Trial Balance"; -pub(super) const OBS_TRIAL_BALANCE_STATEMENT_NAME: &str = "Off-Balance-Sheet Trial Balance"; +pub const OBS_TRIAL_BALANCE_STATEMENT_NAME: &str = "Off-Balance-Sheet Trial Balance"; diff --git a/lana/app/src/app/mod.rs b/lana/app/src/app/mod.rs index 1bcf246ed1..8c34ed53f8 100644 --- a/lana/app/src/app/mod.rs +++ b/lana/app/src/app/mod.rs @@ -44,6 +44,7 @@ pub struct LanaApp { applicants: Applicants, users: Users, credit_facilities: CreditFacilities, + trial_balances: TrialBalances, price: Price, report: Reports, terms_templates: TermsTemplates, @@ -117,6 +118,8 @@ impl LanaApp { journal_init.journal_id, ) .await?; + let trial_balances = + TrialBalances::init(&pool, &authz, &cala, journal_init.journal_id).await?; let terms_templates = TermsTemplates::new(&pool, &authz); jobs.start_poll().await?; @@ -133,6 +136,7 @@ impl LanaApp { price, report, credit_facilities, + trial_balances, terms_templates, documents, _outbox: outbox, @@ -196,6 +200,10 @@ impl LanaApp { &self.credit_facilities } + pub fn trial_balances(&self) -> &TrialBalances { + &self.trial_balances + } + pub fn users(&self) -> &Users { &self.users }