first try for implementing --depth for register
This commit is contained in:
parent
973659d9a1
commit
71f1adad64
2 changed files with 39 additions and 25 deletions
|
|
@ -449,13 +449,16 @@ void collapse_posts::report_subtotal()
|
|||
DEBUG("filters.collapse", "earliest date = " << earliest_date);
|
||||
DEBUG("filters.collapse", "latest date = " << latest_date);
|
||||
|
||||
handle_value(/* value= */ subtotal,
|
||||
/* account= */ totals_account,
|
||||
/* xact= */ &xact,
|
||||
/* temps= */ temps,
|
||||
/* handler= */ handler,
|
||||
/* date= */ latest_date,
|
||||
/* act_date_p= */ false);
|
||||
foreach (post_t * post, component_posts) {
|
||||
handle_value(/* value= */ subtotal,
|
||||
/* account= */ find_totals_account(post->account),
|
||||
/* xact= */ &xact,
|
||||
/* temps= */ temps,
|
||||
/* handler= */ handler,
|
||||
/* date= */ latest_date,
|
||||
/* act_date_p= */ false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
component_posts.clear();
|
||||
|
|
@ -466,6 +469,21 @@ void collapse_posts::report_subtotal()
|
|||
count = 0;
|
||||
}
|
||||
|
||||
account_t* collapse_posts::find_totals_account(account_t* account)
|
||||
{
|
||||
unsigned short depth=2;
|
||||
if(account->depth==depth)
|
||||
{
|
||||
string name=account->fullname();
|
||||
account_t*& acc = totals_accounts[name];
|
||||
if(acc==NULL)
|
||||
acc= &temps.create_account(name);
|
||||
return acc;
|
||||
}
|
||||
//recurse
|
||||
return find_totals_account(account->parent);
|
||||
}
|
||||
|
||||
void collapse_posts::operator()(post_t& post)
|
||||
{
|
||||
// If we've reached a new xact, report on the subtotal
|
||||
|
|
|
|||
|
|
@ -421,18 +421,18 @@ public:
|
|||
|
||||
class collapse_posts : public item_handler<post_t>
|
||||
{
|
||||
expr_t& amount_expr;
|
||||
predicate_t display_predicate;
|
||||
predicate_t only_predicate;
|
||||
value_t subtotal;
|
||||
std::size_t count;
|
||||
xact_t * last_xact;
|
||||
post_t * last_post;
|
||||
temporaries_t temps;
|
||||
account_t * totals_account;
|
||||
bool only_collapse_if_zero;
|
||||
std::list<post_t *> component_posts;
|
||||
report_t& report;
|
||||
expr_t& amount_expr;
|
||||
predicate_t display_predicate;
|
||||
predicate_t only_predicate;
|
||||
value_t subtotal;
|
||||
std::size_t count;
|
||||
xact_t * last_xact;
|
||||
post_t * last_post;
|
||||
temporaries_t temps;
|
||||
std::map<string,account_t *> totals_accounts;
|
||||
bool only_collapse_if_zero;
|
||||
std::list<post_t *> component_posts;
|
||||
report_t& report;
|
||||
|
||||
collapse_posts();
|
||||
|
||||
|
|
@ -448,17 +448,13 @@ public:
|
|||
only_predicate(_only_predicate), count(0),
|
||||
last_xact(NULL), last_post(NULL),
|
||||
only_collapse_if_zero(_only_collapse_if_zero), report(_report) {
|
||||
create_accounts();
|
||||
TRACE_CTOR(collapse_posts, "post_handler_ptr, ...");
|
||||
}
|
||||
virtual ~collapse_posts() {
|
||||
TRACE_DTOR(collapse_posts);
|
||||
handler.reset();
|
||||
}
|
||||
|
||||
void create_accounts() {
|
||||
totals_account = &temps.create_account(_("<Total>"));
|
||||
}
|
||||
account_t* find_totals_account(account_t* account);
|
||||
|
||||
virtual void flush() {
|
||||
report_subtotal();
|
||||
|
|
@ -480,7 +476,7 @@ public:
|
|||
last_post = NULL;
|
||||
|
||||
temps.clear();
|
||||
create_accounts();
|
||||
totals_accounts.clear();
|
||||
component_posts.clear();
|
||||
|
||||
item_handler<post_t>::clear();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue