Functionnal version of ImportPanel
This commit is contained in:
@@ -83,7 +83,7 @@ std::vector<wxString> ExplodeString(wxString& s)
|
||||
- tail spaces
|
||||
- every word starting by a number
|
||||
*/
|
||||
wxString ImportEngine::RemoveUnused(wxString& s)
|
||||
wxString ImportEngine::RemoveUnused(const wxString& s)
|
||||
{
|
||||
wxString tmp = s, tmp2;
|
||||
wxString res;
|
||||
@@ -124,9 +124,16 @@ wxString ImportEngine::FindPattern(wxString& orig, wxString& dest)
|
||||
{
|
||||
wxString pattern, cur_pat;
|
||||
int i, a;
|
||||
std::vector<wxString> tok1 = ExplodeString(orig);
|
||||
std::vector<wxString> tok2 = ExplodeString(dest);
|
||||
int size1 = tok1.size(), size2 = tok2.size();
|
||||
std::vector<wxString> tok1;
|
||||
std::vector<wxString> tok2;
|
||||
int size1, size2;
|
||||
|
||||
if (orig == dest) return NULL_IMPORT_PATTERN;
|
||||
|
||||
tok1 = ExplodeString(orig);
|
||||
tok2 = ExplodeString(dest);
|
||||
size1 = tok1.size();
|
||||
size2 = tok2.size();
|
||||
|
||||
for(i=0; i<size2; i++)
|
||||
{
|
||||
@@ -171,11 +178,20 @@ wxString ImportEngine::FindPattern(wxString& orig, wxString& dest)
|
||||
|
||||
void ImportEngine::ApplyPattern(ImportPattern& pattern, Operation& op)
|
||||
{
|
||||
std::vector<wxString> tok1 = ExplodeString(pattern.filter);
|
||||
std::vector<wxString> tok2 = ExplodeString(op.description);
|
||||
int size1 = tok1.size(), i;
|
||||
std::vector<wxString> tok1;
|
||||
std::vector<wxString> tok2;
|
||||
int size1, i;
|
||||
long pos;
|
||||
|
||||
op.account = pattern.account;
|
||||
op.category = pattern.category;
|
||||
|
||||
if (pattern.pattern == NULL_IMPORT_PATTERN) return;
|
||||
|
||||
tok1 = ExplodeString(pattern.pattern);
|
||||
tok2 = ExplodeString(op.description);
|
||||
size1 = tok1.size();
|
||||
|
||||
op.description = wxT("");
|
||||
|
||||
for(i=0; i<size1; i++)
|
||||
@@ -203,8 +219,6 @@ void ImportEngine::ApplyPattern(ImportPattern& pattern, Operation& op)
|
||||
}
|
||||
|
||||
op.description.Trim();
|
||||
op.account = pattern.account;
|
||||
op.category = pattern.category;
|
||||
}
|
||||
|
||||
int ImportEngine::UpdatePattern(int pos)
|
||||
@@ -222,7 +236,7 @@ int ImportEngine::UpdatePattern(int pos)
|
||||
|
||||
key1 = RemoveUnused(_descriptions[op.id]);
|
||||
|
||||
pattern.filter = FindPattern(_descriptions[op.id], op.description);
|
||||
pattern.pattern = FindPattern(_descriptions[op.id], op.description);
|
||||
pattern.account = op.account;
|
||||
pattern.category = op.category;
|
||||
|
||||
@@ -253,13 +267,13 @@ void ImportEngine::MatchPattern(wxString& originalKey, Operation& op)
|
||||
|
||||
if (!_user->_importPatterns.count(key1))
|
||||
{
|
||||
pattern.filter = FindPattern(originalKey, op.description);
|
||||
pattern.pattern = FindPattern(originalKey, op.description);
|
||||
pattern.account = op.account;
|
||||
pattern.category = op.category;
|
||||
|
||||
_user->_importPatterns[key1] = pattern;
|
||||
|
||||
// std::cout << "New pattern " << key1.mb_str() << "\t" << pattern.filter.mb_str() << std::endl;
|
||||
// std::cout << "New pattern " << key1.mb_str() << "\t" << pattern.pattern.mb_str() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -267,3 +281,26 @@ void ImportEngine::MatchPattern(wxString& originalKey, Operation& op)
|
||||
ApplyPattern(_user->_importPatterns[key1], op);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<wxString> ImportEngine::ParseFile()
|
||||
{
|
||||
return _unresolvedAccounts;
|
||||
}
|
||||
|
||||
std::vector<Operation>* ImportEngine::GetOperations(std::map<wxString, wxString>& accounts)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<(int)_operations.size(); i++)
|
||||
{
|
||||
if (_operations[i].account.StartsWith(wxT("unknown-")))
|
||||
_operations[i].account = accounts[_operations[i].account.Mid(8)];
|
||||
}
|
||||
|
||||
if (_kiss->GetOperationOrder() == wxT("ASC"))
|
||||
std::sort(_operations.begin(), _operations.end(), sortOperations);
|
||||
else
|
||||
std::sort(_operations.begin(), _operations.end(), reverseSortOperations);
|
||||
|
||||
return &_operations;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,13 @@ class KissCount;
|
||||
|
||||
class ImportPattern {
|
||||
public:
|
||||
wxString filter;
|
||||
wxString pattern;
|
||||
wxString account;
|
||||
wxString category;
|
||||
} ;
|
||||
|
||||
#define NULL_IMPORT_PATTERN wxT("(nil)")
|
||||
|
||||
class ImportEngine {
|
||||
public:
|
||||
ImportEngine();
|
||||
@@ -42,17 +44,18 @@ public:
|
||||
virtual wxString GetFileExt();
|
||||
|
||||
// Handle the file
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss);
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)=0;
|
||||
|
||||
// Parse the file and return accounts that doesn't match
|
||||
virtual std::vector<wxString> ParseFile()=0;
|
||||
virtual std::vector<wxString> ParseFile();
|
||||
|
||||
// Final Step
|
||||
virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts)=0;
|
||||
virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts);
|
||||
|
||||
void MatchPattern(wxString& key, Operation& op);
|
||||
int UpdatePattern(int pos);
|
||||
|
||||
static wxString RemoveUnused(const wxString& s);
|
||||
protected:
|
||||
Database* _db;
|
||||
User* _user;
|
||||
@@ -67,7 +70,6 @@ protected:
|
||||
std::vector<Operation> _operations;
|
||||
std::map<wxString, wxString> _descriptions;
|
||||
|
||||
wxString RemoveUnused(wxString& s);
|
||||
void ApplyPattern(ImportPattern& pattern, Operation& op);
|
||||
wxString FindPattern(wxString& s1, wxString& s2);
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ int OFXImportEngine::account_cb(const struct OfxAccountData data, void * account
|
||||
|
||||
if (!_this->_curAccount.Len())
|
||||
{
|
||||
_this->_accounts[account_number] = wxT("unknown-") + account_number;
|
||||
_this->_curAccount = _this->_accounts[account_number] = wxT("unknown-") + account_number;
|
||||
_this->_unresolvedAccounts.push_back(account_number);
|
||||
}
|
||||
|
||||
@@ -136,18 +136,3 @@ bool OFXImportEngine::HandleFile(const wxString& path, User* user, Database* db,
|
||||
|
||||
return !libofx_proc_file(_ctx, path.mb_str(), AUTODETECT);
|
||||
}
|
||||
|
||||
std::vector<wxString> OFXImportEngine::ParseFile()
|
||||
{
|
||||
return _unresolvedAccounts;
|
||||
}
|
||||
|
||||
std::vector<Operation>* OFXImportEngine::GetOperations(std::map<wxString, wxString>& accounts)
|
||||
{
|
||||
if (_kiss->GetOperationOrder() == wxT("ASC"))
|
||||
std::sort(_operations.begin(), _operations.end(), sortOperations);
|
||||
else
|
||||
std::sort(_operations.begin(), _operations.end(), reverseSortOperations);
|
||||
|
||||
return &_operations;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ public:
|
||||
~OFXImportEngine();
|
||||
|
||||
virtual bool HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss);
|
||||
virtual std::vector<wxString> ParseFile();
|
||||
virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts);
|
||||
/* virtual std::vector<wxString> ParseFile(); */
|
||||
/* virtual std::vector<Operation>* GetOperations(std::map<wxString, wxString>& accounts); */
|
||||
|
||||
private:
|
||||
LibofxContextPtr _ctx;
|
||||
|
||||
Reference in New Issue
Block a user