chain_xact_handlers now always operators the same
Previously, account-wise reports used a subset of the total number of transaction filters, but this could cause confusing results, and made some reports immpossible (such as account-wise monthly averages).
This commit is contained in:
parent
cb6b6e8b67
commit
5d4ac67920
3 changed files with 72 additions and 79 deletions
138
src/chain.cc
138
src/chain.cc
|
|
@ -36,89 +36,85 @@
|
||||||
namespace ledger {
|
namespace ledger {
|
||||||
|
|
||||||
xact_handler_ptr chain_xact_handlers(report_t& report,
|
xact_handler_ptr chain_xact_handlers(report_t& report,
|
||||||
xact_handler_ptr base_handler,
|
xact_handler_ptr base_handler)
|
||||||
const bool handle_individual_xacts)
|
|
||||||
{
|
{
|
||||||
xact_handler_ptr handler(base_handler);
|
xact_handler_ptr handler(base_handler);
|
||||||
|
|
||||||
// format_xacts write each xact received to the output stream.
|
// truncate_entries cuts off a certain number of _entries_ from being
|
||||||
if (handle_individual_xacts) {
|
// displayed. It does not affect calculation.
|
||||||
// truncate_entries cuts off a certain number of _entries_ from being
|
if (report.HANDLED(head_) || report.HANDLED(tail_))
|
||||||
// displayed. It does not affect calculation.
|
handler.reset(new truncate_entries(handler,
|
||||||
if (report.HANDLED(head_) || report.HANDLED(tail_))
|
report.HANDLER(head_).value.to_long(),
|
||||||
handler.reset(new truncate_entries(handler,
|
report.HANDLER(tail_).value.to_long()));
|
||||||
report.HANDLER(head_).value.to_long(),
|
|
||||||
report.HANDLER(tail_).value.to_long()));
|
|
||||||
|
|
||||||
// filter_xacts will only pass through xacts matching the
|
// filter_xacts will only pass through xacts matching the
|
||||||
// `display_predicate'.
|
// `display_predicate'.
|
||||||
if (report.HANDLED(display_))
|
if (report.HANDLED(display_))
|
||||||
handler.reset(new filter_xacts
|
handler.reset(new filter_xacts
|
||||||
(handler, item_predicate<xact_t>(report.HANDLER(display_).str(),
|
(handler, item_predicate<xact_t>(report.HANDLER(display_).str(),
|
||||||
report.what_to_keep())));
|
report.what_to_keep())));
|
||||||
|
|
||||||
// calc_xacts computes the running total. When this appears will
|
// calc_xacts computes the running total. When this appears will
|
||||||
// determine, for example, whether filtered xacts are included or excluded
|
// determine, for example, whether filtered xacts are included or excluded
|
||||||
// from the running total.
|
// from the running total.
|
||||||
assert(report.HANDLED(amount_));
|
assert(report.HANDLED(amount_));
|
||||||
expr_t& expr(report.HANDLER(amount_).expr);
|
expr_t& expr(report.HANDLER(amount_).expr);
|
||||||
expr.set_context(&report);
|
expr.set_context(&report);
|
||||||
handler.reset(new calc_xacts(handler, expr));
|
handler.reset(new calc_xacts(handler, expr));
|
||||||
|
|
||||||
// filter_xacts will only pass through xacts matching the
|
// filter_xacts will only pass through xacts matching the
|
||||||
// `secondary_predicate'.
|
// `secondary_predicate'.
|
||||||
if (report.HANDLED(only_))
|
if (report.HANDLED(only_))
|
||||||
handler.reset(new filter_xacts
|
handler.reset(new filter_xacts
|
||||||
(handler, item_predicate<xact_t>
|
(handler, item_predicate<xact_t>
|
||||||
(report.HANDLER(only_).str(), report.what_to_keep())));
|
(report.HANDLER(only_).str(), report.what_to_keep())));
|
||||||
|
|
||||||
// sort_xacts will sort all the xacts it sees, based on the `sort_order'
|
// sort_xacts will sort all the xacts it sees, based on the `sort_order'
|
||||||
// value expression.
|
// value expression.
|
||||||
if (report.HANDLED(sort_)) {
|
if (report.HANDLED(sort_)) {
|
||||||
if (report.HANDLED(sort_entries_))
|
if (report.HANDLED(sort_entries_))
|
||||||
handler.reset(new sort_entries(handler, report.HANDLER(sort_).str()));
|
handler.reset(new sort_entries(handler, report.HANDLER(sort_).str()));
|
||||||
else
|
else
|
||||||
handler.reset(new sort_xacts(handler, report.HANDLER(sort_).str()));
|
handler.reset(new sort_xacts(handler, report.HANDLER(sort_).str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// changed_value_xacts adds virtual xacts to the list to account for
|
// changed_value_xacts adds virtual xacts to the list to account for
|
||||||
// changes in market value of commodities, which otherwise would affect
|
// changes in market value of commodities, which otherwise would affect
|
||||||
// the running total unpredictably.
|
// the running total unpredictably.
|
||||||
if (report.HANDLED(revalued))
|
if (report.HANDLED(revalued))
|
||||||
handler.reset(new changed_value_xacts(handler,
|
handler.reset(new changed_value_xacts(handler,
|
||||||
report.HANDLER(total_).expr,
|
report.HANDLER(total_).expr,
|
||||||
report.HANDLED(revalued_only)));
|
report.HANDLED(revalued_only)));
|
||||||
|
|
||||||
// collapse_xacts causes entries with multiple xacts to appear as entries
|
// collapse_xacts causes entries with multiple xacts to appear as entries
|
||||||
// with a subtotaled xact for each commodity used.
|
// with a subtotaled xact for each commodity used.
|
||||||
if (report.HANDLED(collapse))
|
if (report.HANDLED(collapse))
|
||||||
handler.reset(new collapse_xacts(handler, expr,
|
handler.reset(new collapse_xacts(handler, expr,
|
||||||
report.HANDLED(collapse_if_zero)));
|
report.HANDLED(collapse_if_zero)));
|
||||||
|
|
||||||
// subtotal_xacts combines all the xacts it receives into one subtotal
|
// subtotal_xacts combines all the xacts it receives into one subtotal
|
||||||
// entry, which has one xact for each commodity in each account.
|
// entry, which has one xact for each commodity in each account.
|
||||||
//
|
//
|
||||||
// period_xacts is like subtotal_xacts, but it subtotals according to time
|
// period_xacts is like subtotal_xacts, but it subtotals according to time
|
||||||
// periods rather than totalling everything.
|
// periods rather than totalling everything.
|
||||||
//
|
//
|
||||||
// dow_xacts is like period_xacts, except that it reports all the xacts
|
// dow_xacts is like period_xacts, except that it reports all the xacts
|
||||||
// that fall on each subsequent day of the week.
|
// that fall on each subsequent day of the week.
|
||||||
if (report.HANDLED(subtotal))
|
if (report.HANDLED(subtotal))
|
||||||
handler.reset(new subtotal_xacts(handler, expr));
|
handler.reset(new subtotal_xacts(handler, expr));
|
||||||
|
|
||||||
if (report.HANDLED(dow))
|
if (report.HANDLED(dow))
|
||||||
handler.reset(new dow_xacts(handler, expr));
|
handler.reset(new dow_xacts(handler, expr));
|
||||||
else if (report.HANDLED(by_payee))
|
else if (report.HANDLED(by_payee))
|
||||||
handler.reset(new by_payee_xacts(handler, expr));
|
handler.reset(new by_payee_xacts(handler, expr));
|
||||||
|
|
||||||
// interval_xacts groups xacts together based on a time period, such as
|
// interval_xacts groups xacts together based on a time period, such as
|
||||||
// weekly or monthly.
|
// weekly or monthly.
|
||||||
if (report.HANDLED(period_)) {
|
if (report.HANDLED(period_)) {
|
||||||
handler.reset(new interval_xacts(handler, expr,
|
handler.reset(new interval_xacts(handler, expr,
|
||||||
report.HANDLER(period_).str(),
|
report.HANDLER(period_).str(),
|
||||||
report.session.master.get()));
|
report.session.master.get()));
|
||||||
handler.reset(new sort_xacts(handler, "date"));
|
handler.reset(new sort_xacts(handler, "date"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// invert_xacts inverts the value of the xacts it receives.
|
// invert_xacts inverts the value of the xacts it receives.
|
||||||
|
|
|
||||||
|
|
@ -88,11 +88,8 @@ typedef shared_ptr<item_handler<xact_t> > xact_handler_ptr;
|
||||||
typedef shared_ptr<item_handler<account_t> > acct_handler_ptr;
|
typedef shared_ptr<item_handler<account_t> > acct_handler_ptr;
|
||||||
|
|
||||||
class report_t;
|
class report_t;
|
||||||
|
xact_handler_ptr chain_xact_handlers(report_t& report,
|
||||||
xact_handler_ptr
|
xact_handler_ptr base_handler);
|
||||||
chain_xact_handlers(report_t& report,
|
|
||||||
xact_handler_ptr base_handler,
|
|
||||||
const bool handle_individual_xacts = true);
|
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,9 @@ void report_t::sum_all_accounts()
|
||||||
expr.set_context(this);
|
expr.set_context(this);
|
||||||
|
|
||||||
journal_xacts_iterator walker(*session.journal.get());
|
journal_xacts_iterator walker(*session.journal.get());
|
||||||
pass_down_xacts
|
pass_down_xacts(chain_xact_handlers
|
||||||
(chain_xact_handlers(*this, xact_handler_ptr(new set_account_value(expr)),
|
(*this, xact_handler_ptr(new set_account_value(expr))),
|
||||||
false), walker);
|
walker);
|
||||||
|
|
||||||
expr.mark_uncompiled(); // recompile, throw away xact_t bindings
|
expr.mark_uncompiled(); // recompile, throw away xact_t bindings
|
||||||
session.master->calculate_sums(expr);
|
session.master->calculate_sums(expr);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue