Only display a final balance total if necessary
In the case where only one top-level account is being reported, there is no reason to duplicate the total balance shown.
This commit is contained in:
parent
07f4aefdfd
commit
93d195f1d9
3 changed files with 38 additions and 31 deletions
|
|
@ -118,12 +118,12 @@ class account_t : public scope_t
|
||||||
|
|
||||||
struct xdata_t : public supports_flags<>
|
struct xdata_t : public supports_flags<>
|
||||||
{
|
{
|
||||||
#define ACCOUNT_EXT_DISPLAYED 0x01
|
#define ACCOUNT_EXT_SORT_CALC 0x01
|
||||||
#define ACCOUNT_EXT_SORT_CALC 0x02
|
#define ACCOUNT_EXT_HAS_NON_VIRTUALS 0x02
|
||||||
#define ACCOUNT_EXT_HAS_NON_VIRTUALS 0x04
|
#define ACCOUNT_EXT_HAS_UNB_VIRTUALS 0x04
|
||||||
#define ACCOUNT_EXT_HAS_UNB_VIRTUALS 0x08
|
#define ACCOUNT_EXT_VISITED 0x08
|
||||||
#define ACCOUNT_EXT_VISITED 0x10
|
#define ACCOUNT_EXT_MATCHING 0x10
|
||||||
#define ACCOUNT_EXT_MATCHING 0x20
|
#define ACCOUNT_EXT_DISPLAYED 0x20
|
||||||
|
|
||||||
value_t value;
|
value_t value;
|
||||||
value_t total;
|
value_t total;
|
||||||
|
|
|
||||||
|
|
@ -210,8 +210,10 @@ void format_entries::operator()(xact_t& xact)
|
||||||
last_entry = xact.entry;
|
last_entry = xact.entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_accounts::post_accounts(account_t& account)
|
std::size_t format_accounts::post_accounts(account_t& account)
|
||||||
{
|
{
|
||||||
|
std::size_t displayed = 0;
|
||||||
|
|
||||||
// Don't ever print the top-most account
|
// Don't ever print the top-most account
|
||||||
if (account.parent) {
|
if (account.parent) {
|
||||||
bind_scope_t bound_scope(report, account);
|
bind_scope_t bound_scope(report, account);
|
||||||
|
|
@ -242,31 +244,37 @@ void format_accounts::post_accounts(account_t& account)
|
||||||
" No, neither it nor its children were eligible for display");
|
" No, neither it nor its children were eligible for display");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format_account)
|
if (format_account) {
|
||||||
|
account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED);
|
||||||
|
displayed++;
|
||||||
|
|
||||||
format.format(report.output_stream, bound_scope);
|
format.format(report.output_stream, bound_scope);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (accounts_map::value_type pair, account.accounts)
|
foreach (accounts_map::value_type pair, account.accounts) {
|
||||||
post_accounts(*pair.second);
|
if (post_accounts(*pair.second) > 0)
|
||||||
|
displayed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return displayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_accounts::flush()
|
void format_accounts::flush()
|
||||||
{
|
{
|
||||||
std::ostream& out(report.output_stream);
|
std::ostream& out(report.output_stream);
|
||||||
|
|
||||||
post_accounts(*report.session.master.get());
|
std::size_t top_displayed = post_accounts(*report.session.master.get());
|
||||||
|
|
||||||
if (print_final_total) {
|
|
||||||
assert(report.session.master->has_xdata());
|
assert(report.session.master->has_xdata());
|
||||||
account_t::xdata_t& xdata(report.session.master->xdata());
|
account_t::xdata_t& xdata(report.session.master->xdata());
|
||||||
|
|
||||||
if (! report.HANDLED(collapse) && xdata.total) {
|
if (top_displayed > 1 && ! report.HANDLED(collapse) && xdata.total) {
|
||||||
out << "--------------------\n";
|
out << "--------------------\n";
|
||||||
xdata.value = xdata.total;
|
xdata.value = xdata.total;
|
||||||
bind_scope_t bound_scope(report, *report.session.master);
|
bind_scope_t bound_scope(report, *report.session.master);
|
||||||
format.format(out, bound_scope);
|
format.format(out, bound_scope);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
|
@ -341,12 +349,12 @@ void format_equity::flush()
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void format_equity::post_accounts(account_t& account)
|
std::size_t format_equity::post_accounts(account_t& account)
|
||||||
{
|
{
|
||||||
std::ostream& out(report.output_stream);
|
std::ostream& out(report.output_stream);
|
||||||
|
|
||||||
if (! account.has_flags(ACCOUNT_EXT_MATCHING))
|
if (! account.has_flags(ACCOUNT_EXT_MATCHING))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
value_t val = account.xdata().value;
|
value_t val = account.xdata().value;
|
||||||
|
|
||||||
|
|
@ -368,6 +376,8 @@ void format_equity::post_accounts(account_t& account)
|
||||||
next_lines_format.format(out, bound_scope);
|
next_lines_format.format(out, bound_scope);
|
||||||
}
|
}
|
||||||
total += val;
|
total += val;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
11
src/output.h
11
src/output.h
|
|
@ -163,14 +163,11 @@ protected:
|
||||||
report_t& report;
|
report_t& report;
|
||||||
format_t format;
|
format_t format;
|
||||||
item_predicate disp_pred;
|
item_predicate disp_pred;
|
||||||
bool print_final_total;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
format_accounts(report_t& _report,
|
format_accounts(report_t& _report,
|
||||||
const string& _format = "",
|
const string& _format = "")
|
||||||
const bool _print_final_total = true)
|
: report(_report), format(_format), disp_pred()
|
||||||
: report(_report), format(_format), disp_pred(),
|
|
||||||
print_final_total(_print_final_total)
|
|
||||||
{
|
{
|
||||||
TRACE_CTOR(format_accounts, "report&, const string&, const bool");
|
TRACE_CTOR(format_accounts, "report&, const string&, const bool");
|
||||||
|
|
||||||
|
|
@ -184,7 +181,7 @@ public:
|
||||||
TRACE_DTOR(format_accounts);
|
TRACE_DTOR(format_accounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void post_accounts(account_t& account);
|
virtual std::size_t post_accounts(account_t& account);
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
|
|
||||||
virtual void operator()(account_t& account);
|
virtual void operator()(account_t& account);
|
||||||
|
|
@ -209,8 +206,8 @@ class format_equity : public format_accounts
|
||||||
TRACE_DTOR(format_equity);
|
TRACE_DTOR(format_equity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::size_t post_accounts(account_t& account);
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
virtual void post_accounts(account_t& account);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue