summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjohannes@debussy <johannes@debussy>2013-11-05 14:56:13 +0100
committerjohannes@debussy <johannes@debussy>2013-11-05 14:56:13 +0100
commit71f1adad647d5ec4f2e69970543758d7f49f1340 (patch)
tree0dfe887b2bc7b6406755852059ea9c7a7c463c3a /src
parent973659d9a1f8679ab67144660915cad015ea633a (diff)
downloadfork-ledger-71f1adad647d5ec4f2e69970543758d7f49f1340.tar.gz
fork-ledger-71f1adad647d5ec4f2e69970543758d7f49f1340.tar.bz2
fork-ledger-71f1adad647d5ec4f2e69970543758d7f49f1340.zip
first try for implementing --depth for register
Diffstat (limited to 'src')
-rw-r--r--src/filters.cc32
-rw-r--r--src/filters.h32
2 files changed, 39 insertions, 25 deletions
diff --git a/src/filters.cc b/src/filters.cc
index fadd5b5a..02f0e79b 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -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
diff --git a/src/filters.h b/src/filters.h
index f256707b..f05ddaa1 100644
--- a/src/filters.h
+++ b/src/filters.h
@@ -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();