*** empty log message ***
This commit is contained in:
parent
8f373c049c
commit
4ca26fbd73
4 changed files with 56 additions and 6 deletions
|
|
@ -168,7 +168,7 @@ void config_t::process_options(const std::string& command,
|
|||
|
||||
// Process remaining command-line arguments
|
||||
|
||||
if (command != "e" && command != "w") {
|
||||
if (command != "e" && command != "w" && command != "R") {
|
||||
// Treat the remaining command-line arguments as regular
|
||||
// expressions, used for refining report results.
|
||||
|
||||
|
|
|
|||
11
main.cc
11
main.cc
|
|
@ -374,8 +374,15 @@ def vmax(d, val):\n\
|
|||
walk_transactions(new_entry->transactions, *formatter);
|
||||
else if (command == "P" || command == "D")
|
||||
walk_commodities(commodity_t::commodities, *formatter);
|
||||
else if (command == "R")
|
||||
reconcile_account(*journal, *journal->master, value_t(long(0)));
|
||||
else if (command == "R") {
|
||||
account_t * account = journal->find_account_re(*arg);
|
||||
if (! account)
|
||||
throw error(std::string("Could not find account matching '") +
|
||||
*arg + "'");
|
||||
reconcile_results_t results = reconcile_account(*journal, *account,
|
||||
value_t(*++arg));
|
||||
walk_transactions(results.pending_xacts, *formatter);
|
||||
}
|
||||
else if (command == "w")
|
||||
write_textual_journal(*journal, *arg, *formatter, *out);
|
||||
else
|
||||
|
|
|
|||
48
reconcile.cc
48
reconcile.cc
|
|
@ -2,6 +2,27 @@
|
|||
|
||||
namespace ledger {
|
||||
|
||||
unsigned long called = 0;
|
||||
bool search_for_balance(const value_t& balance,
|
||||
const value_t& amount,
|
||||
transactions_list::iterator beg,
|
||||
transactions_list::iterator end)
|
||||
{
|
||||
called++;
|
||||
if (balance == amount)
|
||||
return true;
|
||||
|
||||
for (transactions_list::iterator i = beg; i != end; ) {
|
||||
transactions_list::iterator x = i;
|
||||
(*x)->data = (void *)true;
|
||||
if (search_for_balance(balance, amount + (*x)->amount, ++i, end))
|
||||
return true;
|
||||
(*x)->data = NULL;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
reconcile_results_t reconcile_account(journal_t& journal,
|
||||
account_t& account,
|
||||
const value_t& balance)
|
||||
|
|
@ -53,17 +74,38 @@ reconcile_results_t reconcile_account(journal_t& journal,
|
|||
|
||||
results.previous_balance = cleared_balance;
|
||||
|
||||
value_t to_reconcile = balance - cleared_balance;
|
||||
|
||||
// If the amount to reconcile is the same as the pending balance,
|
||||
// then assume an exact match and return the results right away.
|
||||
value_t to_reconcile = balance - cleared_balance;
|
||||
if (to_reconcile == pending_balance) {
|
||||
results.remaining_balance = 0L;
|
||||
results.pending_balance = pending_balance;
|
||||
results.pending_xacts = pending_xacts;
|
||||
return results;
|
||||
}
|
||||
|
||||
throw error("Could not reconcile account");
|
||||
if (search_for_balance(to_reconcile, value_t(),
|
||||
pending_xacts.begin(), pending_xacts.end())) {
|
||||
results.remaining_balance = pending_balance - to_reconcile;
|
||||
results.pending_balance = to_reconcile;
|
||||
|
||||
for (transactions_list::iterator i = pending_xacts.begin();
|
||||
i != pending_xacts.end();
|
||||
i++)
|
||||
if ((*i)->data) {
|
||||
(*i)->data = NULL;
|
||||
results.pending_xacts.push_back(*i);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// At this point we have an uncleared amount X, and a known desired
|
||||
// amount of Y. X != Y because not all of the transactions in
|
||||
// `pending_xacts' are desired, or some are missing, or both. In
|
||||
// the case that none are missing, we now attempt a permutative
|
||||
// search to discover which should be removed to yield the amount Y.
|
||||
|
||||
throw error("Could not reconcile account!");
|
||||
}
|
||||
|
||||
} // namespace ledger
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace ledger {
|
|||
struct reconcile_results_t
|
||||
{
|
||||
value_t previous_balance;
|
||||
value_t pending_balance;
|
||||
value_t remaining_balance;
|
||||
|
||||
transactions_list pending_xacts;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue