libdrcr: Allow configuring backend plugins
This commit is contained in:
parent
94255ffb9d
commit
02667695cc
@ -1,5 +1,5 @@
|
|||||||
--!strict
|
--!strict
|
||||||
-- DrCr: Web-based double-entry bookkeeping framework
|
-- DrCr: Double-entry bookkeeping framework
|
||||||
-- Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
-- Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||||
--
|
--
|
||||||
-- This program is free software: you can redistribute it and/or modify
|
-- 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
|
-- You should have received a copy of the GNU Affero General Public License
|
||||||
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local libdrcr = require('../libdrcr')
|
local libdrcr = require('./libdrcr')
|
||||||
local reporting = require('../austax/reporting')
|
local reporting = require('./austax/reporting')
|
||||||
|
|
||||||
local plugin: libdrcr.Plugin = {
|
local plugin: libdrcr.Plugin = {
|
||||||
name = 'austax',
|
name = 'austax',
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: Double-entry bookkeeping framework
|
||||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@ -216,6 +216,7 @@ pub struct DbMetadata {
|
|||||||
pub eofy_date: NaiveDate,
|
pub eofy_date: NaiveDate,
|
||||||
pub reporting_commodity: String,
|
pub reporting_commodity: String,
|
||||||
pub dps: u32,
|
pub dps: u32,
|
||||||
|
pub plugins: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DbMetadata {
|
impl DbMetadata {
|
||||||
@ -256,11 +257,27 @@ impl DbMetadata {
|
|||||||
.await
|
.await
|
||||||
.expect("SQL error");
|
.expect("SQL error");
|
||||||
|
|
||||||
|
let plugins_joined = sqlx::query("SELECT value FROM metadata WHERE key = 'plugins'")
|
||||||
|
.map(|r: SqliteRow| r.get::<String, _>(0))
|
||||||
|
.fetch_one(&mut *connection)
|
||||||
|
.await
|
||||||
|
.expect("SQL error");
|
||||||
|
|
||||||
|
let plugins = if plugins_joined.len() > 0 {
|
||||||
|
plugins_joined
|
||||||
|
.split(';')
|
||||||
|
.map(String::from)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
};
|
||||||
|
|
||||||
DbMetadata {
|
DbMetadata {
|
||||||
version,
|
version,
|
||||||
eofy_date,
|
eofy_date,
|
||||||
reporting_commodity,
|
reporting_commodity,
|
||||||
dps,
|
dps,
|
||||||
|
plugins,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ async fn main() {
|
|||||||
let mut context = ReportingContext::new(
|
let mut context = ReportingContext::new(
|
||||||
db_connection,
|
db_connection,
|
||||||
"plugins".to_string(),
|
"plugins".to_string(),
|
||||||
vec!["austax.plugin".to_string()],
|
vec!["austax".to_string()],
|
||||||
NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
||||||
"$".to_string(),
|
"$".to_string(),
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: Double-entry bookkeeping framework
|
||||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
// Init Lua environment
|
||||||
let package = lua.globals().get::<Table>("package").unwrap();
|
let package = lua.globals().get::<Table>("package").unwrap();
|
||||||
package
|
package
|
||||||
.set("path", format!("{}/?.luau", plugin_dir))
|
.set("path", format!("{0}/?.luau;{0}/?/init.luau", plugin_dir))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Require and call the plugin
|
// Require and call the plugin
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DrCr: Web-based double-entry bookkeeping framework
|
DrCr: Double-entry bookkeeping framework
|
||||||
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
Copyright (C) 2022-2025 Lee Yingtong Li (RunasSudo)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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);
|
libdrcr::plugin::register_lookup_fns(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_plugins() -> Vec<String> {
|
|
||||||
// FIXME: Dynamically get this
|
|
||||||
vec!["austax.plugin".to_string()]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn get_report(
|
pub(crate) async fn get_report(
|
||||||
app: AppHandle,
|
app: AppHandle,
|
||||||
state: State<'_, Mutex<AppState>>,
|
state: State<'_, Mutex<AppState>>,
|
||||||
@ -61,6 +56,7 @@ pub(crate) async fn get_report(
|
|||||||
|
|
||||||
// Initialise ReportingContext
|
// Initialise ReportingContext
|
||||||
let eofy_date = db_connection.metadata().eofy_date;
|
let eofy_date = db_connection.metadata().eofy_date;
|
||||||
|
let plugin_names = db_connection.metadata().plugins.clone();
|
||||||
let mut context = ReportingContext::new(
|
let mut context = ReportingContext::new(
|
||||||
db_connection,
|
db_connection,
|
||||||
app.path()
|
app.path()
|
||||||
@ -69,22 +65,25 @@ pub(crate) async fn get_report(
|
|||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
get_plugins(),
|
plugin_names,
|
||||||
eofy_date,
|
eofy_date,
|
||||||
"$".to_string(),
|
"$".to_string(),
|
||||||
);
|
);
|
||||||
prepare_reporting_context(&mut context);
|
prepare_reporting_context(&mut context);
|
||||||
|
|
||||||
// Get dynamic report
|
// Get dynamic report
|
||||||
let targets = vec![
|
let mut targets = vec![target.clone()];
|
||||||
// FIXME: Make this configurable
|
|
||||||
ReportingProductId {
|
// Add plugin targets
|
||||||
|
// FIXME: Detect this robustly
|
||||||
|
if context.plugin_names.contains(&"austax".to_string()) {
|
||||||
|
targets.push(ReportingProductId {
|
||||||
name: "CalculateIncomeTax".to_string(),
|
name: "CalculateIncomeTax".to_string(),
|
||||||
kind: ReportingProductKind::Transactions,
|
kind: ReportingProductKind::Transactions,
|
||||||
args: ReportingStepArgs::VoidArgs,
|
args: ReportingStepArgs::VoidArgs,
|
||||||
},
|
});
|
||||||
target.clone(),
|
}
|
||||||
];
|
|
||||||
let products = generate_report(targets, Arc::new(context)).await.unwrap();
|
let products = generate_report(targets, Arc::new(context)).await.unwrap();
|
||||||
let result = products.get_owned_or_err(&target).unwrap();
|
let result = products.get_owned_or_err(&target).unwrap();
|
||||||
|
|
||||||
@ -262,6 +261,7 @@ pub(crate) async fn get_validated_balance_assertions(
|
|||||||
|
|
||||||
// Initialise ReportingContext
|
// Initialise ReportingContext
|
||||||
let eofy_date = db_connection.metadata().eofy_date;
|
let eofy_date = db_connection.metadata().eofy_date;
|
||||||
|
let plugin_names = db_connection.metadata().plugins.clone();
|
||||||
let mut context = ReportingContext::new(
|
let mut context = ReportingContext::new(
|
||||||
db_connection,
|
db_connection,
|
||||||
app.path()
|
app.path()
|
||||||
@ -270,18 +270,14 @@ pub(crate) async fn get_validated_balance_assertions(
|
|||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
get_plugins(),
|
plugin_names,
|
||||||
eofy_date,
|
eofy_date,
|
||||||
"$".to_string(),
|
"$".to_string(),
|
||||||
);
|
);
|
||||||
prepare_reporting_context(&mut context);
|
prepare_reporting_context(&mut context);
|
||||||
|
|
||||||
// Get report targets
|
// Get report targets
|
||||||
let mut targets = vec![ReportingProductId {
|
let mut targets = Vec::new();
|
||||||
name: "CalculateIncomeTax".to_string(),
|
|
||||||
kind: ReportingProductKind::Transactions,
|
|
||||||
args: ReportingStepArgs::VoidArgs,
|
|
||||||
}];
|
|
||||||
for dt in dates {
|
for dt in dates {
|
||||||
// Request ordinary transaction balances at each balance assertion date
|
// Request ordinary transaction balances at each balance assertion date
|
||||||
targets.push(ReportingProductId {
|
targets.push(ReportingProductId {
|
||||||
@ -290,6 +286,16 @@ pub(crate) async fn get_validated_balance_assertions(
|
|||||||
args: ReportingStepArgs::DateArgs(DateArgs { date: dt.date() }),
|
args: ReportingStepArgs::DateArgs(DateArgs { date: dt.date() }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Run report
|
// Run report
|
||||||
let products = generate_report(targets, Arc::new(context)).await.unwrap();
|
let products = generate_report(targets, Arc::new(context)).await.unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user