Change ReportingStepArgs to enum not trait
Preparation for plugins
This commit is contained in:
parent
c422b53f16
commit
97644042a3
14
libdrcr/Cargo.lock
generated
14
libdrcr/Cargo.lock
generated
@ -278,18 +278,6 @@ version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005"
|
||||
|
||||
[[package]]
|
||||
name = "dyn-eq"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c2d035d21af5cde1a6f5c7b444a5bf963520a9f142e5d06931178433d7d5388"
|
||||
|
||||
[[package]]
|
||||
name = "dyn-hash"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15401da73a9ed8c80e3b2d4dc05fe10e7b72d7243b9f614e516a44fa99986e88"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
@ -691,8 +679,6 @@ dependencies = [
|
||||
"chrono",
|
||||
"downcast-rs",
|
||||
"dyn-clone",
|
||||
"dyn-eq",
|
||||
"dyn-hash",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -8,8 +8,6 @@ async-trait = "0.1.88"
|
||||
chrono = "0.4.41"
|
||||
downcast-rs = "2.0.1"
|
||||
dyn-clone = "1.0.19"
|
||||
dyn-eq = "0.1.3"
|
||||
dyn-hash = "0.2.2"
|
||||
indexmap = "2.9.0"
|
||||
serde = "1.0.219"
|
||||
serde_json = "1.0.140"
|
||||
|
@ -25,7 +25,7 @@ use libdrcr::reporting::dynamic_report::DynamicReport;
|
||||
use libdrcr::reporting::generate_report;
|
||||
use libdrcr::reporting::types::{
|
||||
DateArgs, DateStartDateEndArgs, MultipleDateArgs, MultipleDateStartDateEndArgs,
|
||||
ReportingContext, ReportingProductId, ReportingProductKind, VoidArgs,
|
||||
ReportingContext, ReportingProductId, ReportingProductKind, ReportingStepArgs,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@ -53,7 +53,7 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
// ReportingProductId {
|
||||
// name: "AllTransactionsExceptEarningsToEquity",
|
||||
@ -65,7 +65,7 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateArgs {
|
||||
args: ReportingStepArgs::MultipleDateArgs(MultipleDateArgs {
|
||||
dates: vec![DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}],
|
||||
@ -74,7 +74,7 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "IncomeStatement".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateStartDateEndArgs {
|
||||
args: ReportingStepArgs::MultipleDateStartDateEndArgs(MultipleDateStartDateEndArgs {
|
||||
dates: vec![DateStartDateEndArgs {
|
||||
date_start: NaiveDate::from_ymd_opt(YEAR - 1, 7, 1).unwrap(),
|
||||
date_end: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
@ -93,12 +93,12 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(DateStartDateEndArgs {
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(DateStartDateEndArgs {
|
||||
date_start: NaiveDate::from_ymd_opt(YEAR - 1, 7, 1).unwrap(),
|
||||
date_end: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}),
|
||||
@ -113,7 +113,7 @@ async fn main() {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@ -124,7 +124,7 @@ async fn main() {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(DateStartDateEndArgs {
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(DateStartDateEndArgs {
|
||||
date_start: NaiveDate::from_ymd_opt(YEAR - 1, 7, 1).unwrap(),
|
||||
date_end: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}),
|
||||
@ -140,12 +140,12 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
ReportingProductId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateArgs {
|
||||
args: ReportingStepArgs::MultipleDateArgs(MultipleDateArgs {
|
||||
dates: vec![DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}],
|
||||
@ -160,7 +160,7 @@ async fn main() {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateArgs {
|
||||
args: ReportingStepArgs::MultipleDateArgs(MultipleDateArgs {
|
||||
dates: vec![DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}],
|
||||
@ -180,12 +180,12 @@ async fn main() {
|
||||
ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
ReportingProductId {
|
||||
name: "TrialBalance".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}),
|
||||
},
|
||||
@ -198,7 +198,7 @@ async fn main() {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "TrialBalance".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(YEAR, 6, 30).unwrap(),
|
||||
}),
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ use super::executor::ReportingExecutionError;
|
||||
use super::types::{
|
||||
BalancesAt, BalancesBetween, DateArgs, DateStartDateEndArgs, ReportingContext,
|
||||
ReportingProductId, ReportingProductKind, ReportingProducts, ReportingStep, ReportingStepArgs,
|
||||
ReportingStepDynamicBuilder, ReportingStepId, Transactions, VoidArgs,
|
||||
ReportingStepDynamicBuilder, ReportingStepId, Transactions,
|
||||
};
|
||||
|
||||
/// Call [ReportingContext::register_dynamic_builder] for all dynamic builders provided by this module
|
||||
@ -67,37 +67,35 @@ impl BalancesAtToBalancesBetween {
|
||||
fn can_build(
|
||||
name: &str,
|
||||
kind: ReportingProductKind,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
args: &ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
context: &ReportingContext,
|
||||
) -> bool {
|
||||
// Check for BalancesAt, BalancesAt -> BalancesBetween
|
||||
if kind == ReportingProductKind::BalancesBetween {
|
||||
if !args.is::<DateStartDateEndArgs>() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let args = args.downcast_ref::<DateStartDateEndArgs>().unwrap();
|
||||
|
||||
match has_step_or_can_build(
|
||||
&ReportingProductId {
|
||||
name: name.to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
date: args.date_start.clone(),
|
||||
}),
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
context,
|
||||
) {
|
||||
HasStepOrCanBuild::HasStep(_)
|
||||
| HasStepOrCanBuild::CanLookup(_)
|
||||
| HasStepOrCanBuild::CanBuild(_) => {
|
||||
return true;
|
||||
if let ReportingStepArgs::DateStartDateEndArgs(args) = args {
|
||||
match has_step_or_can_build(
|
||||
&ReportingProductId {
|
||||
name: name.to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: args.date_start.clone(),
|
||||
}),
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
context,
|
||||
) {
|
||||
HasStepOrCanBuild::HasStep(_)
|
||||
| HasStepOrCanBuild::CanLookup(_)
|
||||
| HasStepOrCanBuild::CanBuild(_) => {
|
||||
return true;
|
||||
}
|
||||
HasStepOrCanBuild::None => {}
|
||||
}
|
||||
HasStepOrCanBuild::None => {}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -106,14 +104,14 @@ impl BalancesAtToBalancesBetween {
|
||||
fn build(
|
||||
name: String,
|
||||
_kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||
_dependencies: &ReportingGraphDependencies,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(BalancesAtToBalancesBetween {
|
||||
step_name: name,
|
||||
args: *args.downcast().unwrap(),
|
||||
args: args.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -133,7 +131,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
||||
ReportingStepId {
|
||||
name: self.step_name.clone(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesBetween],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,14 +141,14 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date_start.pred_opt().unwrap(), // Opening balance is the closing balance of the preceding day
|
||||
}),
|
||||
},
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date_end,
|
||||
}),
|
||||
},
|
||||
@ -171,7 +169,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date_start.pred_opt().unwrap(), // Opening balance is the closing balance of the preceding day
|
||||
}),
|
||||
})?
|
||||
@ -183,7 +181,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date_end,
|
||||
}),
|
||||
})?
|
||||
@ -207,7 +205,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -234,7 +232,7 @@ impl GenerateBalances {
|
||||
fn can_build(
|
||||
name: &str,
|
||||
kind: ReportingProductKind,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
args: &ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
context: &ReportingContext,
|
||||
@ -273,7 +271,7 @@ impl GenerateBalances {
|
||||
&ReportingProductId {
|
||||
name: name.to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
@ -301,14 +299,14 @@ impl GenerateBalances {
|
||||
fn build(
|
||||
name: String,
|
||||
_kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||
_dependencies: &ReportingGraphDependencies,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(GenerateBalances {
|
||||
step_name: name,
|
||||
args: *args.downcast().unwrap(),
|
||||
args: args.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -325,7 +323,7 @@ impl ReportingStep for GenerateBalances {
|
||||
ReportingStepId {
|
||||
name: self.step_name.clone(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesAt],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +341,7 @@ impl ReportingStep for GenerateBalances {
|
||||
&ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
@ -357,7 +355,7 @@ impl ReportingStep for GenerateBalances {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
);
|
||||
return;
|
||||
@ -371,7 +369,7 @@ impl ReportingStep for GenerateBalances {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -410,7 +408,7 @@ impl ReportingStep for GenerateBalances {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -441,73 +439,72 @@ impl UpdateBalancesAt {
|
||||
fn can_build(
|
||||
name: &str,
|
||||
kind: ReportingProductKind,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
args: &ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
context: &ReportingContext,
|
||||
) -> bool {
|
||||
if !args.is::<DateArgs>() {
|
||||
return false;
|
||||
}
|
||||
if let ReportingStepArgs::DateArgs(args) = args {
|
||||
// Check for Transactions -> BalancesAt
|
||||
if kind == ReportingProductKind::BalancesAt {
|
||||
// Initially no need to check args
|
||||
if let Some(step) = steps.iter().find(|s| {
|
||||
s.id().name == name
|
||||
&& s.id()
|
||||
.product_kinds
|
||||
.contains(&ReportingProductKind::Transactions)
|
||||
}) {
|
||||
// Check for BalancesAt -> Transactions
|
||||
let dependencies_for_step = dependencies.dependencies_for_step(&step.id());
|
||||
if dependencies_for_step.len() == 1
|
||||
&& dependencies_for_step[0].product.kind == ReportingProductKind::BalancesAt
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for Transactions -> BalancesAt
|
||||
if kind == ReportingProductKind::BalancesAt {
|
||||
// Initially no need to check args
|
||||
if let Some(step) = steps.iter().find(|s| {
|
||||
s.id().name == name
|
||||
&& s.id()
|
||||
.product_kinds
|
||||
.contains(&ReportingProductKind::Transactions)
|
||||
}) {
|
||||
// Check for BalancesAt -> Transactions
|
||||
let dependencies_for_step = dependencies.dependencies_for_step(&step.id());
|
||||
if dependencies_for_step.len() == 1
|
||||
&& dependencies_for_step[0].product.kind == ReportingProductKind::BalancesAt
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if BalancesBetween -> Transactions and BalancesAt is available
|
||||
if dependencies_for_step.len() == 1
|
||||
&& dependencies_for_step[0].product.kind
|
||||
== ReportingProductKind::BalancesBetween
|
||||
{
|
||||
match has_step_or_can_build(
|
||||
&ReportingProductId {
|
||||
name: dependencies_for_step[0].product.name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
date: args.downcast_ref::<DateArgs>().unwrap().date,
|
||||
}),
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
context,
|
||||
) {
|
||||
HasStepOrCanBuild::HasStep(_)
|
||||
| HasStepOrCanBuild::CanLookup(_)
|
||||
| HasStepOrCanBuild::CanBuild(_) => {
|
||||
return true;
|
||||
// Check if BalancesBetween -> Transactions and BalancesAt is available
|
||||
if dependencies_for_step.len() == 1
|
||||
&& dependencies_for_step[0].product.kind
|
||||
== ReportingProductKind::BalancesBetween
|
||||
{
|
||||
match has_step_or_can_build(
|
||||
&ReportingProductId {
|
||||
name: dependencies_for_step[0].product.name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: ReportingStepArgs::DateArgs(DateArgs { date: args.date }),
|
||||
},
|
||||
steps,
|
||||
dependencies,
|
||||
context,
|
||||
) {
|
||||
HasStepOrCanBuild::HasStep(_)
|
||||
| HasStepOrCanBuild::CanLookup(_)
|
||||
| HasStepOrCanBuild::CanBuild(_) => {
|
||||
return true;
|
||||
}
|
||||
HasStepOrCanBuild::None => {}
|
||||
}
|
||||
HasStepOrCanBuild::None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fn build(
|
||||
name: String,
|
||||
_kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||
_dependencies: &ReportingGraphDependencies,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(UpdateBalancesAt {
|
||||
step_name: name,
|
||||
args: *args.downcast().unwrap(),
|
||||
args: args.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -524,7 +521,7 @@ impl ReportingStep for UpdateBalancesAt {
|
||||
ReportingStepId {
|
||||
name: self.step_name.clone(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesAt],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,7 +566,7 @@ impl ReportingStep for UpdateBalancesAt {
|
||||
ReportingProductId {
|
||||
name: dependency.name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date,
|
||||
}),
|
||||
},
|
||||
@ -626,7 +623,7 @@ impl ReportingStep for UpdateBalancesAt {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: dependency.name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: self.args.date,
|
||||
}),
|
||||
})?
|
||||
@ -651,7 +648,7 @@ impl ReportingStep for UpdateBalancesAt {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -678,7 +675,7 @@ impl UpdateBalancesBetween {
|
||||
fn can_build(
|
||||
name: &str,
|
||||
kind: ReportingProductKind,
|
||||
_args: &Box<dyn ReportingStepArgs>,
|
||||
_args: &ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
_context: &ReportingContext,
|
||||
@ -708,14 +705,14 @@ impl UpdateBalancesBetween {
|
||||
fn build(
|
||||
name: String,
|
||||
_kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||
_dependencies: &ReportingGraphDependencies,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(UpdateBalancesBetween {
|
||||
step_name: name,
|
||||
args: *args.downcast().unwrap(),
|
||||
args: args.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -732,7 +729,7 @@ impl ReportingStep for UpdateBalancesBetween {
|
||||
ReportingStepId {
|
||||
name: self.step_name.clone(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesBetween],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -767,11 +764,10 @@ impl ReportingStep for UpdateBalancesBetween {
|
||||
let dependencies_for_step = dependencies.dependencies_for_step(&parent_step.id());
|
||||
let balances_between_product = &dependencies_for_step[0].product; // Existence and uniqueness checked in can_build
|
||||
|
||||
if *balances_between_product
|
||||
.args
|
||||
.downcast_ref::<DateStartDateEndArgs>()
|
||||
.unwrap() == self.args
|
||||
{
|
||||
if matches!(
|
||||
balances_between_product.args,
|
||||
ReportingStepArgs::DateStartDateEndArgs(_)
|
||||
) {
|
||||
// Directly depends on BalanceBetween -> Transaction with appropriate date
|
||||
// Do not need to add extra dependencies
|
||||
} else {
|
||||
@ -781,7 +777,7 @@ impl ReportingStep for UpdateBalancesBetween {
|
||||
ReportingProductId {
|
||||
name: balances_between_product.name.clone(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -827,7 +823,7 @@ impl ReportingStep for UpdateBalancesBetween {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: balances_between_product.name.clone(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
})?
|
||||
.downcast_ref::<BalancesBetween>()
|
||||
.unwrap()
|
||||
@ -851,7 +847,7 @@ impl ReportingStep for UpdateBalancesBetween {
|
||||
ReportingProductId {
|
||||
name: self.step_name.clone(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
|
@ -39,7 +39,6 @@ use super::executor::ReportingExecutionError;
|
||||
use super::types::{
|
||||
BalancesBetween, DateArgs, MultipleDateArgs, MultipleDateStartDateEndArgs, ReportingContext,
|
||||
ReportingProductKind, ReportingProducts, ReportingStep, ReportingStepArgs, ReportingStepId,
|
||||
VoidArgs,
|
||||
};
|
||||
|
||||
/// Call [ReportingContext::register_lookup_fn] for all steps provided by this module
|
||||
@ -79,22 +78,16 @@ impl AllTransactionsExceptEarningsToEquity {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(AllTransactionsExceptEarningsToEquity {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(AllTransactionsExceptEarningsToEquity { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +103,7 @@ impl ReportingStep for AllTransactionsExceptEarningsToEquity {
|
||||
ReportingStepId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +112,7 @@ impl ReportingStep for AllTransactionsExceptEarningsToEquity {
|
||||
vec![ReportingProductId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}]
|
||||
}
|
||||
|
||||
@ -142,7 +135,7 @@ impl ReportingStep for AllTransactionsExceptEarningsToEquity {
|
||||
#[derive(Debug)]
|
||||
pub struct AllTransactionsExceptEarningsToEquityBalances {
|
||||
pub product_kind: ReportingProductKind,
|
||||
pub args: Box<dyn ReportingStepArgs>,
|
||||
pub args: ReportingStepArgs,
|
||||
}
|
||||
|
||||
impl AllTransactionsExceptEarningsToEquityBalances {
|
||||
@ -162,17 +155,13 @@ impl AllTransactionsExceptEarningsToEquityBalances {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
_args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
fn takes_args(_name: &str, _args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
product_kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(AllTransactionsExceptEarningsToEquityBalances { product_kind, args })
|
||||
}
|
||||
@ -261,22 +250,16 @@ impl AllTransactionsIncludingEarningsToEquity {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(AllTransactionsIncludingEarningsToEquity {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(AllTransactionsIncludingEarningsToEquity { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,7 +275,7 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
ReportingStepId {
|
||||
name: "AllTransactionsIncludingEarningsToEquity".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesAt],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,19 +285,19 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
// AllTransactionsIncludingEarningsToEquity requires CurrentYearEarningsToEquity
|
||||
ReportingProductId {
|
||||
name: "CurrentYearEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
// AllTransactionsIncludingEarningsToEquity requires RetainedEarningsToEquity
|
||||
ReportingProductId {
|
||||
name: "RetainedEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -333,7 +316,7 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
})?
|
||||
.downcast_ref::<BalancesAt>()
|
||||
.unwrap();
|
||||
@ -343,7 +326,7 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "CurrentYearEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
})?
|
||||
.downcast_ref::<Transactions>()
|
||||
.unwrap();
|
||||
@ -353,7 +336,7 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "RetainedEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
})?
|
||||
.downcast_ref::<Transactions>()
|
||||
.unwrap();
|
||||
@ -377,7 +360,7 @@ impl ReportingStep for AllTransactionsIncludingEarningsToEquity {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -401,22 +384,16 @@ impl BalanceSheet {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<MultipleDateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::MultipleDateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(BalanceSheet {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(BalanceSheet { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,7 +409,7 @@ impl ReportingStep for BalanceSheet {
|
||||
ReportingStepId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::DynamicReport],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::MultipleDateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +421,7 @@ impl ReportingStep for BalanceSheet {
|
||||
result.push(ReportingProductId {
|
||||
name: "AllTransactionsIncludingEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(date_args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(date_args.clone()),
|
||||
});
|
||||
}
|
||||
|
||||
@ -466,7 +443,7 @@ impl ReportingStep for BalanceSheet {
|
||||
let product = products.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsIncludingEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(date_args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(date_args.clone()),
|
||||
})?;
|
||||
|
||||
balances.push(&product.downcast_ref::<BalancesAt>().unwrap().balances);
|
||||
@ -557,7 +534,7 @@ impl ReportingStep for BalanceSheet {
|
||||
ReportingProductId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::MultipleDateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(report),
|
||||
);
|
||||
@ -583,22 +560,16 @@ impl CombineOrdinaryTransactions {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(CombineOrdinaryTransactions {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(CombineOrdinaryTransactions { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -614,7 +585,7 @@ impl ReportingStep for CombineOrdinaryTransactions {
|
||||
ReportingStepId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,13 +595,13 @@ impl ReportingStep for CombineOrdinaryTransactions {
|
||||
ReportingProductId {
|
||||
name: "DBTransactions".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
// CombineOrdinaryTransactions depends on PostUnreconciledStatementLines
|
||||
ReportingProductId {
|
||||
name: "PostUnreconciledStatementLines".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -664,22 +635,16 @@ impl CombineOrdinaryTransactionsBalances {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(CombineOrdinaryTransactionsBalances {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(CombineOrdinaryTransactionsBalances { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,7 +660,7 @@ impl ReportingStep for CombineOrdinaryTransactionsBalances {
|
||||
ReportingStepId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesAt],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -705,13 +670,13 @@ impl ReportingStep for CombineOrdinaryTransactionsBalances {
|
||||
ReportingProductId {
|
||||
name: "DBBalances".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
// CombineOrdinaryTransactions depends on PostUnreconciledStatementLines
|
||||
ReportingProductId {
|
||||
name: "PostUnreconciledStatementLines".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -749,7 +714,7 @@ impl ReportingStep for CombineOrdinaryTransactionsBalances {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -773,22 +738,16 @@ impl CurrentYearEarningsToEquity {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(CurrentYearEarningsToEquity {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(CurrentYearEarningsToEquity { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,7 +763,7 @@ impl ReportingStep for CurrentYearEarningsToEquity {
|
||||
ReportingStepId {
|
||||
name: "CurrentYearEarningsToEquity".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -813,7 +772,7 @@ impl ReportingStep for CurrentYearEarningsToEquity {
|
||||
vec![ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(DateStartDateEndArgs {
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(DateStartDateEndArgs {
|
||||
date_start: sofy_from_eofy(get_eofy(&self.args.date, &context.eofy_date)),
|
||||
date_end: self.args.date,
|
||||
}),
|
||||
@ -834,7 +793,7 @@ impl ReportingStep for CurrentYearEarningsToEquity {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(DateStartDateEndArgs {
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(DateStartDateEndArgs {
|
||||
date_start: sofy_from_eofy(get_eofy(&self.args.date, &context.eofy_date)),
|
||||
date_end: self.args.date,
|
||||
}),
|
||||
@ -894,7 +853,7 @@ impl ReportingStep for CurrentYearEarningsToEquity {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(transactions),
|
||||
);
|
||||
@ -918,22 +877,16 @@ impl DBBalances {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(DBBalances {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(DBBalances { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -949,7 +902,7 @@ impl ReportingStep for DBBalances {
|
||||
ReportingStepId {
|
||||
name: "DBBalances".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::BalancesAt],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -971,7 +924,7 @@ impl ReportingStep for DBBalances {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(balances),
|
||||
);
|
||||
@ -993,17 +946,13 @@ impl DBTransactions {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<VoidArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
*args == ReportingStepArgs::VoidArgs
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
_args: Box<dyn ReportingStepArgs>,
|
||||
_args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(DBTransactions {})
|
||||
@ -1022,7 +971,7 @@ impl ReportingStep for DBTransactions {
|
||||
ReportingStepId {
|
||||
name: "DBTransactions".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1044,7 +993,7 @@ impl ReportingStep for DBTransactions {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
Box::new(transactions),
|
||||
);
|
||||
@ -1068,22 +1017,16 @@ impl IncomeStatement {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<MultipleDateStartDateEndArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::MultipleDateStartDateEndArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(IncomeStatement {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(IncomeStatement { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -1099,7 +1042,7 @@ impl ReportingStep for IncomeStatement {
|
||||
ReportingStepId {
|
||||
name: "IncomeStatement".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::DynamicReport],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::MultipleDateStartDateEndArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,7 +1054,7 @@ impl ReportingStep for IncomeStatement {
|
||||
result.push(ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(date_args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(date_args.clone()),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1133,7 +1076,7 @@ impl ReportingStep for IncomeStatement {
|
||||
let product = products.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesBetween,
|
||||
args: Box::new(date_args.clone()),
|
||||
args: ReportingStepArgs::DateStartDateEndArgs(date_args.clone()),
|
||||
})?;
|
||||
|
||||
balances.push(&product.downcast_ref::<BalancesBetween>().unwrap().balances);
|
||||
@ -1225,7 +1168,7 @@ impl ReportingStep for IncomeStatement {
|
||||
ReportingProductId {
|
||||
name: "IncomeStatement".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::MultipleDateStartDateEndArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(report),
|
||||
);
|
||||
@ -1247,17 +1190,13 @@ impl PostUnreconciledStatementLines {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<VoidArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
*args == ReportingStepArgs::VoidArgs
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
_args: Box<dyn ReportingStepArgs>,
|
||||
_args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(PostUnreconciledStatementLines {})
|
||||
@ -1276,7 +1215,7 @@ impl ReportingStep for PostUnreconciledStatementLines {
|
||||
ReportingStepId {
|
||||
name: "PostUnreconciledStatementLines".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1338,7 +1277,7 @@ impl ReportingStep for PostUnreconciledStatementLines {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
Box::new(transactions),
|
||||
);
|
||||
@ -1362,22 +1301,16 @@ impl RetainedEarningsToEquity {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(RetainedEarningsToEquity {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(RetainedEarningsToEquity { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -1393,7 +1326,7 @@ impl ReportingStep for RetainedEarningsToEquity {
|
||||
ReportingStepId {
|
||||
name: "RetainedEarningsToEquity".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::Transactions],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1405,7 +1338,7 @@ impl ReportingStep for RetainedEarningsToEquity {
|
||||
vec![ReportingProductId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: last_eofy_date,
|
||||
}),
|
||||
}]
|
||||
@ -1427,7 +1360,7 @@ impl ReportingStep for RetainedEarningsToEquity {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: last_eofy_date.clone(),
|
||||
}),
|
||||
})?
|
||||
@ -1486,7 +1419,7 @@ impl ReportingStep for RetainedEarningsToEquity {
|
||||
ReportingProductId {
|
||||
name: self.id().name,
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(transactions),
|
||||
);
|
||||
@ -1510,22 +1443,16 @@ impl TrialBalance {
|
||||
);
|
||||
}
|
||||
|
||||
fn takes_args(
|
||||
_name: &str,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
_context: &ReportingContext,
|
||||
) -> bool {
|
||||
args.is::<DateArgs>()
|
||||
fn takes_args(_name: &str, args: &ReportingStepArgs, _context: &ReportingContext) -> bool {
|
||||
matches!(args, ReportingStepArgs::DateArgs(_))
|
||||
}
|
||||
|
||||
fn from_args(
|
||||
_name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
_context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep> {
|
||||
Box::new(TrialBalance {
|
||||
args: *args.downcast().unwrap(),
|
||||
})
|
||||
Box::new(TrialBalance { args: args.into() })
|
||||
}
|
||||
}
|
||||
|
||||
@ -1541,7 +1468,7 @@ impl ReportingStep for TrialBalance {
|
||||
ReportingStepId {
|
||||
name: "TrialBalance".to_string(),
|
||||
product_kinds: vec![ReportingProductKind::DynamicReport],
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1552,7 +1479,7 @@ impl ReportingStep for TrialBalance {
|
||||
result.push(ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
});
|
||||
|
||||
result
|
||||
@ -1572,7 +1499,7 @@ impl ReportingStep for TrialBalance {
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
})?
|
||||
.downcast_ref::<BalancesAt>()
|
||||
.unwrap()
|
||||
@ -1646,7 +1573,7 @@ impl ReportingStep for TrialBalance {
|
||||
ReportingProductId {
|
||||
name: "TrialBalance".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(self.args.clone()),
|
||||
args: ReportingStepArgs::DateArgs(self.args.clone()),
|
||||
},
|
||||
Box::new(report),
|
||||
);
|
||||
|
@ -24,8 +24,6 @@ use async_trait::async_trait;
|
||||
use chrono::NaiveDate;
|
||||
use downcast_rs::Downcast;
|
||||
use dyn_clone::DynClone;
|
||||
use dyn_eq::DynEq;
|
||||
use dyn_hash::DynHash;
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::RwLock;
|
||||
@ -103,16 +101,13 @@ impl ReportingContext {
|
||||
///
|
||||
/// See [ReportingContext::register_lookup_fn].
|
||||
pub type ReportingStepTakesArgsFn =
|
||||
fn(name: &str, args: &Box<dyn ReportingStepArgs>, context: &ReportingContext) -> bool;
|
||||
fn(name: &str, args: &ReportingStepArgs, context: &ReportingContext) -> bool;
|
||||
|
||||
/// Function which builds a concrete [ReportingStep] from the given [ReportingStepArgs]
|
||||
///
|
||||
/// See [ReportingContext::register_lookup_fn].
|
||||
pub type ReportingStepFromArgsFn = fn(
|
||||
name: &str,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
context: &ReportingContext,
|
||||
) -> Box<dyn ReportingStep>;
|
||||
pub type ReportingStepFromArgsFn =
|
||||
fn(name: &str, args: ReportingStepArgs, context: &ReportingContext) -> Box<dyn ReportingStep>;
|
||||
|
||||
// -------------------------------
|
||||
// REPORTING STEP DYNAMIC BUILDERS
|
||||
@ -125,7 +120,7 @@ pub struct ReportingStepDynamicBuilder {
|
||||
pub can_build: fn(
|
||||
name: &str,
|
||||
kind: ReportingProductKind,
|
||||
args: &Box<dyn ReportingStepArgs>,
|
||||
args: &ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
context: &ReportingContext,
|
||||
@ -133,7 +128,7 @@ pub struct ReportingStepDynamicBuilder {
|
||||
pub build: fn(
|
||||
name: String,
|
||||
kind: ReportingProductKind,
|
||||
args: Box<dyn ReportingStepArgs>,
|
||||
args: ReportingStepArgs,
|
||||
steps: &Vec<Box<dyn ReportingStep>>,
|
||||
dependencies: &ReportingGraphDependencies,
|
||||
context: &ReportingContext,
|
||||
@ -148,7 +143,7 @@ pub struct ReportingStepDynamicBuilder {
|
||||
pub struct ReportingProductId {
|
||||
pub name: String,
|
||||
pub kind: ReportingProductKind,
|
||||
pub args: Box<dyn ReportingStepArgs>,
|
||||
pub args: ReportingStepArgs,
|
||||
}
|
||||
|
||||
impl Display for ReportingProductId {
|
||||
@ -283,7 +278,7 @@ impl Display for ReportingProducts {
|
||||
pub struct ReportingStepId {
|
||||
pub name: String,
|
||||
pub product_kinds: Vec<ReportingProductKind>,
|
||||
pub args: Box<dyn ReportingStepArgs>,
|
||||
pub args: ReportingStepArgs,
|
||||
}
|
||||
|
||||
impl Display for ReportingStepId {
|
||||
@ -350,65 +345,87 @@ downcast_rs::impl_downcast!(ReportingStep);
|
||||
// REPORTING STEP ARGUMENTS
|
||||
|
||||
/// Represents arguments to a [ReportingStep]
|
||||
pub trait ReportingStepArgs:
|
||||
Debug + Display + Downcast + DynClone + DynEq + DynHash + Send + Sync
|
||||
{
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum ReportingStepArgs {
|
||||
// This is an enum not a trait, to simply conversion to and from Lua
|
||||
/// [ReportingStepArgs] implementation which takes no arguments
|
||||
VoidArgs,
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes a single date
|
||||
DateArgs(DateArgs),
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes a date range
|
||||
DateStartDateEndArgs(DateStartDateEndArgs),
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes multiple [DateArgs]
|
||||
MultipleDateArgs(MultipleDateArgs),
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes multiple [DateStartDateEndArgs]
|
||||
MultipleDateStartDateEndArgs(MultipleDateStartDateEndArgs),
|
||||
}
|
||||
|
||||
downcast_rs::impl_downcast!(ReportingStepArgs);
|
||||
dyn_clone::clone_trait_object!(ReportingStepArgs);
|
||||
dyn_eq::eq_trait_object!(ReportingStepArgs);
|
||||
dyn_hash::hash_trait_object!(ReportingStepArgs);
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes no arguments
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct VoidArgs {}
|
||||
|
||||
impl ReportingStepArgs for VoidArgs {}
|
||||
|
||||
impl Display for VoidArgs {
|
||||
impl Display for ReportingStepArgs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(""))
|
||||
match self {
|
||||
ReportingStepArgs::VoidArgs => f.write_str("void"),
|
||||
ReportingStepArgs::DateArgs(args) => f.write_fmt(format_args!("{}", args)),
|
||||
ReportingStepArgs::DateStartDateEndArgs(args) => f.write_fmt(format_args!("{}", args)),
|
||||
ReportingStepArgs::MultipleDateArgs(args) => f.write_fmt(format_args!("{}", args)),
|
||||
ReportingStepArgs::MultipleDateStartDateEndArgs(args) => {
|
||||
f.write_fmt(format_args!("{}", args))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes a single date
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct DateArgs {
|
||||
pub date: NaiveDate,
|
||||
}
|
||||
|
||||
impl ReportingStepArgs for DateArgs {}
|
||||
|
||||
impl Display for DateArgs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("{}", self.date))
|
||||
}
|
||||
}
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes a date range
|
||||
impl Into<DateArgs> for ReportingStepArgs {
|
||||
fn into(self) -> DateArgs {
|
||||
if let ReportingStepArgs::DateArgs(args) = self {
|
||||
args
|
||||
} else {
|
||||
panic!("Expected DateArgs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct DateStartDateEndArgs {
|
||||
pub date_start: NaiveDate,
|
||||
pub date_end: NaiveDate,
|
||||
}
|
||||
|
||||
impl ReportingStepArgs for DateStartDateEndArgs {}
|
||||
|
||||
impl Display for DateStartDateEndArgs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("{}, {}", self.date_start, self.date_end))
|
||||
}
|
||||
}
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes multiple [DateArgs]
|
||||
impl Into<DateStartDateEndArgs> for ReportingStepArgs {
|
||||
fn into(self) -> DateStartDateEndArgs {
|
||||
if let ReportingStepArgs::DateStartDateEndArgs(args) = self {
|
||||
args
|
||||
} else {
|
||||
panic!("Expected DateStartDateEndArgs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct MultipleDateArgs {
|
||||
pub dates: Vec<DateArgs>,
|
||||
}
|
||||
|
||||
impl ReportingStepArgs for MultipleDateArgs {}
|
||||
|
||||
impl Display for MultipleDateArgs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
@ -422,14 +439,21 @@ impl Display for MultipleDateArgs {
|
||||
}
|
||||
}
|
||||
|
||||
/// [ReportingStepArgs] implementation which takes multiple [DateStartDateEndArgs]
|
||||
impl Into<MultipleDateArgs> for ReportingStepArgs {
|
||||
fn into(self) -> MultipleDateArgs {
|
||||
if let ReportingStepArgs::MultipleDateArgs(args) = self {
|
||||
args
|
||||
} else {
|
||||
panic!("Expected MultipleDateArgs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct MultipleDateStartDateEndArgs {
|
||||
pub dates: Vec<DateStartDateEndArgs>,
|
||||
}
|
||||
|
||||
impl ReportingStepArgs for MultipleDateStartDateEndArgs {}
|
||||
|
||||
impl Display for MultipleDateStartDateEndArgs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
@ -442,3 +466,13 @@ impl Display for MultipleDateStartDateEndArgs {
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<MultipleDateStartDateEndArgs> for ReportingStepArgs {
|
||||
fn into(self) -> MultipleDateStartDateEndArgs {
|
||||
if let ReportingStepArgs::MultipleDateStartDateEndArgs(args) = self {
|
||||
args
|
||||
} else {
|
||||
panic!("Expected MultipleDateStartDateEndArgs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
use libdrcr::reporting::dynamic_report::DynamicReport;
|
||||
use libdrcr::reporting::types::{ReportingProductId, ReportingProductKind, VoidArgs};
|
||||
use libdrcr::reporting::types::{ReportingProductId, ReportingProductKind, ReportingStepArgs};
|
||||
use tauri::State;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@ -31,7 +31,7 @@ pub(crate) async fn get_tax_summary(state: State<'_, Mutex<AppState>>) -> Result
|
||||
&ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
@ -26,8 +26,8 @@ use libdrcr::reporting::dynamic_report::DynamicReport;
|
||||
use libdrcr::reporting::generate_report;
|
||||
use libdrcr::reporting::types::{
|
||||
BalancesAt, DateArgs, DateStartDateEndArgs, MultipleDateArgs, MultipleDateStartDateEndArgs,
|
||||
ReportingContext, ReportingProduct, ReportingProductId, ReportingProductKind, Transactions,
|
||||
VoidArgs,
|
||||
ReportingContext, ReportingProduct, ReportingProductId, ReportingProductKind,
|
||||
ReportingStepArgs, Transactions,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::State;
|
||||
@ -63,7 +63,7 @@ pub(crate) async fn get_report(
|
||||
ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
},
|
||||
target.clone(),
|
||||
];
|
||||
@ -82,7 +82,7 @@ pub(crate) async fn get_all_transactions_except_earnings_to_equity(
|
||||
&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(9999, 12, 31).unwrap(),
|
||||
}),
|
||||
},
|
||||
@ -105,7 +105,7 @@ pub(crate) async fn get_all_transactions_except_earnings_to_equity_for_account(
|
||||
&ReportingProductId {
|
||||
name: "AllTransactionsExceptEarningsToEquity".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: NaiveDate::from_ymd_opt(9999, 12, 31).unwrap(),
|
||||
}),
|
||||
},
|
||||
@ -141,7 +141,7 @@ pub(crate) async fn get_balance_sheet(
|
||||
&ReportingProductId {
|
||||
name: "BalanceSheet".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateArgs {
|
||||
args: ReportingStepArgs::MultipleDateArgs(MultipleDateArgs {
|
||||
dates: date_args.clone(),
|
||||
}),
|
||||
},
|
||||
@ -170,7 +170,7 @@ pub(crate) async fn get_income_statement(
|
||||
&ReportingProductId {
|
||||
name: "IncomeStatement".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(MultipleDateStartDateEndArgs {
|
||||
args: ReportingStepArgs::MultipleDateStartDateEndArgs(MultipleDateStartDateEndArgs {
|
||||
dates: date_args.clone(),
|
||||
}),
|
||||
},
|
||||
@ -193,7 +193,7 @@ pub(crate) async fn get_trial_balance(
|
||||
&ReportingProductId {
|
||||
name: "TrialBalance".to_string(),
|
||||
kind: ReportingProductKind::DynamicReport,
|
||||
args: Box::new(DateArgs { date }),
|
||||
args: ReportingStepArgs::DateArgs(DateArgs { date }),
|
||||
},
|
||||
)
|
||||
.await
|
||||
@ -233,21 +233,22 @@ pub(crate) async fn get_validated_balance_assertions(
|
||||
|
||||
// Initialise ReportingContext
|
||||
let eofy_date = db_connection.metadata().eofy_date;
|
||||
let mut context = ReportingContext::new(db_connection, eofy_date, "$".to_string());
|
||||
let mut context =
|
||||
ReportingContext::new(db_connection, get_plugins(), eofy_date, "$".to_string());
|
||||
prepare_reporting_context(&mut context);
|
||||
|
||||
// Get report targets
|
||||
let mut targets = vec![ReportingProductId {
|
||||
name: "CalculateIncomeTax".to_string(),
|
||||
kind: ReportingProductKind::Transactions,
|
||||
args: Box::new(VoidArgs {}),
|
||||
args: ReportingStepArgs::VoidArgs,
|
||||
}];
|
||||
for dt in dates {
|
||||
// Request ordinary transaction balances at each balance assertion date
|
||||
targets.push(ReportingProductId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs { date: dt.date() }),
|
||||
args: ReportingStepArgs::DateArgs(DateArgs { date: dt.date() }),
|
||||
});
|
||||
}
|
||||
|
||||
@ -261,7 +262,7 @@ pub(crate) async fn get_validated_balance_assertions(
|
||||
.get_or_err(&ReportingProductId {
|
||||
name: "CombineOrdinaryTransactions".to_string(),
|
||||
kind: ReportingProductKind::BalancesAt,
|
||||
args: Box::new(DateArgs {
|
||||
args: ReportingStepArgs::DateArgs(DateArgs {
|
||||
date: balance_assertion.dt.date(),
|
||||
}),
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user