diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-26 18:52:26 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-26 18:52:26 -0400 |
commit | 151a8d87ee299b54da262346471aa71a729a6eb2 (patch) | |
tree | e2151c34eb1a2756e5e4324465ebf629ef4859e6 /src/iterators.cc | |
parent | d85a415bc5119d4271ca7355fe3e0ce3951c0d23 (diff) | |
download | fork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.tar.gz fork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.tar.bz2 fork-ledger-151a8d87ee299b54da262346471aa71a729a6eb2.zip |
Fixed sorting in bal reports when --flat is used
Note that sorting on the "total" is not the same thing as sorting on the
"display_total" when multiple commodities are in use and the -X flag is
selected! One should always sort on display_total, since that's the
value which is shown in the report. 'T' is a synonym for display_total.
Diffstat (limited to 'src/iterators.cc')
-rw-r--r-- | src/iterators.cc | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/iterators.cc b/src/iterators.cc index 63cbb9b2..020f70b0 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -173,46 +173,22 @@ account_t * basic_accounts_iterator::operator()() return account; } -void sorted_accounts_iterator::sort_accounts(account_t& account, - accounts_deque_t& deque) -{ - foreach (accounts_map::value_type& pair, account.accounts) - deque.push_back(pair.second); - - std::stable_sort(deque.begin(), deque.end(), - compare_items<account_t>(sort_cmp)); - -#if defined(DEBUG_ON) - if (SHOW_DEBUG("accounts.sorted")) { - foreach (account_t * account, deque) - DEBUG("accounts.sorted", "Account: " << account->fullname()); - } -#endif -} - -void sorted_accounts_iterator::push_all(account_t& account) -{ - accounts_deque_t& deque(accounts_list.back()); - - foreach (accounts_map::value_type& pair, account.accounts) { - deque.push_back(pair.second); - push_all(*pair.second); - } -} - void sorted_accounts_iterator::push_back(account_t& account) { accounts_list.push_back(accounts_deque_t()); if (flatten_all) { - push_all(account); + push_all(account, accounts_list.back()); + std::stable_sort(accounts_list.back().begin(), accounts_list.back().end(), compare_items<account_t>(sort_cmp)); + #if defined(DEBUG_ON) if (SHOW_DEBUG("accounts.sorted")) { foreach (account_t * account, accounts_list.back()) - DEBUG("accounts.sorted", "Account: " << account->fullname()); + DEBUG("accounts.sorted", + "Account (flat): " << account->fullname()); } #endif } else { @@ -223,6 +199,32 @@ void sorted_accounts_iterator::push_back(account_t& account) sorted_accounts_end.push_back(accounts_list.back().end()); } +void sorted_accounts_iterator::push_all(account_t& account, + accounts_deque_t& deque) +{ + foreach (accounts_map::value_type& pair, account.accounts) { + deque.push_back(pair.second); + push_all(*pair.second, deque); + } +} + +void sorted_accounts_iterator::sort_accounts(account_t& account, + accounts_deque_t& deque) +{ + foreach (accounts_map::value_type& pair, account.accounts) + deque.push_back(pair.second); + + std::stable_sort(deque.begin(), deque.end(), + compare_items<account_t>(sort_cmp)); + +#if defined(DEBUG_ON) + if (SHOW_DEBUG("accounts.sorted")) { + foreach (account_t * account, deque) + DEBUG("accounts.sorted", "Account: " << account->fullname()); + } +#endif +} + account_t * sorted_accounts_iterator::operator()() { while (! sorted_accounts_i.empty() && |