-s bal is functional again
This commit is contained in:
parent
6048ae7c05
commit
c0205f0204
4 changed files with 128 additions and 65 deletions
67
format.cc
67
format.cc
|
|
@ -293,4 +293,71 @@ void format_t::format_elements(std::ostream& out,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void format_transaction::operator()(transaction_t * xact)
|
||||||
|
{
|
||||||
|
if (inverted) {
|
||||||
|
xact->total.quantity += - xact->amount;
|
||||||
|
xact->total.cost += - xact->cost;
|
||||||
|
} else {
|
||||||
|
xact->total += *xact;
|
||||||
|
}
|
||||||
|
xact->index = index++;
|
||||||
|
|
||||||
|
// This makes the assumption that transactions from a single entry
|
||||||
|
// will always be grouped together.
|
||||||
|
|
||||||
|
if (last_entry != xact->entry)
|
||||||
|
first_line_format.format_elements(output_stream, details_t(xact));
|
||||||
|
else
|
||||||
|
next_lines_format.format_elements(output_stream, details_t(xact));
|
||||||
|
|
||||||
|
last_entry = xact->entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void format_account::operator()(const account_t * account,
|
||||||
|
const unsigned int max_depth,
|
||||||
|
const bool report_top)
|
||||||
|
{
|
||||||
|
// Don't output the account if only one child will be displayed
|
||||||
|
// which shows the exact same amount. jww (2004-08-03): How do
|
||||||
|
// compute the right figure? It should a value expression specified
|
||||||
|
// by the user, to say, "If this expression is equivalent between a
|
||||||
|
// parent account and a lone displayed child, then don't display the
|
||||||
|
// parent."
|
||||||
|
|
||||||
|
if (bool output = report_top || account->parent != NULL) {
|
||||||
|
int counted = 0;
|
||||||
|
bool display = false;
|
||||||
|
|
||||||
|
for (accounts_map::const_iterator i = account->accounts.begin();
|
||||||
|
i != account->accounts.end();
|
||||||
|
i++) {
|
||||||
|
if (! (*i).second->total)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((*i).second->total != account->total || counted > 0) {
|
||||||
|
display = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
counted++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counted == 1 && ! display)
|
||||||
|
output = false;
|
||||||
|
|
||||||
|
if (output) {
|
||||||
|
unsigned int depth = account->depth;
|
||||||
|
if (max_depth == 0 || depth <= max_depth) {
|
||||||
|
for (const account_t * acct = account;
|
||||||
|
depth > 0 && acct && acct != last_account;
|
||||||
|
acct = acct->parent)
|
||||||
|
depth--;
|
||||||
|
|
||||||
|
format.format_elements(output_stream, details_t(account, depth));
|
||||||
|
last_account = account;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
37
format.h
37
format.h
|
|
@ -82,6 +82,43 @@ struct format_t
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class format_transaction
|
||||||
|
{
|
||||||
|
std::ostream& output_stream;
|
||||||
|
const format_t& first_line_format;
|
||||||
|
const format_t& next_lines_format;
|
||||||
|
const bool inverted;
|
||||||
|
unsigned int index;
|
||||||
|
entry_t * last_entry;
|
||||||
|
|
||||||
|
public:
|
||||||
|
format_transaction(std::ostream& _output_stream,
|
||||||
|
const format_t& _first_line_format,
|
||||||
|
const format_t& _next_lines_format,
|
||||||
|
const bool _inverted)
|
||||||
|
: output_stream(_output_stream),
|
||||||
|
first_line_format(_first_line_format),
|
||||||
|
next_lines_format(_next_lines_format),
|
||||||
|
inverted(_inverted), index(0), last_entry(NULL) {}
|
||||||
|
|
||||||
|
void operator()(transaction_t * xact);
|
||||||
|
};
|
||||||
|
|
||||||
|
class format_account
|
||||||
|
{
|
||||||
|
std::ostream& output_stream;
|
||||||
|
const format_t& format;
|
||||||
|
const account_t * last_account;
|
||||||
|
|
||||||
|
public:
|
||||||
|
format_account(std::ostream& _output_stream, const format_t& _format)
|
||||||
|
: output_stream(_output_stream), format(_format) {}
|
||||||
|
|
||||||
|
void operator()(const account_t * account,
|
||||||
|
const unsigned int max_depth = 1,
|
||||||
|
const bool report_top = false);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
||||||
#endif // _REPORT_H
|
#endif // _REPORT_H
|
||||||
|
|
|
||||||
3
main.cc
3
main.cc
|
|
@ -765,7 +765,8 @@ int main(int argc, char * argv[])
|
||||||
format_t format(f);
|
format_t format(f);
|
||||||
walk_accounts(journal->master, format_account(std::cout, format),
|
walk_accounts(journal->master, format_account(std::cout, format),
|
||||||
predicate.get(), xact_display_flags, show_subtotals,
|
predicate.get(), xact_display_flags, show_subtotals,
|
||||||
display_predicate.get(), sort_order.get());
|
show_expanded ? 0 : 1, display_predicate.get(),
|
||||||
|
sort_order.get());
|
||||||
|
|
||||||
if (! display_predicate.get() ||
|
if (! display_predicate.get() ||
|
||||||
item_predicate<account_t>(display_predicate.get())(journal->master)) {
|
item_predicate<account_t>(display_predicate.get())(journal->master)) {
|
||||||
|
|
|
||||||
86
walk.h
86
walk.h
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "ledger.h"
|
#include "ledger.h"
|
||||||
#include "balance.h"
|
#include "balance.h"
|
||||||
#include "format.h"
|
|
||||||
#include "valexpr.h"
|
#include "valexpr.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -30,40 +29,6 @@ class item_predicate
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void add_to_balance_pair(balance_pair_t& balance,
|
|
||||||
transaction_t * xact,
|
|
||||||
const bool inverted = false)
|
|
||||||
{
|
|
||||||
if (inverted) {
|
|
||||||
balance.quantity += - xact->amount;
|
|
||||||
balance.cost += - xact->cost;
|
|
||||||
} else {
|
|
||||||
balance += *xact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class format_transaction
|
|
||||||
{
|
|
||||||
std::ostream& output_stream;
|
|
||||||
const format_t& first_line_format;
|
|
||||||
const format_t& next_lines_format;
|
|
||||||
const bool inverted;
|
|
||||||
unsigned int index;
|
|
||||||
entry_t * last_entry;
|
|
||||||
|
|
||||||
public:
|
|
||||||
format_transaction(std::ostream& _output_stream,
|
|
||||||
const format_t& _first_line_format,
|
|
||||||
const format_t& _next_lines_format,
|
|
||||||
const bool _inverted)
|
|
||||||
: output_stream(_output_stream),
|
|
||||||
first_line_format(_first_line_format),
|
|
||||||
next_lines_format(_next_lines_format),
|
|
||||||
inverted(_inverted), index(0), last_entry(NULL) {}
|
|
||||||
|
|
||||||
void operator()(transaction_t * xact);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct compare_items {
|
struct compare_items {
|
||||||
const node_t * sort_order;
|
const node_t * sort_order;
|
||||||
|
|
@ -205,19 +170,6 @@ void walk_transactions(transactions_deque::iterator begin,
|
||||||
functor(*i);
|
functor(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
class format_account
|
|
||||||
{
|
|
||||||
std::ostream& output_stream;
|
|
||||||
const format_t& format;
|
|
||||||
const account_t * last_account;
|
|
||||||
|
|
||||||
public:
|
|
||||||
format_account(std::ostream& _output_stream, const format_t& _format)
|
|
||||||
: output_stream(_output_stream), format(_format) {}
|
|
||||||
|
|
||||||
void operator()(const account_t * account, bool report_top = false);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::deque<account_t *> accounts_deque;
|
typedef std::deque<account_t *> accounts_deque;
|
||||||
|
|
||||||
inline void sort_accounts(account_t * account,
|
inline void sort_accounts(account_t * account,
|
||||||
|
|
@ -234,25 +186,29 @@ inline void sort_accounts(account_t * account,
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
void walk__accounts(const account_t * account, Function functor,
|
void walk__accounts(const account_t * account,
|
||||||
|
Function functor,
|
||||||
|
const unsigned int max_depth,
|
||||||
item_predicate<account_t>& disp_pred_functor)
|
item_predicate<account_t>& disp_pred_functor)
|
||||||
{
|
{
|
||||||
if (disp_pred_functor(account))
|
if (disp_pred_functor(account))
|
||||||
functor(account);
|
functor(account, max_depth);
|
||||||
|
|
||||||
for (accounts_map::const_iterator i = account->accounts.begin();
|
for (accounts_map::const_iterator i = account->accounts.begin();
|
||||||
i != account->accounts.end();
|
i != account->accounts.end();
|
||||||
i++)
|
i++)
|
||||||
walk__accounts((*i).second, functor, disp_pred_functor);
|
walk__accounts((*i).second, functor, max_depth, disp_pred_functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
void walk__accounts_sorted(const account_t * account, Function functor,
|
void walk__accounts_sorted(const account_t * account,
|
||||||
const node_t * sort_order,
|
Function functor,
|
||||||
|
const unsigned int max_depth,
|
||||||
|
const node_t * sort_order,
|
||||||
item_predicate<account_t>& disp_pred_functor)
|
item_predicate<account_t>& disp_pred_functor)
|
||||||
{
|
{
|
||||||
if (disp_pred_functor(account))
|
if (disp_pred_functor(account))
|
||||||
functor(account);
|
functor(account, max_depth);
|
||||||
|
|
||||||
accounts_deque accounts;
|
accounts_deque accounts;
|
||||||
|
|
||||||
|
|
@ -267,7 +223,8 @@ void walk__accounts_sorted(const account_t * account, Function functor,
|
||||||
for (accounts_deque::const_iterator i = accounts.begin();
|
for (accounts_deque::const_iterator i = accounts.begin();
|
||||||
i != accounts.end();
|
i != accounts.end();
|
||||||
i++)
|
i++)
|
||||||
walk__accounts_sorted(*i, functor, sort_order, disp_pred_functor);
|
walk__accounts_sorted(*i, functor, max_depth, sort_order,
|
||||||
|
disp_pred_functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
|
|
@ -297,13 +254,14 @@ inline void sum__accounts(account_t * account)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
void walk_accounts(account_t * account,
|
void walk_accounts(account_t * account,
|
||||||
Function functor,
|
Function functor,
|
||||||
const node_t * predicate,
|
const node_t * predicate,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const bool calc_subtotals,
|
const bool calc_subtotals,
|
||||||
const node_t * display_predicate = NULL,
|
const unsigned int max_depth,
|
||||||
const node_t * sort_order = NULL)
|
const node_t * display_predicate = NULL,
|
||||||
|
const node_t * sort_order = NULL)
|
||||||
{
|
{
|
||||||
item_predicate<transaction_t> pred_functor(predicate);
|
item_predicate<transaction_t> pred_functor(predicate);
|
||||||
item_predicate<account_t> disp_pred_functor(display_predicate);
|
item_predicate<account_t> disp_pred_functor(display_predicate);
|
||||||
|
|
@ -313,10 +271,10 @@ void walk_accounts(account_t * account,
|
||||||
sum__accounts(account);
|
sum__accounts(account);
|
||||||
|
|
||||||
if (sort_order)
|
if (sort_order)
|
||||||
walk__accounts_sorted<Function>(account, functor, sort_order,
|
walk__accounts_sorted<Function>(account, functor, max_depth, sort_order,
|
||||||
disp_pred_functor);
|
disp_pred_functor);
|
||||||
else
|
else
|
||||||
walk__accounts<Function>(account, functor, disp_pred_functor);
|
walk__accounts<Function>(account, functor, max_depth, disp_pred_functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue