diff options
author | John Wiegley <johnw@newartisans.com> | 2015-08-04 14:23:44 -0700 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2015-08-04 14:23:44 -0700 |
commit | fbba9adc16c515632a5009d2ec88c9fcab532676 (patch) | |
tree | ba1175218f653b46fae7b978ae5d5dd4b91edf65 | |
parent | 00e4cdb008a21ded16efdac80a6249cfc316f71d (diff) | |
parent | 658029d39f8594c7f3bf75fb8f7ca9fb2081b473 (diff) | |
download | fork-ledger-fbba9adc16c515632a5009d2ec88c9fcab532676.tar.gz fork-ledger-fbba9adc16c515632a5009d2ec88c9fcab532676.tar.bz2 fork-ledger-fbba9adc16c515632a5009d2ec88c9fcab532676.zip |
Merge pull request #216 from johannesgerer/master
--depth for register
-rw-r--r-- | doc/ledger3.texi | 2 | ||||
-rw-r--r-- | src/filters.cc | 33 | ||||
-rw-r--r-- | src/filters.h | 13 |
3 files changed, 33 insertions, 15 deletions
diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 62869a29..4dc3f48f 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -7740,7 +7740,7 @@ The market value of a posting or an account, without its children. The net gain (market value minus cost basis), for a posting or an account, without its children. It is the same as @samp{v-b}. -@item l +@item depth The depth (``level'') of an account. If an account has one parent, its depth is one. diff --git a/src/filters.cc b/src/filters.cc index 2f97a0e5..fd30c966 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -448,16 +448,20 @@ 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 (totals_map::value_type& pat, totals) { + handle_value(/* value= */ pat.second, + /* account= */ &temps.create_account(pat.first), + /* xact= */ &xact, + /* temps= */ temps, + /* handler= */ handler, + /* date= */ latest_date, + /* act_date_p= */ false); + } - handle_value(/* value= */ subtotal, - /* account= */ totals_account, - /* xact= */ &xact, - /* temps= */ temps, - /* handler= */ handler, - /* date= */ latest_date, - /* act_date_p= */ false); } + totals.clear(); component_posts.clear(); last_xact = NULL; @@ -466,6 +470,20 @@ void collapse_posts::report_subtotal() count = 0; } +value_t& collapse_posts::find_totals(account_t* account) +{ + unsigned short depth=3; + + if(depth==0) + return totals[_("<Total>")]; + + if(account->depth==depth) + return totals[account->fullname()]; + + //else recurse + return find_totals(account->parent); +} + void collapse_posts::operator()(post_t& post) { // If we've reached a new xact, report on the subtotal @@ -475,6 +493,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 1404b38e..9b745235 100644 --- a/src/filters.h +++ b/src/filters.h @@ -421,6 +421,9 @@ public: class collapse_posts : public item_handler<post_t> { + + typedef std::map<string,value_t> totals_map; + expr_t& amount_expr; predicate_t display_predicate; predicate_t only_predicate; @@ -429,7 +432,7 @@ class collapse_posts : public item_handler<post_t> xact_t * last_xact; post_t * last_post; temporaries_t temps; - account_t * totals_account; + totals_map totals; bool only_collapse_if_zero; std::list<post_t *> component_posts; report_t& report; @@ -448,17 +451,13 @@ public: only_predicate(_only_predicate), count(0), last_xact(NULL), last_post(NULL), only_collapse_if_zero(_only_collapse_if_zero), report(_report) { - create_accounts(); TRACE_CTOR(collapse_posts, "post_handler_ptr, ..."); } virtual ~collapse_posts() { TRACE_DTOR(collapse_posts); handler.reset(); } - - void create_accounts() { - totals_account = &temps.create_account(_("<Total>")); - } + value_t& find_totals(account_t* account); virtual void flush() { report_subtotal(); @@ -480,7 +479,7 @@ public: last_post = NULL; temps.clear(); - create_accounts(); + totals.clear(); component_posts.clear(); item_handler<post_t>::clear(); |