summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2005-02-13 23:26:55 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:40:59 -0400
commit32df4dd5631462c05471734d5d684d0f01c6fc6f (patch)
treeef1a7623b6ad6eaf6bed58a82cad105092ee43ef
parent76f0d00f408c06cf0d42ed061e3f93ffe682b739 (diff)
downloadfork-ledger-32df4dd5631462c05471734d5d684d0f01c6fc6f.tar.gz
fork-ledger-32df4dd5631462c05471734d5d684d0f01c6fc6f.tar.bz2
fork-ledger-32df4dd5631462c05471734d5d684d0f01c6fc6f.zip
(format_equity::flush): If the equity balance uses multiple
commodities, then multiple "Equity" lines need to be printed, one for each. (format_equity::operator()): Same, but for individual accounts.
-rw-r--r--format.cc48
1 files changed, 44 insertions, 4 deletions
diff --git a/format.cc b/format.cc
index c8d07cd8..036e83e1 100644
--- a/format.cc
+++ b/format.cc
@@ -820,16 +820,56 @@ void format_equity::flush()
xdata.value.negate();
account_t summary(NULL, "Equity:Opening Balances");
summary.data = &xdata;
- next_lines_format.format(output_stream, details_t(summary));
+
+ if (total.type >= value_t::BALANCE) {
+ balance_t * bal;
+ if (total.type == value_t::BALANCE)
+ bal = (balance_t *) total.data;
+ else if (total.type == value_t::BALANCE_PAIR)
+ bal = &((balance_pair_t *) total.data)->quantity;
+ else
+ assert(0);
+
+ for (amounts_map::const_iterator i = bal->amounts.begin();
+ i != bal->amounts.end();
+ i++) {
+ xdata.value = (*i).second;
+ xdata.value.negate();
+ next_lines_format.format(output_stream, details_t(summary));
+ }
+ } else {
+ next_lines_format.format(output_stream, details_t(summary));
+ }
output_stream.flush();
}
void format_equity::operator()(account_t& account)
{
if (display_account(account, disp_pred)) {
- next_lines_format.format(output_stream, details_t(account));
- if (account_has_xdata(account))
- total += account_xdata_(account).value;
+ if (account_has_xdata(account)) {
+ value_t val = account_xdata_(account).value;
+
+ if (val.type >= value_t::BALANCE) {
+ balance_t * bal;
+ if (val.type == value_t::BALANCE)
+ bal = (balance_t *) val.data;
+ else if (val.type == value_t::BALANCE_PAIR)
+ bal = &((balance_pair_t *) val.data)->quantity;
+ else
+ assert(0);
+
+ for (amounts_map::const_iterator i = bal->amounts.begin();
+ i != bal->amounts.end();
+ i++) {
+ account_xdata_(account).value = (*i).second;
+ next_lines_format.format(output_stream, details_t(account));
+ }
+ account_xdata_(account).value = val;
+ } else {
+ next_lines_format.format(output_stream, details_t(account));
+ }
+ total += val;
+ }
account_xdata(account).dflags |= ACCOUNT_DISPLAYED;
}
}