Refactor representation of ReportingStep args
This commit is contained in:
parent
f15d190112
commit
a7e9c74dd1
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -70,6 +70,18 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea8a8b81cacc08888170eef4d13b775126db426d0b348bee9d18c2c1eaf123cf"
|
checksum = "ea8a8b81cacc08888170eef4d13b775126db426d0b348bee9d18c2c1eaf123cf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dyn-clone"
|
||||||
|
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]]
|
[[package]]
|
||||||
name = "iana-time-zone"
|
name = "iana-time-zone"
|
||||||
version = "0.1.63"
|
version = "0.1.63"
|
||||||
@ -116,6 +128,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"downcast-rs",
|
"downcast-rs",
|
||||||
|
"dyn-clone",
|
||||||
|
"dyn-eq",
|
||||||
"solvent",
|
"solvent",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6,5 +6,6 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.41"
|
chrono = "0.4.41"
|
||||||
downcast-rs = "2.0.1"
|
downcast-rs = "2.0.1"
|
||||||
#dyn-clone = "1.0.19"
|
dyn-clone = "1.0.19"
|
||||||
|
dyn-eq = "0.1.3"
|
||||||
solvent = "0.8.3"
|
solvent = "0.8.3"
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -21,7 +21,7 @@ use libdrcr::reporting::{
|
|||||||
builders::register_dynamic_builders,
|
builders::register_dynamic_builders,
|
||||||
calculator::solve_for,
|
calculator::solve_for,
|
||||||
steps::{register_lookup_fns, AllTransactionsExceptRetainedEarnings, CalculateIncomeTax},
|
steps::{register_lookup_fns, AllTransactionsExceptRetainedEarnings, CalculateIncomeTax},
|
||||||
ReportingContext, ReportingStep,
|
DateEofyArgs, DateStartDateEndArgs, ReportingContext, ReportingStep,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -31,13 +31,24 @@ fn main() {
|
|||||||
|
|
||||||
let targets: Vec<Box<dyn ReportingStep>> = vec![
|
let targets: Vec<Box<dyn ReportingStep>> = vec![
|
||||||
Box::new(CalculateIncomeTax {
|
Box::new(CalculateIncomeTax {
|
||||||
|
args: DateEofyArgs {
|
||||||
date_eofy: NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
date_eofy: NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
Box::new(AllTransactionsExceptRetainedEarnings {
|
Box::new(AllTransactionsExceptRetainedEarnings {
|
||||||
|
args: DateStartDateEndArgs {
|
||||||
date_start: NaiveDate::from_ymd_opt(2024, 7, 1).unwrap(),
|
date_start: NaiveDate::from_ymd_opt(2024, 7, 1).unwrap(),
|
||||||
date_end: NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
date_end: NaiveDate::from_ymd_opt(2025, 6, 30).unwrap(),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
println!("{:?}", solve_for(targets, context));
|
match solve_for(targets, context) {
|
||||||
|
Ok(steps) => {
|
||||||
|
for step in steps {
|
||||||
|
println!("- {}", step.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => panic!("Error: {:?}", err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,10 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
calculator::{has_step_or_can_build, HasStepOrCanBuild, ReportingGraphDependencies},
|
calculator::{has_step_or_can_build, HasStepOrCanBuild, ReportingGraphDependencies},
|
||||||
ReportingContext, ReportingProductId, ReportingProductKind, ReportingStep,
|
DateArgs, DateStartDateEndArgs, ReportingContext, ReportingProductId, ReportingProductKind,
|
||||||
ReportingStepDynamicBuilder, ReportingStepId,
|
ReportingStep, ReportingStepArgs, ReportingStepDynamicBuilder, ReportingStepId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn register_dynamic_builders(context: &mut ReportingContext) {
|
pub fn register_dynamic_builders(context: &mut ReportingContext) {
|
||||||
@ -41,8 +39,7 @@ pub fn register_dynamic_builders(context: &mut ReportingContext) {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BalancesAtToBalancesBetween {
|
pub struct BalancesAtToBalancesBetween {
|
||||||
step_name: &'static str,
|
step_name: &'static str,
|
||||||
date_start: NaiveDate,
|
args: DateStartDateEndArgs,
|
||||||
date_end: NaiveDate,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BalancesAtToBalancesBetween {
|
impl BalancesAtToBalancesBetween {
|
||||||
@ -51,7 +48,7 @@ impl BalancesAtToBalancesBetween {
|
|||||||
fn can_build(
|
fn can_build(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
kind: ReportingProductKind,
|
kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: &Box<dyn ReportingStepArgs>,
|
||||||
steps: &Vec<Box<dyn ReportingStep>>,
|
steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &ReportingGraphDependencies,
|
dependencies: &ReportingGraphDependencies,
|
||||||
context: &ReportingContext,
|
context: &ReportingContext,
|
||||||
@ -62,7 +59,7 @@ impl BalancesAtToBalancesBetween {
|
|||||||
&ReportingProductId {
|
&ReportingProductId {
|
||||||
name,
|
name,
|
||||||
kind: ReportingProductKind::BalancesAt,
|
kind: ReportingProductKind::BalancesAt,
|
||||||
args: vec![args[1].clone()],
|
args: args.clone(),
|
||||||
},
|
},
|
||||||
steps,
|
steps,
|
||||||
dependencies,
|
dependencies,
|
||||||
@ -82,15 +79,14 @@ impl BalancesAtToBalancesBetween {
|
|||||||
fn build(
|
fn build(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_kind: ReportingProductKind,
|
_kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: Box<dyn ReportingStepArgs>,
|
||||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
_dependencies: &ReportingGraphDependencies,
|
_dependencies: &ReportingGraphDependencies,
|
||||||
_context: &ReportingContext,
|
_context: &ReportingContext,
|
||||||
) -> Box<dyn ReportingStep> {
|
) -> Box<dyn ReportingStep> {
|
||||||
Box::new(BalancesAtToBalancesBetween {
|
Box::new(BalancesAtToBalancesBetween {
|
||||||
step_name: name,
|
step_name: name,
|
||||||
date_start: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
date_end: NaiveDate::parse_from_str(&args[1], "%Y-%m-%d").unwrap(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,10 +96,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: self.step_name,
|
name: self.step_name,
|
||||||
product_kinds: &[ReportingProductKind::BalancesBetween],
|
product_kinds: &[ReportingProductKind::BalancesBetween],
|
||||||
args: vec![
|
args: Box::new(self.args.clone()),
|
||||||
self.date_start.format("%Y-%m-%d").to_string(),
|
|
||||||
self.date_end.format("%Y-%m-%d").to_string(),
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +105,15 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
|||||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &mut ReportingGraphDependencies,
|
dependencies: &mut ReportingGraphDependencies,
|
||||||
) {
|
) {
|
||||||
|
// BalancesAtToBalancesBetween depends on BalancesAt at both time points
|
||||||
dependencies.add_dependency(
|
dependencies.add_dependency(
|
||||||
self.id(),
|
self.id(),
|
||||||
ReportingProductId {
|
ReportingProductId {
|
||||||
name: self.step_name,
|
name: self.step_name,
|
||||||
kind: ReportingProductKind::BalancesAt,
|
kind: ReportingProductKind::BalancesAt,
|
||||||
args: vec![self.date_start.format("%Y-%m-%d").to_string()],
|
args: Box::new(DateArgs {
|
||||||
|
date: self.args.date_start.clone(),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
dependencies.add_dependency(
|
dependencies.add_dependency(
|
||||||
@ -125,7 +121,9 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
|||||||
ReportingProductId {
|
ReportingProductId {
|
||||||
name: self.step_name,
|
name: self.step_name,
|
||||||
kind: ReportingProductKind::BalancesAt,
|
kind: ReportingProductKind::BalancesAt,
|
||||||
args: vec![self.date_end.format("%Y-%m-%d").to_string()],
|
args: Box::new(DateArgs {
|
||||||
|
date: self.args.date_end.clone(),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -134,8 +132,7 @@ impl ReportingStep for BalancesAtToBalancesBetween {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UpdateBalancesBetween {
|
pub struct UpdateBalancesBetween {
|
||||||
step_name: &'static str,
|
step_name: &'static str,
|
||||||
date_start: NaiveDate,
|
args: DateStartDateEndArgs,
|
||||||
date_end: NaiveDate,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateBalancesBetween {
|
impl UpdateBalancesBetween {
|
||||||
@ -144,7 +141,7 @@ impl UpdateBalancesBetween {
|
|||||||
fn can_build(
|
fn can_build(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
kind: ReportingProductKind,
|
kind: ReportingProductKind,
|
||||||
_args: Vec<String>,
|
_args: &Box<dyn ReportingStepArgs>,
|
||||||
steps: &Vec<Box<dyn ReportingStep>>,
|
steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &ReportingGraphDependencies,
|
dependencies: &ReportingGraphDependencies,
|
||||||
_context: &ReportingContext,
|
_context: &ReportingContext,
|
||||||
@ -191,15 +188,14 @@ impl UpdateBalancesBetween {
|
|||||||
fn build(
|
fn build(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
_kind: ReportingProductKind,
|
_kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: Box<dyn ReportingStepArgs>,
|
||||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
_dependencies: &ReportingGraphDependencies,
|
_dependencies: &ReportingGraphDependencies,
|
||||||
_context: &ReportingContext,
|
_context: &ReportingContext,
|
||||||
) -> Box<dyn ReportingStep> {
|
) -> Box<dyn ReportingStep> {
|
||||||
Box::new(UpdateBalancesBetween {
|
Box::new(UpdateBalancesBetween {
|
||||||
step_name: name,
|
step_name: name,
|
||||||
date_start: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
date_end: NaiveDate::parse_from_str(&args[1], "%Y-%m-%d").unwrap(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,10 +205,7 @@ impl ReportingStep for UpdateBalancesBetween {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: self.step_name,
|
name: self.step_name,
|
||||||
product_kinds: &[ReportingProductKind::BalancesBetween],
|
product_kinds: &[ReportingProductKind::BalancesBetween],
|
||||||
args: vec![
|
args: Box::new(self.args.clone()),
|
||||||
self.date_start.format("%Y-%m-%d").to_string(),
|
|
||||||
self.date_end.format("%Y-%m-%d").to_string(),
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ pub fn has_step_or_can_build<'a, 'b>(
|
|||||||
if (builder.can_build)(
|
if (builder.can_build)(
|
||||||
product.name,
|
product.name,
|
||||||
product.kind,
|
product.kind,
|
||||||
product.args.clone(),
|
&product.args,
|
||||||
steps,
|
steps,
|
||||||
dependencies,
|
dependencies,
|
||||||
context,
|
context,
|
||||||
@ -225,7 +225,7 @@ pub fn solve_for(
|
|||||||
if (builder.can_build)(
|
if (builder.can_build)(
|
||||||
dependency.dependency.name,
|
dependency.dependency.name,
|
||||||
dependency.dependency.kind,
|
dependency.dependency.kind,
|
||||||
dependency.dependency.args.clone(),
|
&dependency.dependency.args,
|
||||||
&steps,
|
&steps,
|
||||||
&dependencies,
|
&dependencies,
|
||||||
&context,
|
&context,
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::{collections::HashMap, fmt::Display};
|
use std::{collections::HashMap, fmt::Display};
|
||||||
|
|
||||||
use calculator::{ReportingGraphDependencies};
|
use calculator::ReportingGraphDependencies;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use downcast_rs::Downcast;
|
use downcast_rs::Downcast;
|
||||||
|
use dyn_clone::DynClone;
|
||||||
|
use dyn_eq::DynEq;
|
||||||
|
|
||||||
pub mod builders;
|
pub mod builders;
|
||||||
pub mod calculator;
|
pub mod calculator;
|
||||||
@ -66,12 +68,12 @@ impl ReportingContext {
|
|||||||
pub struct ReportingProductId {
|
pub struct ReportingProductId {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
kind: ReportingProductKind,
|
kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: Box<dyn ReportingStepArgs>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ReportingProductId {
|
impl Display for ReportingProductId {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_fmt(format_args!("{}.{:?}{:?}", self.name, self.kind, self.args))
|
f.write_fmt(format_args!("{}.{:?}({})", self.name, self.kind, self.args))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,13 +104,13 @@ pub enum ReportingProductKind {
|
|||||||
pub struct ReportingStepId {
|
pub struct ReportingStepId {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub product_kinds: &'static [ReportingProductKind],
|
pub product_kinds: &'static [ReportingProductKind],
|
||||||
pub args: Vec<String>,
|
pub args: Box<dyn ReportingStepArgs>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ReportingStepId {
|
impl Display for ReportingStepId {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_fmt(format_args!(
|
f.write_fmt(format_args!(
|
||||||
"{}{:?}{:?}",
|
"{}{:?}({})",
|
||||||
self.name, self.product_kinds, self.args
|
self.name, self.product_kinds, self.args
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -138,14 +140,60 @@ pub trait ReportingStep: Debug + Downcast {
|
|||||||
|
|
||||||
downcast_rs::impl_downcast!(ReportingStep);
|
downcast_rs::impl_downcast!(ReportingStep);
|
||||||
|
|
||||||
pub type ReportingStepLookupFn = fn(args: Vec<String>) -> Box<dyn ReportingStep>;
|
pub trait ReportingStepArgs: Debug + Display + Downcast + DynClone + DynEq {}
|
||||||
|
|
||||||
|
downcast_rs::impl_downcast!(ReportingStepArgs);
|
||||||
|
dyn_clone::clone_trait_object!(ReportingStepArgs);
|
||||||
|
dyn_eq::eq_trait_object!(ReportingStepArgs);
|
||||||
|
|
||||||
|
pub type ReportingStepLookupFn = fn(args: Box<dyn ReportingStepArgs>) -> Box<dyn ReportingStep>;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct DateEofyArgs {
|
||||||
|
pub date_eofy: NaiveDate,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReportingStepArgs for DateEofyArgs {}
|
||||||
|
|
||||||
|
impl Display for DateEofyArgs {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_fmt(format_args!("{}", self.date_eofy))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ReportingStepDynamicBuilder {
|
pub struct ReportingStepDynamicBuilder {
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
can_build: fn(
|
can_build: fn(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
kind: ReportingProductKind,
|
kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: &Box<dyn ReportingStepArgs>,
|
||||||
steps: &Vec<Box<dyn ReportingStep>>,
|
steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &ReportingGraphDependencies,
|
dependencies: &ReportingGraphDependencies,
|
||||||
context: &ReportingContext,
|
context: &ReportingContext,
|
||||||
@ -153,7 +201,7 @@ pub struct ReportingStepDynamicBuilder {
|
|||||||
build: fn(
|
build: fn(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
kind: ReportingProductKind,
|
kind: ReportingProductKind,
|
||||||
args: Vec<String>,
|
args: Box<dyn ReportingStepArgs>,
|
||||||
steps: &Vec<Box<dyn ReportingStep>>,
|
steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &ReportingGraphDependencies,
|
dependencies: &ReportingGraphDependencies,
|
||||||
context: &ReportingContext,
|
context: &ReportingContext,
|
||||||
|
@ -16,13 +16,12 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
|
|
||||||
use crate::util::sofy_from_eofy;
|
use crate::util::sofy_from_eofy;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
calculator::ReportingGraphDependencies, ReportingContext, ReportingProductId,
|
calculator::ReportingGraphDependencies, DateArgs, DateEofyArgs, DateStartDateEndArgs,
|
||||||
ReportingProductKind, ReportingStep, ReportingStepId,
|
ReportingContext, ReportingProductId, ReportingProductKind, ReportingStep, ReportingStepArgs,
|
||||||
|
ReportingStepId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn register_lookup_fns(context: &mut ReportingContext) {
|
pub fn register_lookup_fns(context: &mut ReportingContext) {
|
||||||
@ -53,15 +52,13 @@ pub fn register_lookup_fns(context: &mut ReportingContext) {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AllTransactionsExceptRetainedEarnings {
|
pub struct AllTransactionsExceptRetainedEarnings {
|
||||||
pub date_start: NaiveDate,
|
pub args: DateStartDateEndArgs,
|
||||||
pub date_end: NaiveDate,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllTransactionsExceptRetainedEarnings {
|
impl AllTransactionsExceptRetainedEarnings {
|
||||||
fn from_args(args: Vec<String>) -> Box<dyn ReportingStep> {
|
fn from_args(args: Box<dyn ReportingStepArgs>) -> Box<dyn ReportingStep> {
|
||||||
Box::new(AllTransactionsExceptRetainedEarnings {
|
Box::new(AllTransactionsExceptRetainedEarnings {
|
||||||
date_start: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
date_end: NaiveDate::parse_from_str(&args[1], "%Y-%m-%d").unwrap(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,23 +68,20 @@ impl ReportingStep for AllTransactionsExceptRetainedEarnings {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: "AllTransactionsExceptRetainedEarnings",
|
name: "AllTransactionsExceptRetainedEarnings",
|
||||||
product_kinds: &[ReportingProductKind::BalancesBetween],
|
product_kinds: &[ReportingProductKind::BalancesBetween],
|
||||||
args: vec![
|
args: Box::new(self.args.clone()),
|
||||||
self.date_start.format("%Y-%m-%d").to_string(),
|
|
||||||
self.date_end.format("%Y-%m-%d").to_string(),
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CalculateIncomeTax {
|
pub struct CalculateIncomeTax {
|
||||||
pub date_eofy: NaiveDate,
|
pub args: DateEofyArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CalculateIncomeTax {
|
impl CalculateIncomeTax {
|
||||||
fn from_args(args: Vec<String>) -> Box<dyn ReportingStep> {
|
fn from_args(args: Box<dyn ReportingStepArgs>) -> Box<dyn ReportingStep> {
|
||||||
Box::new(CalculateIncomeTax {
|
Box::new(CalculateIncomeTax {
|
||||||
date_eofy: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +91,7 @@ impl ReportingStep for CalculateIncomeTax {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: "CalculateIncomeTax",
|
name: "CalculateIncomeTax",
|
||||||
product_kinds: &[ReportingProductKind::Transactions],
|
product_kinds: &[ReportingProductKind::Transactions],
|
||||||
args: vec![self.date_eofy.format("%Y-%m-%d").to_string()],
|
args: Box::new(self.args.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +100,16 @@ impl ReportingStep for CalculateIncomeTax {
|
|||||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &mut ReportingGraphDependencies,
|
dependencies: &mut ReportingGraphDependencies,
|
||||||
) {
|
) {
|
||||||
|
// CalculateIncomeTax depends on CombineOrdinaryTransactions
|
||||||
dependencies.add_dependency(
|
dependencies.add_dependency(
|
||||||
self.id(),
|
self.id(),
|
||||||
ReportingProductId {
|
ReportingProductId {
|
||||||
name: "CombineOrdinaryTransactions",
|
name: "CombineOrdinaryTransactions",
|
||||||
kind: ReportingProductKind::BalancesBetween,
|
kind: ReportingProductKind::BalancesBetween,
|
||||||
args: vec![
|
args: Box::new(DateStartDateEndArgs {
|
||||||
sofy_from_eofy(self.date_eofy)
|
date_start: sofy_from_eofy(self.args.date_eofy),
|
||||||
.format("%Y-%m-%d")
|
date_end: self.args.date_eofy.clone(),
|
||||||
.to_string(),
|
}),
|
||||||
self.date_eofy.format("%Y-%m-%d").to_string(),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -128,7 +121,10 @@ impl ReportingStep for CalculateIncomeTax {
|
|||||||
) {
|
) {
|
||||||
for other in steps {
|
for other in steps {
|
||||||
if let Some(other) = other.downcast_ref::<AllTransactionsExceptRetainedEarnings>() {
|
if let Some(other) = other.downcast_ref::<AllTransactionsExceptRetainedEarnings>() {
|
||||||
if other.date_start <= self.date_eofy && other.date_end >= self.date_eofy {
|
if other.args.date_start <= self.args.date_eofy
|
||||||
|
&& other.args.date_end >= self.args.date_eofy
|
||||||
|
{
|
||||||
|
// AllTransactionsExceptRetainedEarnings (in applicable periods) depends on CalculateIncomeTax
|
||||||
dependencies.add_target_dependency(other.id(), self.id());
|
dependencies.add_target_dependency(other.id(), self.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,13 +134,13 @@ impl ReportingStep for CalculateIncomeTax {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CombineOrdinaryTransactions {
|
pub struct CombineOrdinaryTransactions {
|
||||||
pub date: NaiveDate,
|
pub args: DateArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CombineOrdinaryTransactions {
|
impl CombineOrdinaryTransactions {
|
||||||
fn from_args(args: Vec<String>) -> Box<dyn ReportingStep> {
|
fn from_args(args: Box<dyn ReportingStepArgs>) -> Box<dyn ReportingStep> {
|
||||||
Box::new(CombineOrdinaryTransactions {
|
Box::new(CombineOrdinaryTransactions {
|
||||||
date: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +150,7 @@ impl ReportingStep for CombineOrdinaryTransactions {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: "CombineOrdinaryTransactions",
|
name: "CombineOrdinaryTransactions",
|
||||||
product_kinds: &[ReportingProductKind::BalancesAt],
|
product_kinds: &[ReportingProductKind::BalancesAt],
|
||||||
args: vec![self.date.format("%Y-%m-%d").to_string()],
|
args: Box::new(self.args.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,12 +159,13 @@ impl ReportingStep for CombineOrdinaryTransactions {
|
|||||||
_steps: &Vec<Box<dyn ReportingStep>>,
|
_steps: &Vec<Box<dyn ReportingStep>>,
|
||||||
dependencies: &mut ReportingGraphDependencies,
|
dependencies: &mut ReportingGraphDependencies,
|
||||||
) {
|
) {
|
||||||
|
// CombineOrdinaryTransactions depends on DBBalances
|
||||||
dependencies.add_dependency(
|
dependencies.add_dependency(
|
||||||
self.id(),
|
self.id(),
|
||||||
ReportingProductId {
|
ReportingProductId {
|
||||||
name: "DBBalances",
|
name: "DBBalances",
|
||||||
kind: ReportingProductKind::BalancesAt,
|
kind: ReportingProductKind::BalancesAt,
|
||||||
args: vec![self.date.format("%Y-%m-%d").to_string()],
|
args: Box::new(self.args.clone()),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -176,13 +173,13 @@ impl ReportingStep for CombineOrdinaryTransactions {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DBBalances {
|
pub struct DBBalances {
|
||||||
pub date: NaiveDate,
|
pub args: DateArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DBBalances {
|
impl DBBalances {
|
||||||
fn from_args(args: Vec<String>) -> Box<dyn ReportingStep> {
|
fn from_args(args: Box<dyn ReportingStepArgs>) -> Box<dyn ReportingStep> {
|
||||||
Box::new(DBBalances {
|
Box::new(DBBalances {
|
||||||
date: NaiveDate::parse_from_str(&args[0], "%Y-%m-%d").unwrap(),
|
args: *args.downcast().unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +189,7 @@ impl ReportingStep for DBBalances {
|
|||||||
ReportingStepId {
|
ReportingStepId {
|
||||||
name: "DBBalances",
|
name: "DBBalances",
|
||||||
product_kinds: &[ReportingProductKind::BalancesAt],
|
product_kinds: &[ReportingProductKind::BalancesAt],
|
||||||
args: vec![self.date.format("%Y-%m-%d").to_string()],
|
args: Box::new(self.args.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user