diff --git a/libdrcr/plugins/austax/plugin.luau b/libdrcr/plugins/austax/init.luau similarity index 86% rename from libdrcr/plugins/austax/plugin.luau rename to libdrcr/plugins/austax/init.luau index 9283d45..40c28ea 100644 --- a/libdrcr/plugins/austax/plugin.luau +++ b/libdrcr/plugins/austax/init.luau @@ -1,5 +1,5 @@ --!strict --- DrCr: Web-based double-entry bookkeeping framework +-- DrCr: Double-entry bookkeeping framework -- Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo) -- -- This program is free software: you can redistribute it and/or modify @@ -15,8 +15,8 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -local libdrcr = require('../libdrcr') -local reporting = require('../austax/reporting') +local libdrcr = require('./libdrcr') +local reporting = require('./austax/reporting') local plugin: libdrcr.Plugin = { name = 'austax', diff --git a/libdrcr/src/db.rs b/libdrcr/src/db.rs index fd8fe70..5410a32 100644 --- a/libdrcr/src/db.rs +++ b/libdrcr/src/db.rs @@ -1,5 +1,5 @@ /* - DrCr: Web-based double-entry bookkeeping framework + DrCr: Double-entry bookkeeping framework Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify @@ -216,6 +216,7 @@ pub struct DbMetadata { pub eofy_date: NaiveDate, pub reporting_commodity: String, pub dps: u32, + pub plugins: Vec, } impl DbMetadata { @@ -256,11 +257,27 @@ impl DbMetadata { .await .expect("SQL error"); + let plugins_joined = sqlx::query("SELECT value FROM metadata WHERE key = 'plugins'") + .map(|r: SqliteRow| r.get::(0)) + .fetch_one(&mut *connection) + .await + .expect("SQL error"); + + let plugins = if plugins_joined.len() > 0 { + plugins_joined + .split(';') + .map(String::from) + .collect::>() + } else { + vec![] + }; + DbMetadata { version, eofy_date, reporting_commodity, dps, + plugins, } } } diff --git a/libdrcr/src/main.rs b/libdrcr/src/main.rs index 86a420e..d973651 100644 --- a/libdrcr/src/main.rs +++ b/libdrcr/src/main.rs @@ -39,7 +39,7 @@ async fn main() { let mut context = ReportingContext::new( db_connection, "plugins".to_string(), - vec!["austax.plugin".to_string()], + vec!["austax".to_string()], NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(), "$".to_string(), ); diff --git a/libdrcr/src/plugin.rs b/libdrcr/src/plugin.rs index b9b53db..631977a 100644 --- a/libdrcr/src/plugin.rs +++ b/libdrcr/src/plugin.rs @@ -1,5 +1,5 @@ /* - DrCr: Web-based double-entry bookkeeping framework + DrCr: Double-entry bookkeeping framework Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify @@ -41,7 +41,7 @@ fn load_plugin(plugin_dir: &str, plugin_name: &str) -> (Lua, Plugin) { // Init Lua environment let package = lua.globals().get::("package").unwrap(); package - .set("path", format!("{}/?.luau", plugin_dir)) + .set("path", format!("{0}/?.luau;{0}/?/init.luau", plugin_dir)) .unwrap(); // Require and call the plugin diff --git a/src-tauri/src/libdrcr_bridge.rs b/src-tauri/src/libdrcr_bridge.rs index c3adfb1..e118fb4 100644 --- a/src-tauri/src/libdrcr_bridge.rs +++ b/src-tauri/src/libdrcr_bridge.rs @@ -1,5 +1,5 @@ /* - DrCr: Web-based double-entry bookkeeping framework + DrCr: Double-entry bookkeeping framework Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo) This program is free software: you can redistribute it and/or modify @@ -42,11 +42,6 @@ fn prepare_reporting_context(context: &mut ReportingContext) { libdrcr::plugin::register_lookup_fns(context); } -fn get_plugins() -> Vec { - // FIXME: Dynamically get this - vec!["austax.plugin".to_string()] -} - pub(crate) async fn get_report( app: AppHandle, state: State<'_, Mutex>, @@ -61,6 +56,7 @@ pub(crate) async fn get_report( // Initialise ReportingContext let eofy_date = db_connection.metadata().eofy_date; + let plugin_names = db_connection.metadata().plugins.clone(); let mut context = ReportingContext::new( db_connection, app.path() @@ -69,22 +65,25 @@ pub(crate) async fn get_report( .to_str() .unwrap() .to_string(), - get_plugins(), + plugin_names, eofy_date, "$".to_string(), ); prepare_reporting_context(&mut context); // Get dynamic report - let targets = vec![ - // FIXME: Make this configurable - ReportingProductId { + let mut targets = vec![target.clone()]; + + // Add plugin targets + // FIXME: Detect this robustly + if context.plugin_names.contains(&"austax".to_string()) { + targets.push(ReportingProductId { name: "CalculateIncomeTax".to_string(), kind: ReportingProductKind::Transactions, args: ReportingStepArgs::VoidArgs, - }, - target.clone(), - ]; + }); + } + let products = generate_report(targets, Arc::new(context)).await.unwrap(); let result = products.get_owned_or_err(&target).unwrap(); @@ -262,6 +261,7 @@ pub(crate) async fn get_validated_balance_assertions( // Initialise ReportingContext let eofy_date = db_connection.metadata().eofy_date; + let plugin_names = db_connection.metadata().plugins.clone(); let mut context = ReportingContext::new( db_connection, app.path() @@ -270,7 +270,7 @@ pub(crate) async fn get_validated_balance_assertions( .to_str() .unwrap() .to_string(), - get_plugins(), + plugin_names, eofy_date, "$".to_string(), );