From 71f1adad647d5ec4f2e69970543758d7f49f1340 Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 14:56:13 +0100 Subject: first try for implementing --depth for register --- src/filters.cc | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index fadd5b5a..02f0e79b 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -449,13 +449,16 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - handle_value(/* value= */ subtotal, - /* account= */ totals_account, - /* xact= */ &xact, - /* temps= */ temps, - /* handler= */ handler, - /* date= */ latest_date, - /* act_date_p= */ false); + foreach (post_t * post, component_posts) { + handle_value(/* value= */ subtotal, + /* account= */ find_totals_account(post->account), + /* xact= */ &xact, + /* temps= */ temps, + /* handler= */ handler, + /* date= */ latest_date, + /* act_date_p= */ false); + } + } component_posts.clear(); @@ -466,6 +469,21 @@ void collapse_posts::report_subtotal() count = 0; } +account_t* collapse_posts::find_totals_account(account_t* account) +{ + unsigned short depth=2; + if(account->depth==depth) + { + string name=account->fullname(); + account_t*& acc = totals_accounts[name]; + if(acc==NULL) + acc= &temps.create_account(name); + return acc; + } + //recurse + return find_totals_account(account->parent); +} + void collapse_posts::operator()(post_t& post) { // If we've reached a new xact, report on the subtotal -- cgit v1.2.3 From a2d29dda5f514b84b503037195ca8a79a7969f7d Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 15:58:52 +0100 Subject: first implementation of --depth for register --- src/filters.cc | 27 ++++++++++++--------------- src/filters.h | 31 +++++++++++++++++-------------- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index 02f0e79b..f7321438 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -448,10 +448,10 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "Pseudo-xact date = " << *xact._date); DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - - foreach (post_t * post, component_posts) { - handle_value(/* value= */ subtotal, - /* account= */ find_totals_account(post->account), + + foreach (totals_map::value_type& pat, totals) { + handle_value(/* value= */ pat.second, + /* account= */ &temps.create_account(pat.first), /* xact= */ &xact, /* temps= */ temps, /* handler= */ handler, @@ -461,6 +461,7 @@ void collapse_posts::report_subtotal() } + totals.clear(); component_posts.clear(); last_xact = NULL; @@ -469,19 +470,14 @@ void collapse_posts::report_subtotal() count = 0; } -account_t* collapse_posts::find_totals_account(account_t* account) +value_t& collapse_posts::find_totals(account_t* account) { - unsigned short depth=2; + unsigned short depth=3; if(account->depth==depth) - { - string name=account->fullname(); - account_t*& acc = totals_accounts[name]; - if(acc==NULL) - acc= &temps.create_account(name); - return acc; - } - //recurse - return find_totals_account(account->parent); + return totals[account->fullname()]; + + //else recurse + return find_totals(account->parent); } void collapse_posts::operator()(post_t& post) @@ -493,6 +489,7 @@ void collapse_posts::operator()(post_t& post) report_subtotal(); post.add_to_value(subtotal, amount_expr); + post.add_to_value(find_totals(post.account), amount_expr); component_posts.push_back(&post); diff --git a/src/filters.h b/src/filters.h index f05ddaa1..d6e1b6fc 100644 --- a/src/filters.h +++ b/src/filters.h @@ -421,18 +421,21 @@ public: class collapse_posts : public item_handler { - expr_t& amount_expr; - predicate_t display_predicate; - predicate_t only_predicate; - value_t subtotal; - std::size_t count; - xact_t * last_xact; - post_t * last_post; - temporaries_t temps; - std::map totals_accounts; - bool only_collapse_if_zero; - std::list component_posts; - report_t& report; + + typedef std::map totals_map; + + expr_t& amount_expr; + predicate_t display_predicate; + predicate_t only_predicate; + value_t subtotal; + std::size_t count; + xact_t * last_xact; + post_t * last_post; + temporaries_t temps; + totals_map totals; + bool only_collapse_if_zero; + std::list component_posts; + report_t& report; collapse_posts(); @@ -454,7 +457,7 @@ public: TRACE_DTOR(collapse_posts); handler.reset(); } - account_t* find_totals_account(account_t* account); + value_t& find_totals(account_t* account); virtual void flush() { report_subtotal(); @@ -476,7 +479,7 @@ public: last_post = NULL; temps.clear(); - totals_accounts.clear(); + totals.clear(); component_posts.clear(); item_handler::clear(); -- cgit v1.2.3 From 658029d39f8594c7f3bf75fb8f7ca9fb2081b473 Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 16:13:37 +0100 Subject: first implementation of --depth for register --- src/filters.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/filters.cc') diff --git a/src/filters.cc b/src/filters.cc index f7321438..2b4fe1bf 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -473,6 +473,10 @@ void collapse_posts::report_subtotal() value_t& collapse_posts::find_totals(account_t* account) { unsigned short depth=3; + + if(depth==0) + return totals[_("")]; + if(account->depth==depth) return totals[account->fullname()]; -- cgit v1.2.3