From ad3276bbd53ae06dcf9c048148ace0fa8bef162b Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 27 May 2025 23:49:34 +1000 Subject: [PATCH] General ledger report using libdrcr --- src-tauri/src/lib.rs | 1 + src-tauri/src/libdrcr_bridge.rs | 54 ++++-- src/pages/GeneralLedgerView.vue | 16 +- src/reporting.ts | 294 -------------------------------- 4 files changed, 46 insertions(+), 319 deletions(-) delete mode 100644 src/reporting.ts diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d8da86e..4033df5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -90,6 +90,7 @@ pub fn run() { .invoke_handler(tauri::generate_handler![ get_open_filename, set_open_filename, + libdrcr_bridge::get_all_transactions_except_earnings_to_equity, libdrcr_bridge::get_balance_sheet, libdrcr_bridge::get_income_statement, libdrcr_bridge::get_trial_balance, diff --git a/src-tauri/src/libdrcr_bridge.rs b/src-tauri/src/libdrcr_bridge.rs index a55384f..4087ed2 100644 --- a/src-tauri/src/libdrcr_bridge.rs +++ b/src-tauri/src/libdrcr_bridge.rs @@ -26,17 +26,18 @@ use libdrcr::reporting::generate_report; use libdrcr::reporting::steps::register_lookup_fns; use libdrcr::reporting::types::{ DateArgs, DateStartDateEndArgs, MultipleDateArgs, MultipleDateStartDateEndArgs, - ReportingContext, ReportingProductId, ReportingProductKind, VoidArgs, + ReportingContext, ReportingProduct, ReportingProductId, ReportingProductKind, Transactions, + VoidArgs, }; use tauri::State; use tokio::sync::Mutex; use crate::AppState; -async fn get_dynamic_report( +async fn get_report( state: State<'_, Mutex>, - target: ReportingProductId, -) -> Result { + target: &ReportingProductId, +) -> Box { let state = state.lock().await; let db_filename = state.db_filename.clone().unwrap(); @@ -60,11 +61,29 @@ async fn get_dynamic_report( target.clone(), ]; let products = generate_report(targets, Arc::new(context)).await.unwrap(); - let result = products.get_or_err(&target).unwrap(); + let result = products.get_owned_or_err(&target).unwrap(); - let dynamic_report = result.downcast_ref::().unwrap().to_json(); + result +} - Ok(dynamic_report) +#[tauri::command] +pub(crate) async fn get_all_transactions_except_earnings_to_equity( + state: State<'_, Mutex>, +) -> Result { + Ok(get_report( + state, + &ReportingProductId { + name: "AllTransactionsExceptEarningsToEquity", + kind: ReportingProductKind::Transactions, + args: Box::new(DateArgs { + date: NaiveDate::from_ymd_opt(9999, 12, 31).unwrap(), + }), + }, + ) + .await + .downcast_ref::() + .unwrap() + .to_json()) } #[tauri::command] @@ -79,9 +98,9 @@ pub(crate) async fn get_balance_sheet( }) } - get_dynamic_report( + Ok(get_report( state, - ReportingProductId { + &ReportingProductId { name: "BalanceSheet", kind: ReportingProductKind::Generic, args: Box::new(MultipleDateArgs { @@ -90,6 +109,9 @@ pub(crate) async fn get_balance_sheet( }, ) .await + .downcast_ref::() + .unwrap() + .to_json()) } #[tauri::command] @@ -105,9 +127,9 @@ pub(crate) async fn get_income_statement( }) } - get_dynamic_report( + Ok(get_report( state, - ReportingProductId { + &ReportingProductId { name: "IncomeStatement", kind: ReportingProductKind::Generic, args: Box::new(MultipleDateStartDateEndArgs { @@ -116,6 +138,9 @@ pub(crate) async fn get_income_statement( }, ) .await + .downcast_ref::() + .unwrap() + .to_json()) } #[tauri::command] @@ -125,13 +150,16 @@ pub(crate) async fn get_trial_balance( ) -> Result { let date = NaiveDate::parse_from_str(&date, "%Y-%m-%d").expect("Invalid date"); - get_dynamic_report( + Ok(get_report( state, - ReportingProductId { + &ReportingProductId { name: "TrialBalance", kind: ReportingProductKind::Generic, args: Box::new(DateArgs { date }), }, ) .await + .downcast_ref::() + .unwrap() + .to_json()) } diff --git a/src/pages/GeneralLedgerView.vue b/src/pages/GeneralLedgerView.vue index 3c6cc1d..a57df41 100644 --- a/src/pages/GeneralLedgerView.vue +++ b/src/pages/GeneralLedgerView.vue @@ -60,16 +60,13 @@