From 32df4dd5631462c05471734d5d684d0f01c6fc6f Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 13 Feb 2005 23:26:55 +0000 Subject: (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. --- format.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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; } } -- cgit v1.2.3