If 2+ child accounts are shown, show the parent

Also, also show a final balance if there are multiple accounts
displayed, even if that final balance is zero.
This commit is contained in:
John Wiegley 2009-03-15 21:31:06 -04:00
parent d0963ece02
commit 16c77af9c9
10 changed files with 49 additions and 14 deletions

View file

@ -136,14 +136,22 @@ format_accounts::format_accounts(report_t& _report,
} }
} }
void format_accounts::post_account(account_t& account) std::size_t format_accounts::post_account(account_t& account)
{ {
if (account.xdata().has_flags(ACCOUNT_EXT_TO_DISPLAY)) { if (account.xdata().has_flags(ACCOUNT_EXT_TO_DISPLAY)) {
if (account.parent &&
account.parent->xdata().has_flags(ACCOUNT_EXT_TO_DISPLAY) &&
! account.parent->xdata().has_flags(ACCOUNT_EXT_DISPLAYED))
post_account(*account.parent);
account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED); account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
bind_scope_t bound_scope(report, account); bind_scope_t bound_scope(report, account);
account_line_format.format(report.output_stream, bound_scope); account_line_format.format(report.output_stream, bound_scope);
return 1;
} }
return 0;
} }
std::pair<std::size_t, std::size_t> std::pair<std::size_t, std::size_t>
@ -167,9 +175,11 @@ format_accounts::mark_accounts(account_t& account, const bool flat)
" it has " << to_display << " children to display"); " it has " << to_display << " children to display");
#endif #endif
if (account.has_flags(ACCOUNT_EXT_VISITED) || (! flat && visited > 0)) { if (account.parent &&
(account.has_flags(ACCOUNT_EXT_VISITED) || (! flat && visited > 0))) {
bind_scope_t bound_scope(report, account); bind_scope_t bound_scope(report, account);
if (disp_pred(bound_scope) && (flat || to_display != 1)) { if ((! flat && to_display > 1) ||
(disp_pred(bound_scope) && (flat || to_display != 1))) {
account.xdata().add_flags(ACCOUNT_EXT_TO_DISPLAY); account.xdata().add_flags(ACCOUNT_EXT_TO_DISPLAY);
DEBUG("account.display", "Marking account as TO_DISPLAY"); DEBUG("account.display", "Marking account as TO_DISPLAY");
to_display = 1; to_display = 1;
@ -192,17 +202,12 @@ void format_accounts::flush()
mark_accounts(*report.session.master, report.HANDLED(flat)); mark_accounts(*report.session.master, report.HANDLED(flat));
std::size_t top_displayed = 0; std::size_t displayed = 0;
foreach (account_t * account, posted_accounts) { foreach (account_t * account, posted_accounts)
post_account(*account); displayed += post_account(*account);
if (account->has_flags(ACCOUNT_EXT_DISPLAYED)) if (! report.HANDLED(no_total) && displayed > 1) {
top_displayed++;
}
if (! report.HANDLED(no_total) && top_displayed > 1 &&
report.session.master->family_total()) {
bind_scope_t bound_scope(report, *report.session.master); bind_scope_t bound_scope(report, *report.session.master);
separator_format.format(out, bound_scope); separator_format.format(out, bound_scope);
total_line_format.format(out, bound_scope); total_line_format.format(out, bound_scope);

View file

@ -109,7 +109,7 @@ public:
std::pair<std::size_t, std::size_t> std::pair<std::size_t, std::size_t>
mark_accounts(account_t& account, const bool flat); mark_accounts(account_t& account, const bool flat);
virtual void post_account(account_t& account); virtual std::size_t post_account(account_t& account);
virtual void flush(); virtual void flush();
virtual void operator()(account_t& account); virtual void operator()(account_t& account);

View file

@ -6,5 +6,7 @@ bal --basis
>>>1 >>>1
$0.35 Assets:Investments:Vanguard:VMMXX $0.35 Assets:Investments:Vanguard:VMMXX
$-0.35 Income:Dividends:Vanguard:VMMXX $-0.35 Income:Dividends:Vanguard:VMMXX
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -6,5 +6,7 @@ bal --cost
>>>1 >>>1
$0.35 Assets:Investments:Vanguard:VMMXX $0.35 Assets:Investments:Vanguard:VMMXX
$-0.35 Income:Dividends:Vanguard:VMMXX $-0.35 Income:Dividends:Vanguard:VMMXX
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -23,6 +23,8 @@ bal --depth 1
$-10.00 Assets $-10.00 Assets
$40.00 Expenses $40.00 Expenses
$-30.00 Income $-30.00 Income
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 2 bal --depth 2
@ -32,6 +34,8 @@ bal --depth 2
$10.00 Books $10.00 Books
$30.00 One $30.00 One
$-30.00 Income:One $-30.00 Income:One
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 3 bal --depth 3
@ -45,6 +49,8 @@ bal --depth 3
$-30.00 Income:One $-30.00 Income:One
$-10.00 Books $-10.00 Books
$-20.00 Two $-20.00 Two
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 4 bal --depth 4
@ -62,6 +68,8 @@ bal --depth 4
$-20.00 Two $-20.00 Two
$-10.00 Books $-10.00 Books
$-10.00 Three $-10.00 Three
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 5 bal --depth 5
@ -79,5 +87,7 @@ bal --depth 5
$-20.00 Two $-20.00 Two
$-10.00 Books $-10.00 Books
$-10.00 Three:Books $-10.00 Three:Books
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -26,6 +26,8 @@ bal --depth 2 --flat
>>>1 >>>1
$-10.00 Assets:Cash $-10.00 Assets:Cash
$10.00 Expenses:Books $10.00 Expenses:Books
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 3 --flat bal --depth 3 --flat
@ -34,6 +36,8 @@ bal --depth 3 --flat
$10.00 Expenses:Books $10.00 Expenses:Books
$10.00 Expenses:One:Books $10.00 Expenses:One:Books
$-10.00 Income:One:Books $-10.00 Income:One:Books
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 4 --flat bal --depth 4 --flat
@ -44,6 +48,8 @@ bal --depth 4 --flat
$10.00 Expenses:One:Two:Books $10.00 Expenses:One:Two:Books
$-10.00 Income:One:Books $-10.00 Income:One:Books
$-10.00 Income:One:Two:Books $-10.00 Income:One:Two:Books
--------------------
0
>>>2 >>>2
=== 0 === 0
bal --depth 5 --flat bal --depth 5 --flat
@ -56,5 +62,7 @@ bal --depth 5 --flat
$-10.00 Income:One:Books $-10.00 Income:One:Books
$-10.00 Income:One:Two:Books $-10.00 Income:One:Two:Books
$-10.00 Income:One:Two:Three:Books $-10.00 Income:One:Two:Three:Books
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -35,5 +35,7 @@ bal --empty
$-20.00 Two $-20.00 Two
$-10.00 Books $-10.00 Books
$-10.00 Three:Books $-10.00 Three:Books
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -29,5 +29,7 @@ bal --empty --flat
$-10.00 Income:One:Books $-10.00 Income:One:Books
$-10.00 Income:One:Two:Books $-10.00 Income:One:Two:Books
$-10.00 Income:One:Two:Three:Books $-10.00 Income:One:Two:Three:Books
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -28,5 +28,7 @@ bal --flat
$-10.00 Income:One:Books $-10.00 Income:One:Books
$-10.00 Income:One:Two:Books $-10.00 Income:One:Two:Books
$-10.00 Income:One:Two:Three:Books $-10.00 Income:One:Two:Three:Books
--------------------
0
>>>2 >>>2
=== 0 === 0

View file

@ -20,5 +20,7 @@ bal discover
0 liabilities:credit cards:discover 4462 0 liabilities:credit cards:discover 4462
$-39.00 fee $-39.00 fee
$-64.76 interest $-64.76 interest
--------------------
0
>>>2 >>>2
=== 0 === 0