From 1bf0220f246c5e984d9a43e5d8b3979b9091bc5a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 7 Mar 2010 22:53:57 -0500 Subject: Added experimental account lookup logic This is used by the "xact" command, and the CSV importer. It is very slow O(xacts*records). --- src/draft.cc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/draft.cc') diff --git a/src/draft.cc b/src/draft.cc index 74e17dba..89c68541 100644 --- a/src/draft.cc +++ b/src/draft.cc @@ -38,6 +38,7 @@ #include "journal.h" #include "session.h" #include "report.h" +#include "lookup.h" #include "print.h" namespace ledger { @@ -242,18 +243,25 @@ xact_t * draft_t::insert(journal_t& journal) if (tmpl->payee_mask.empty()) throw std::runtime_error(_("xact' command requires at least a payee")); - xact_t * matching = NULL; + xact_t * matching = NULL; std::auto_ptr added(new xact_t); - for (xacts_list::reverse_iterator j = journal.xacts.rbegin(); - j != journal.xacts.rend(); - j++) { - if (tmpl->payee_mask.match((*j)->payee)) { - matching = *j; - DEBUG("derive.xact", - "Found payee match: transaction on line " << (*j)->pos->beg_line); - break; + xacts_iterator xi(journal); + if (xact_t * xact = lookup_probable_account(tmpl->payee_mask.str(), xi).first) { + DEBUG("derive.xact", "Found payee by lookup: transaction on line " + << xact->pos->beg_line); + matching = xact; + } else { + for (xacts_list::reverse_iterator j = journal.xacts.rbegin(); + j != journal.xacts.rend(); + j++) { + if (tmpl->payee_mask.match((*j)->payee)) { + matching = *j; + DEBUG("derive.xact", + "Found payee match: transaction on line " << (*j)->pos->beg_line); + break; + } } } -- cgit v1.2.3