summaryrefslogtreecommitdiff
path: root/src/filters.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-20 02:53:54 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-20 02:53:54 -0400
commitc1b25fcf8629eca326fe6dd586e4896eeb5f2d45 (patch)
treef7c59ce215ee66513db2f9eb142cdf9e7095c465 /src/filters.cc
parentf2f52066d2a9c82619ffea0f3972e48417a90b5b (diff)
downloadfork-ledger-c1b25fcf8629eca326fe6dd586e4896eeb5f2d45.tar.gz
fork-ledger-c1b25fcf8629eca326fe6dd586e4896eeb5f2d45.tar.bz2
fork-ledger-c1b25fcf8629eca326fe6dd586e4896eeb5f2d45.zip
Rewrote the equity command, which is working again
The old implementation used an account formatter, and was very specialized. The new is done as a transaction filter, and works along with everything else, eliminating bugs special to the equity report.
Diffstat (limited to 'src/filters.cc')
-rw-r--r--src/filters.cc45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/filters.cc b/src/filters.cc
index c5116b6c..651bc762 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -516,7 +516,7 @@ void interval_xacts::operator()(xact_t& xact)
xact_temps.push_back(xact_t(&empty_account));
xact_t& null_xact = xact_temps.back();
- null_xact.add_flags(ITEM_TEMP);
+ null_xact.add_flags(ITEM_TEMP | XACT_CALCULATED);
null_xact.amount = 0L;
null_entry.add_xact(&null_xact);
@@ -536,6 +536,49 @@ void interval_xacts::operator()(xact_t& xact)
last_xact = &xact;
}
+void xacts_as_equity::report_subtotal()
+{
+ date_t finish;
+ foreach (xact_t * xact, component_xacts) {
+ date_t date = xact->reported_date();
+ if (! is_valid(finish) || date > finish)
+ finish = date;
+ }
+ component_xacts.clear();
+
+ entry_temps.push_back(entry_t());
+ entry_t& entry = entry_temps.back();
+ entry.payee = "Opening Balances";
+ entry._date = finish;
+
+ value_t total = 0L;
+ foreach (values_map::value_type& pair, values) {
+ handle_value(pair.second.value, pair.second.account, &entry, 0,
+ xact_temps, *handler);
+ total += pair.second.value;
+ }
+ values.clear();
+
+ if (total.is_balance()) {
+ foreach (balance_t::amounts_map::value_type pair,
+ total.as_balance().amounts) {
+ xact_temps.push_back(xact_t(balance_account));
+ xact_t& balance_xact = xact_temps.back();
+ balance_xact.add_flags(ITEM_TEMP);
+ balance_xact.amount = - pair.second;
+ entry.add_xact(&balance_xact);
+ (*handler)(balance_xact);
+ }
+ } else {
+ xact_temps.push_back(xact_t(balance_account));
+ xact_t& balance_xact = xact_temps.back();
+ balance_xact.add_flags(ITEM_TEMP);
+ balance_xact.amount = - total.to_amount();
+ entry.add_xact(&balance_xact);
+ (*handler)(balance_xact);
+ }
+}
+
by_payee_xacts::~by_payee_xacts()
{
TRACE_DTOR(by_payee_xacts);