Skip to content

Commit

Permalink
chore: start integrating trial_balance gql query
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 23, 2025
1 parent 8855ba9 commit 6986d3a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
18 changes: 18 additions & 0 deletions lana/admin-server/src/graphql/primitives.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -13,3 +16,18 @@ impl From<SortDirection> for es_entity::ListDirection {
}
}
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct CurrencyCode(Currency);
scalar!(CurrencyCode);
impl From<CurrencyCode> for Currency {
fn from(code: CurrencyCode) -> Self {
code.0
}
}
impl From<Currency> for CurrencyCode {
fn from(code: Currency) -> Self {
Self(code)
}
}
28 changes: 16 additions & 12 deletions lana/admin-server/src/graphql/schema.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -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;
Expand Down Expand Up @@ -394,16 +394,20 @@ impl Query {
async fn trial_balance(
&self,
ctx: &Context<'_>,
from: Timestamp,
until: Option<Timestamp>,
currency: CurrencyCode,
// from: Timestamp,
// until: Option<Timestamp>,
) -> async_graphql::Result<Option<TrialBalance>> {
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)]
Expand Down
4 changes: 2 additions & 2 deletions lana/app/src/accounting_init/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 8 additions & 0 deletions lana/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct LanaApp {
applicants: Applicants,
users: Users,
credit_facilities: CreditFacilities,
trial_balances: TrialBalances,
price: Price,
report: Reports,
terms_templates: TermsTemplates,
Expand Down Expand Up @@ -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?;

Expand All @@ -133,6 +136,7 @@ impl LanaApp {
price,
report,
credit_facilities,
trial_balances,
terms_templates,
documents,
_outbox: outbox,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6986d3a

Please sign in to comment.