diff --git a/src/reporting/builders.rs b/src/reporting/builders.rs index 15bb630..0eaa902 100644 --- a/src/reporting/builders.rs +++ b/src/reporting/builders.rs @@ -24,31 +24,14 @@ use super::types::{ ReportingStep, ReportingStepArgs, ReportingStepDynamicBuilder, ReportingStepId, }; +/// Call [ReportingContext::register_dynamic_builder] for all dynamic builders provided by this module pub fn register_dynamic_builders(context: &mut ReportingContext) { - context.register_dynamic_builder(ReportingStepDynamicBuilder { - name: "GenerateBalances", - can_build: GenerateBalances::can_build, - build: GenerateBalances::build, - }); + GenerateBalances::register_dynamic_builder(context); + UpdateBalancesBetween::register_dynamic_builder(context); + UpdateBalancesAt::register_dynamic_builder(context); - context.register_dynamic_builder(ReportingStepDynamicBuilder { - name: "UpdateBalancesBetween", - can_build: UpdateBalancesBetween::can_build, - build: UpdateBalancesBetween::build, - }); - - context.register_dynamic_builder(ReportingStepDynamicBuilder { - name: "UpdateBalancesAt", - can_build: UpdateBalancesAt::can_build, - build: UpdateBalancesAt::build, - }); - - // This is the least efficient way of generating BalancesBetween - context.register_dynamic_builder(ReportingStepDynamicBuilder { - name: "BalancesAtToBalancesBetween", - can_build: BalancesAtToBalancesBetween::can_build, - build: BalancesAtToBalancesBetween::build, - }); + // This is the least efficient way of generating BalancesBetween so put at the end + BalancesAtToBalancesBetween::register_dynamic_builder(context); } #[derive(Debug)] @@ -60,6 +43,14 @@ pub struct BalancesAtToBalancesBetween { impl BalancesAtToBalancesBetween { // Implements BalancesAt, BalancesAt -> BalancesBetween + fn register_dynamic_builder(context: &mut ReportingContext) { + context.register_dynamic_builder(ReportingStepDynamicBuilder { + name: "BalancesAtToBalancesBetween", + can_build: Self::can_build, + build: Self::build, + }); + } + fn can_build( name: &'static str, kind: ReportingProductKind, @@ -162,6 +153,14 @@ pub struct GenerateBalances { impl GenerateBalances { // Implements (() -> Transactions) -> BalancesAt + fn register_dynamic_builder(context: &mut ReportingContext) { + context.register_dynamic_builder(ReportingStepDynamicBuilder { + name: "GenerateBalances", + can_build: Self::can_build, + build: Self::build, + }); + } + fn can_build( name: &'static str, kind: ReportingProductKind, @@ -250,6 +249,14 @@ pub struct UpdateBalancesAt { impl UpdateBalancesAt { // Implements (BalancesAt -> Transactions) -> BalancesAt + fn register_dynamic_builder(context: &mut ReportingContext) { + context.register_dynamic_builder(ReportingStepDynamicBuilder { + name: "UpdateBalancesAt", + can_build: Self::can_build, + build: Self::build, + }); + } + fn can_build( name: &'static str, kind: ReportingProductKind, @@ -378,6 +385,14 @@ pub struct UpdateBalancesBetween { impl UpdateBalancesBetween { // Implements (BalancesBetween -> Transactions) -> BalancesBetween + fn register_dynamic_builder(context: &mut ReportingContext) { + context.register_dynamic_builder(ReportingStepDynamicBuilder { + name: "UpdateBalancesBetween", + can_build: Self::can_build, + build: Self::build, + }); + } + fn can_build( name: &'static str, kind: ReportingProductKind, diff --git a/src/reporting/steps.rs b/src/reporting/steps.rs index 9984f69..e021277 100644 --- a/src/reporting/steps.rs +++ b/src/reporting/steps.rs @@ -33,69 +33,15 @@ use super::types::{ ReportingStepArgs, ReportingStepId, VoidArgs, }; +/// Call [ReportingContext::register_lookup_fn] for all steps provided by this module pub fn register_lookup_fns(context: &mut ReportingContext) { - context.register_lookup_fn( - "AllTransactionsExceptRetainedEarnings", - &[ReportingProductKind::BalancesAt], - AllTransactionsExceptRetainedEarnings::takes_args, - |a| { - AllTransactionsExceptRetainedEarnings::from_args(&[ReportingProductKind::BalancesAt], a) - }, - ); - - context.register_lookup_fn( - "AllTransactionsExceptRetainedEarnings", - &[ReportingProductKind::BalancesBetween], - AllTransactionsExceptRetainedEarnings::takes_args, - |a| { - AllTransactionsExceptRetainedEarnings::from_args( - &[ReportingProductKind::BalancesBetween], - a, - ) - }, - ); - - context.register_lookup_fn( - "AllTransactionsIncludingRetainedEarnings", - &[ReportingProductKind::BalancesAt], - AllTransactionsIncludingRetainedEarnings::takes_args, - AllTransactionsIncludingRetainedEarnings::from_args, - ); - - context.register_lookup_fn( - "CalculateIncomeTax", - &[ReportingProductKind::Transactions], - CalculateIncomeTax::takes_args, - CalculateIncomeTax::from_args, - ); - - context.register_lookup_fn( - "CombineOrdinaryTransactions", - &[ReportingProductKind::BalancesAt], - CombineOrdinaryTransactions::takes_args, - CombineOrdinaryTransactions::from_args, - ); - - context.register_lookup_fn( - "DBBalances", - &[ReportingProductKind::BalancesAt], - DBBalances::takes_args, - DBBalances::from_args, - ); - - context.register_lookup_fn( - "PostUnreconciledStatementLines", - &[ReportingProductKind::Transactions], - PostUnreconciledStatementLines::takes_args, - PostUnreconciledStatementLines::from_args, - ); - - context.register_lookup_fn( - "RetainedEarningsToEquity", - &[ReportingProductKind::Transactions], - RetainedEarningsToEquity::takes_args, - RetainedEarningsToEquity::from_args, - ); + AllTransactionsExceptRetainedEarnings::register_lookup_fn(context); + AllTransactionsIncludingRetainedEarnings::register_lookup_fn(context); + CalculateIncomeTax::register_lookup_fn(context); + CombineOrdinaryTransactions::register_lookup_fn(context); + DBBalances::register_lookup_fn(context); + PostUnreconciledStatementLines::register_lookup_fn(context); + RetainedEarningsToEquity::register_lookup_fn(context); } #[derive(Debug)] @@ -105,6 +51,22 @@ pub struct AllTransactionsExceptRetainedEarnings { } impl AllTransactionsExceptRetainedEarnings { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "AllTransactionsExceptRetainedEarnings", + &[ReportingProductKind::BalancesAt], + Self::takes_args, + |a| Self::from_args(&[ReportingProductKind::BalancesAt], a), + ); + + context.register_lookup_fn( + "AllTransactionsExceptRetainedEarnings", + &[ReportingProductKind::BalancesBetween], + Self::takes_args, + |a| Self::from_args(&[ReportingProductKind::BalancesBetween], a), + ); + } + fn takes_args(_args: &Box) -> bool { true } @@ -142,6 +104,15 @@ pub struct AllTransactionsIncludingRetainedEarnings { } impl AllTransactionsIncludingRetainedEarnings { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "AllTransactionsIncludingRetainedEarnings", + &[ReportingProductKind::BalancesAt], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(args: &Box) -> bool { args.is::() } @@ -190,6 +161,15 @@ impl ReportingStep for AllTransactionsIncludingRetainedEarnings { pub struct CalculateIncomeTax {} impl CalculateIncomeTax { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "CalculateIncomeTax", + &[ReportingProductKind::Transactions], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(_args: &Box) -> bool { true } @@ -254,6 +234,15 @@ pub struct CombineOrdinaryTransactions { } impl CombineOrdinaryTransactions { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "CombineOrdinaryTransactions", + &[ReportingProductKind::BalancesAt], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(args: &Box) -> bool { args.is::() } @@ -304,6 +293,15 @@ pub struct DBBalances { } impl DBBalances { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "DBBalances", + &[ReportingProductKind::BalancesAt], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(args: &Box) -> bool { args.is::() } @@ -360,6 +358,15 @@ pub struct PostUnreconciledStatementLines { } impl PostUnreconciledStatementLines { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "PostUnreconciledStatementLines", + &[ReportingProductKind::Transactions], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(args: &Box) -> bool { args.is::() } @@ -393,6 +400,15 @@ pub struct RetainedEarningsToEquity { } impl RetainedEarningsToEquity { + fn register_lookup_fn(context: &mut ReportingContext) { + context.register_lookup_fn( + "RetainedEarningsToEquity", + &[ReportingProductKind::Transactions], + Self::takes_args, + Self::from_args, + ); + } + fn takes_args(args: &Box) -> bool { args.is::() }