diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-19 04:18:56 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-19 04:18:56 -0500 |
commit | d2422f99e6edd17b86502b34be4fb618fe4c838d (patch) | |
tree | cbb8fb383ad6e7ca208d6f353a056c5640ffb3d8 | |
parent | aee05dc7b7099d4bff8827e293e6b1e3442b9cd9 (diff) | |
download | fork-ledger-d2422f99e6edd17b86502b34be4fb618fe4c838d.tar.gz fork-ledger-d2422f99e6edd17b86502b34be4fb618fe4c838d.tar.bz2 fork-ledger-d2422f99e6edd17b86502b34be4fb618fe4c838d.zip |
Allow the equity command to strip annotations
-rw-r--r-- | src/chain.cc | 2 | ||||
-rw-r--r-- | src/filters.cc | 47 | ||||
-rw-r--r-- | src/filters.h | 6 |
3 files changed, 31 insertions, 24 deletions
diff --git a/src/chain.cc b/src/chain.cc index 44b3db82..52d52f14 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -207,7 +207,7 @@ post_handler_ptr chain_post_handlers(post_handler_ptr base_handler, // day_of_week_posts is like period_posts, except that it reports // all the posts that fall on each subsequent day of the week. if (report.HANDLED(equity)) - handler.reset(new posts_as_equity(handler, expr)); + handler.reset(new posts_as_equity(handler, report, expr)); else if (report.HANDLED(subtotal)) handler.reset(new subtotal_posts(handler, expr)); } diff --git a/src/filters.cc b/src/filters.cc index 749efc77..96e8026a 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -1033,40 +1033,45 @@ void posts_as_equity::report_subtotal() value_t total = 0L; foreach (values_map::value_type& pair, values) { - if (pair.second.value.is_balance()) { - foreach (const balance_t::amounts_map::value_type& amount_pair, - pair.second.value.as_balance().amounts) - handle_value(/* value= */ amount_pair.second, + value_t value(pair.second.value.strip_annotations(report.what_to_keep())); + if (! value.is_zero()) { + if (value.is_balance()) { + foreach (const balance_t::amounts_map::value_type& amount_pair, + value.as_balance_lval().amounts) + handle_value(/* value= */ amount_pair.second, + /* account= */ pair.second.account, + /* xact= */ &xact, + /* temps= */ temps, + /* handler= */ handler, + /* date= */ finish, + /* act_date_p= */ false); + } else { + handle_value(/* value= */ value.to_amount(), /* account= */ pair.second.account, /* xact= */ &xact, /* temps= */ temps, /* handler= */ handler, /* date= */ finish, /* act_date_p= */ false); - } else { - handle_value(/* value= */ pair.second.value, - /* account= */ pair.second.account, - /* xact= */ &xact, - /* temps= */ temps, - /* handler= */ handler, - /* date= */ finish, - /* act_date_p= */ false); + } } - total += pair.second.value; + total += value; } values.clear(); - if (total.is_balance()) { - foreach (const balance_t::amounts_map::value_type& pair, - total.as_balance().amounts) { + if (! total.is_zero()) { + if (total.is_balance()) { + foreach (const balance_t::amounts_map::value_type& pair, + total.as_balance().amounts) { + post_t& balance_post = temps.create_post(xact, balance_account); + balance_post.amount = - pair.second; + (*handler)(balance_post); + } + } else { post_t& balance_post = temps.create_post(xact, balance_account); - balance_post.amount = - pair.second; + balance_post.amount = - total.to_amount(); (*handler)(balance_post); } - } else { - post_t& balance_post = temps.create_post(xact, balance_account); - balance_post.amount = - total.to_amount(); - (*handler)(balance_post); } } diff --git a/src/filters.h b/src/filters.h index d73fff86..3e766863 100644 --- a/src/filters.h +++ b/src/filters.h @@ -763,6 +763,7 @@ public: class posts_as_equity : public subtotal_posts { + report_t& report; post_t * last_post; account_t * equity_account; account_t * balance_account; @@ -770,8 +771,9 @@ class posts_as_equity : public subtotal_posts posts_as_equity(); public: - posts_as_equity(post_handler_ptr _handler, expr_t& amount_expr) - : subtotal_posts(_handler, amount_expr) { + posts_as_equity(post_handler_ptr _handler, report_t& _report, + expr_t& amount_expr) + : subtotal_posts(_handler, amount_expr), report(_report) { TRACE_CTOR(posts_as_equity, "post_handler_ptr, expr_t&"); create_accounts(); } |