Add XMLImportEngine
Fix some bugs in ImportPanel and ImportEngines
This commit is contained in:
@@ -150,8 +150,6 @@ void ImportPanel::OnFileEnter(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void ImportPanel::ProcessFile()
|
||||
{
|
||||
std::vector<Account> accounts;
|
||||
std::vector<Category> categories;
|
||||
User* user = _kiss->GetUser();
|
||||
int i;
|
||||
wxGridCellChoiceEditor* accountEditor;
|
||||
@@ -179,9 +177,9 @@ void ImportPanel::ProcessFile()
|
||||
return ;
|
||||
}
|
||||
|
||||
_importEngine->ParseFile(accounts, categories);
|
||||
_importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories);
|
||||
|
||||
if (accounts.size())
|
||||
if (_unresolvedAccounts.size())
|
||||
{
|
||||
int nb_accounts = user->GetAccountsNumber();
|
||||
userAccounts = new wxString[nb_accounts+1];
|
||||
@@ -195,13 +193,13 @@ void ImportPanel::ProcessFile()
|
||||
|
||||
_buttonLoadOperations->Enable();
|
||||
|
||||
_accountsGrid->AppendRows(accounts.size());
|
||||
_accountsGrid->AppendRows(_unresolvedAccounts.size());
|
||||
|
||||
for (i=0; i<(int)accounts.size(); i++)
|
||||
for (i=0; i<(int)_unresolvedAccounts.size(); i++)
|
||||
{
|
||||
_accountsGrid->SetCellValue(i, 0, accounts[i].number);
|
||||
_accountsGrid->SetCellValue(i, 0, _unresolvedAccounts[i].number);
|
||||
_accountsGrid->SetReadOnly(i, 0);
|
||||
_accountsGrid->SetCellValue(i, 1, accounts[i].name);
|
||||
_accountsGrid->SetCellValue(i, 1, _unresolvedAccounts[i].name);
|
||||
_accountsGrid->SetCellValue(i, 2, userAccounts[0]);
|
||||
|
||||
_accountsGrid->SetCellEditor(i, 2, accountEditor);
|
||||
@@ -211,7 +209,7 @@ void ImportPanel::ProcessFile()
|
||||
_accountsGrid->Layout();
|
||||
}
|
||||
|
||||
if (categories.size())
|
||||
if (_unresolvedCategories.size())
|
||||
{
|
||||
int nb_categories = user->GetCategoriesNumber();
|
||||
userCategories = new wxString[nb_categories+1];
|
||||
@@ -225,11 +223,11 @@ void ImportPanel::ProcessFile()
|
||||
|
||||
_buttonLoadOperations->Enable();
|
||||
|
||||
_categoriesGrid->AppendRows(categories.size());
|
||||
_categoriesGrid->AppendRows(_unresolvedCategories.size());
|
||||
|
||||
for (i=0; i<(int)categories.size(); i++)
|
||||
for (i=0; i<(int)_unresolvedCategories.size(); i++)
|
||||
{
|
||||
_categoriesGrid->SetCellValue(i, 0, categories[i].name);
|
||||
_categoriesGrid->SetCellValue(i, 0, _unresolvedCategories[i].name);
|
||||
_categoriesGrid->SetReadOnly(i, 0);
|
||||
_categoriesGrid->SetCellValue(i, 2, userCategories[0]);
|
||||
|
||||
@@ -240,7 +238,7 @@ void ImportPanel::ProcessFile()
|
||||
_categoriesGrid->Layout();
|
||||
}
|
||||
|
||||
if (!accounts.size() && !categories.size())
|
||||
if (!_unresolvedAccounts.size() && !_unresolvedCategories.size())
|
||||
{
|
||||
OnLoadOperations(event);
|
||||
}
|
||||
@@ -249,19 +247,20 @@ void ImportPanel::ProcessFile()
|
||||
|
||||
void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
std::map<wxString, wxString> resolvedAccounts;
|
||||
std::map<wxString, wxString> resolvedCategories;
|
||||
int i, nbAccounts=0, nbCategories=0;
|
||||
User* user = _kiss->GetUser();
|
||||
Account account;
|
||||
Category category;
|
||||
std::map<wxString, wxString> accounts;
|
||||
std::map<wxString, wxString> categories;
|
||||
wxString oldid;
|
||||
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
if (_accountsGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
nbAccounts++;
|
||||
else
|
||||
resolvedAccounts[_accountsGrid->GetCellValue(i, 0)] =
|
||||
accounts[_accountsGrid->GetCellValue(i, 0)] =
|
||||
user->GetAccountId(_accountsGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
@@ -270,7 +269,7 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
nbCategories++;
|
||||
else
|
||||
resolvedCategories[_categoriesGrid->GetCellValue(i, 0)] =
|
||||
categories[_categoriesGrid->GetCellValue(i, 0)] =
|
||||
user->GetAccountId(_categoriesGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
@@ -297,18 +296,15 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if (_accountsGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
{
|
||||
account = _unresolvedAccounts[i] ;
|
||||
if (_accountsGrid->GetCellValue(i, 1).Length())
|
||||
account.name = _accountsGrid->GetCellValue(i, 1);
|
||||
else
|
||||
account.name = _accountsGrid->GetCellValue(i, 0);
|
||||
account.number = _accountsGrid->GetCellValue(i, 0);
|
||||
account.shared = false;
|
||||
account.blocked = false;
|
||||
account._default = false;
|
||||
account.is_owner = true;
|
||||
account._virtual = false;
|
||||
|
||||
resolvedAccounts[_accountsGrid->GetCellValue(i, 0)] = _kiss->AddAccount(account);
|
||||
oldid = account.id;
|
||||
_resolvedAccounts[oldid] = accounts[_accountsGrid->GetCellValue(i, 0)] = _kiss->AddAccount(account);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,16 +314,14 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
{
|
||||
category = _unresolvedCategories[i] ;
|
||||
if (_categoriesGrid->GetCellValue(i, 1).Length())
|
||||
category.name = _categoriesGrid->GetCellValue(i, 1);
|
||||
else
|
||||
category.name = _categoriesGrid->GetCellValue(i, 0);
|
||||
category.parent = wxT("0");
|
||||
category.backcolor = OWN_GREEN ;
|
||||
category.forecolor = *wxBLACK;
|
||||
category.fix_cost = false;
|
||||
|
||||
resolvedCategories[_categoriesGrid->GetCellValue(i, 0)] = category.id = _kiss->AddCategory(category);
|
||||
|
||||
oldid = category.id;
|
||||
_resolvedCategories[oldid] = categories[_categoriesGrid->GetCellValue(i, 0)] = category.id = _kiss->AddCategory(category);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +330,7 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
_operations = _importEngine->GetOperations(resolvedAccounts, resolvedCategories);
|
||||
_operations = _importEngine->GetOperations(accounts, categories);
|
||||
|
||||
if (_operations->size())
|
||||
{
|
||||
@@ -361,6 +355,12 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
void ImportPanel::OnIntegrate(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
int i;
|
||||
std::map<wxString, wxString> mapid;
|
||||
wxString oldid, account;
|
||||
bool update;
|
||||
std::map<AccountAmount, double, AccountAmount> accountAmounts;
|
||||
std::map<AccountAmount, double, AccountAmount>::iterator it;
|
||||
double amount;
|
||||
|
||||
if (!_operations->size()) return;
|
||||
|
||||
@@ -371,9 +371,48 @@ void ImportPanel::OnIntegrate(wxCommandEvent& WXUNUSED(event))
|
||||
_buttonIntegrate->Disable();
|
||||
|
||||
for(i=0; i<(int)_operations->size(); i++)
|
||||
_kiss->AddOperation((*_operations)[i]);
|
||||
{
|
||||
oldid = (*_operations)[i].id;
|
||||
_kiss->AddOperation((*_operations)[i], false);
|
||||
mapid[oldid] = (*_operations)[i].id;
|
||||
}
|
||||
|
||||
// if (_checkSaveImportPatterns->IsChecked())
|
||||
for(i=0; i<(int)_operations->size(); i++)
|
||||
{
|
||||
update = false;
|
||||
|
||||
if ((*_operations)[i].parent.Length())
|
||||
{
|
||||
(*_operations)[i].parent = mapid[(*_operations)[i].parent];
|
||||
update = true;
|
||||
}
|
||||
|
||||
if ((*_operations)[i].transfert.Length())
|
||||
{
|
||||
(*_operations)[i].transfert = mapid[(*_operations)[i].transfert];
|
||||
update = true;
|
||||
}
|
||||
|
||||
if (update)
|
||||
_kiss->UpdateOperation((*_operations)[i], false);
|
||||
}
|
||||
|
||||
accountAmounts = _importEngine->GetAccountAmounts();
|
||||
|
||||
for(it=accountAmounts.begin(); it!=accountAmounts.end(); it++)
|
||||
{
|
||||
account = it->first.account;
|
||||
|
||||
if (_resolvedAccounts.count(account))
|
||||
account = _resolvedAccounts[account];
|
||||
|
||||
amount = _kiss->GetAccountAmount(account, it->first.month, it->first.year);
|
||||
|
||||
if (!amount)
|
||||
_kiss->SetAccountAmount(account, it->first.month, it->first.year, it->second);
|
||||
}
|
||||
|
||||
if (_checkSaveImportPatterns->IsChecked())
|
||||
_kiss->UpdateImportPattern();
|
||||
|
||||
_operations->clear();
|
||||
|
Reference in New Issue
Block a user