diff --git a/src/reporting/steps.rs b/src/reporting/steps.rs index e98c162..85ab6a7 100644 --- a/src/reporting/steps.rs +++ b/src/reporting/steps.rs @@ -18,6 +18,8 @@ use std::fmt::Display; +use chrono::Datelike; + use crate::util::sofy_from_eofy; use super::{ @@ -82,6 +84,13 @@ pub fn register_lookup_fns(context: &mut ReportingContext) { PostUnreconciledStatementLines::takes_args, PostUnreconciledStatementLines::from_args, ); + + context.register_lookup_fn( + "RetainedEarningsToEquity", + &[ReportingProductKind::Transactions], + RetainedEarningsToEquity::takes_args, + RetainedEarningsToEquity::from_args, + ); } #[derive(Debug)] @@ -349,3 +358,50 @@ impl ReportingStep for PostUnreconciledStatementLines { } } } + +#[derive(Debug)] +pub struct RetainedEarningsToEquity { + pub args: DateArgs, +} + +impl RetainedEarningsToEquity { + fn takes_args(args: &Box) -> bool { + args.is::() + } + + fn from_args(args: Box) -> Box { + Box::new(RetainedEarningsToEquity { + args: *args.downcast().unwrap(), + }) + } +} + +impl Display for RetainedEarningsToEquity { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("{}", self.id())) + } +} + +impl ReportingStep for RetainedEarningsToEquity { + fn id(&self) -> ReportingStepId { + ReportingStepId { + name: "RetainedEarningsToEquity", + product_kinds: &[ReportingProductKind::Transactions], + args: Box::new(self.args.clone()), + } + } + + fn requires(&self, context: &ReportingContext) -> Vec { + // RetainedEarningsToEquity depends on CombineOrdinaryTransactions for last financial year + vec![ReportingProductId { + name: "CombineOrdinaryTransactions", + kind: ReportingProductKind::BalancesAt, + args: Box::new(DateArgs { + date: context + .eofy_date + .with_year(context.eofy_date.year() - 1) + .unwrap(), + }), + }] + } +}