summaryrefslogtreecommitdiff
path: root/src/chain.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-05-30 02:28:58 -0600
committerJohn Wiegley <johnw@newartisans.com>2010-05-30 02:47:40 -0600
commit647d4aac2fa474085d01f7ea1cebdc34fafd64a6 (patch)
treec17157d73c3a9d5dd182a4b7b0896e4f31e318be /src/chain.cc
parenta41d33fba37460587f59ea0349ac4947a4de9f3c (diff)
downloadfork-ledger-647d4aac2fa474085d01f7ea1cebdc34fafd64a6.tar.gz
fork-ledger-647d4aac2fa474085d01f7ea1cebdc34fafd64a6.tar.bz2
fork-ledger-647d4aac2fa474085d01f7ea1cebdc34fafd64a6.zip
New: --group-by=EXPR and --group-title-format=FMT
The --group-by option allows for most reports to be split up into sections based on the varying value of EXPR. For example, to see register subtotals by payee, use: ledger reg --group-by=payee -s This works for separated balances too: ledger bal --group-by=payee Another interesting possibility is seeing a register of all the accounts affected by a related account: ledger reg -r --group-by=payee The option --group-title-format can be used to add a separator bar to the group titles. The option --no-titles can be used to drop titles altogether.
Diffstat (limited to 'src/chain.cc')
-rw-r--r--src/chain.cc126
1 files changed, 67 insertions, 59 deletions
diff --git a/src/chain.cc b/src/chain.cc
index 1103fe42..b8c2eb0a 100644
--- a/src/chain.cc
+++ b/src/chain.cc
@@ -39,6 +39,73 @@
namespace ledger {
+post_handler_ptr chain_pre_post_handlers(report_t& report,
+ post_handler_ptr base_handler)
+{
+ post_handler_ptr handler(base_handler);
+
+ // anonymize_posts removes all meaningful information from xact payee's and
+ // account names, for the sake of creating useful bug reports.
+ if (report.HANDLED(anon))
+ handler.reset(new anonymize_posts(handler));
+
+ // This filter_posts will only pass through posts matching the `predicate'.
+ if (report.HANDLED(limit_)) {
+ DEBUG("report.predicate",
+ "Report predicate expression = " << report.HANDLER(limit_).str());
+ handler.reset(new filter_posts
+ (handler, predicate_t(report.HANDLER(limit_).str(),
+ report.what_to_keep()),
+ report));
+ }
+
+ // budget_posts takes a set of posts from a data file and uses them to
+ // generate "budget posts" which balance against the reported posts.
+ //
+ // forecast_posts is a lot like budget_posts, except that it adds xacts
+ // only for the future, and does not balance them against anything but the
+ // future balance.
+
+ if (report.budget_flags != BUDGET_NO_BUDGET) {
+ budget_posts * budget_handler = new budget_posts(handler,
+ report.budget_flags);
+ budget_handler->add_period_xacts(report.session.journal->period_xacts);
+ handler.reset(budget_handler);
+
+ // Apply this before the budget handler, so that only matching posts are
+ // calculated toward the budget. The use of filter_posts above will
+ // further clean the results so that no automated posts that don't match
+ // the filter get reported.
+ if (report.HANDLED(limit_))
+ handler.reset(new filter_posts
+ (handler, predicate_t(report.HANDLER(limit_).str(),
+ report.what_to_keep()),
+ report));
+ }
+ else if (report.HANDLED(forecast_while_)) {
+ forecast_posts * forecast_handler
+ = new forecast_posts(handler,
+ predicate_t(report.HANDLER(forecast_while_).str(),
+ report.what_to_keep()),
+ report,
+ report.HANDLED(forecast_years_) ?
+ static_cast<std::size_t>
+ (report.HANDLER(forecast_years_).value.to_long()) :
+ 5UL);
+ forecast_handler->add_period_xacts(report.session.journal->period_xacts);
+ handler.reset(forecast_handler);
+
+ // See above, under budget_posts.
+ if (report.HANDLED(limit_))
+ handler.reset(new filter_posts
+ (handler, predicate_t(report.HANDLER(limit_).str(),
+ report.what_to_keep()),
+ report));
+ }
+
+ return handler;
+}
+
post_handler_ptr chain_post_handlers(report_t& report,
post_handler_ptr base_handler,
bool for_accounts_report)
@@ -189,65 +256,6 @@ post_handler_ptr chain_post_handlers(report_t& report,
if (report.HANDLED(related))
handler.reset(new related_posts(handler, report.HANDLED(related_all)));
- // anonymize_posts removes all meaningful information from xact payee's and
- // account names, for the sake of creating useful bug reports.
- if (report.HANDLED(anon))
- handler.reset(new anonymize_posts(handler));
-
- // This filter_posts will only pass through posts matching the `predicate'.
- if (report.HANDLED(limit_)) {
- DEBUG("report.predicate",
- "Report predicate expression = " << report.HANDLER(limit_).str());
- handler.reset(new filter_posts
- (handler, predicate_t(report.HANDLER(limit_).str(),
- report.what_to_keep()),
- report));
- }
-
- // budget_posts takes a set of posts from a data file and uses them to
- // generate "budget posts" which balance against the reported posts.
- //
- // forecast_posts is a lot like budget_posts, except that it adds xacts
- // only for the future, and does not balance them against anything but the
- // future balance.
-
- if (report.budget_flags != BUDGET_NO_BUDGET) {
- budget_posts * budget_handler = new budget_posts(handler,
- report.budget_flags);
- budget_handler->add_period_xacts(report.session.journal->period_xacts);
- handler.reset(budget_handler);
-
- // Apply this before the budget handler, so that only matching posts are
- // calculated toward the budget. The use of filter_posts above will
- // further clean the results so that no automated posts that don't match
- // the filter get reported.
- if (report.HANDLED(limit_))
- handler.reset(new filter_posts
- (handler, predicate_t(report.HANDLER(limit_).str(),
- report.what_to_keep()),
- report));
- }
- else if (report.HANDLED(forecast_while_)) {
- forecast_posts * forecast_handler
- = new forecast_posts(handler,
- predicate_t(report.HANDLER(forecast_while_).str(),
- report.what_to_keep()),
- report,
- report.HANDLED(forecast_years_) ?
- static_cast<std::size_t>
- (report.HANDLER(forecast_years_).value.to_long()) :
- 5UL);
- forecast_handler->add_period_xacts(report.session.journal->period_xacts);
- handler.reset(forecast_handler);
-
- // See above, under budget_posts.
- if (report.HANDLED(limit_))
- handler.reset(new filter_posts
- (handler, predicate_t(report.HANDLER(limit_).str(),
- report.what_to_keep()),
- report));
- }
-
return handler;
}