Add unresolved categories in ImportPanel
Fix two bugs : Don't take in account unknown categories (in stats) Don't try to draw more than MAX_CATEGORIES (12) in charts
This commit is contained in:
@@ -33,12 +33,14 @@ END_EVENT_TABLE()
|
||||
ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent)
|
||||
{
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
_hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxButton* buttonOpen;
|
||||
wxRect rect = wxDisplay().GetGeometry();
|
||||
int w, h;
|
||||
wxStaticBox* staticAccount = new wxStaticBox(this, wxID_ANY, _("Unresolved accounts"));
|
||||
wxStaticBox* staticCategory = new wxStaticBox(this, wxID_ANY, _("Unresolved categories"));
|
||||
|
||||
SetSizer(vbox);
|
||||
|
||||
@@ -73,12 +75,25 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
_accountsGrid->SetColLabelValue(2, _("Internal account"));
|
||||
_accountsGrid->Fit();
|
||||
|
||||
_categoriesGrid = new wxGrid(this, wxID_ANY);
|
||||
_categoriesGrid->CreateGrid(0, 3);
|
||||
_categoriesGrid->SetRowLabelSize(0);
|
||||
_categoriesGrid->SetColLabelValue(0, _("File category"));
|
||||
_categoriesGrid->SetColLabelValue(1, _("Category name"));
|
||||
_categoriesGrid->SetColLabelValue(2, _("Internal category"));
|
||||
_categoriesGrid->Fit();
|
||||
|
||||
wxStaticBoxSizer* staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL);
|
||||
staticBoxSizer->Add(_accountsGrid, 0, wxGROW|wxALL, 2);
|
||||
vbox2->Add(staticBoxSizer, wxGROW|wxALL);
|
||||
|
||||
staticBoxSizer = new wxStaticBoxSizer (staticCategory, wxVERTICAL);
|
||||
staticBoxSizer->Add(_categoriesGrid, 0, wxGROW|wxALL, 2);
|
||||
vbox2->Add(staticBoxSizer, wxGROW|wxALL);
|
||||
|
||||
_operationsGrid = new GridAccount(kiss, this, OPS_GRID_ID, false, false, false);
|
||||
|
||||
_hbox->Add(staticBoxSizer, 0, wxGROW|wxALL, 15);
|
||||
_hbox->Add(vbox2, 0, wxGROW|wxALL, 15);
|
||||
_hbox->Add(_operationsGrid, 0, wxGROW|wxALL, 15);
|
||||
|
||||
vbox->Add(_hbox, wxGROW);
|
||||
@@ -136,11 +151,15 @@ 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;
|
||||
wxString* userAccounts;
|
||||
std::map<wxString, wxString> resolvedAccounts;
|
||||
wxGridCellChoiceEditor* categoryEditor;
|
||||
wxString* userCategories;
|
||||
std::map<wxString, wxString> resolvedCategories;
|
||||
wxCommandEvent event;
|
||||
|
||||
wxString path = _fileTxt->GetLineText(0);
|
||||
@@ -148,6 +167,7 @@ void ImportPanel::ProcessFile()
|
||||
_buttonLoadOperations->Disable();
|
||||
_buttonIntegrate->Disable();
|
||||
_accountsGrid->ClearGrid();
|
||||
_categoriesGrid->ClearGrid();
|
||||
_operationsGrid->ClearGrid();
|
||||
|
||||
_importEngine = _kiss->GetImportEngine(path);
|
||||
@@ -159,7 +179,7 @@ void ImportPanel::ProcessFile()
|
||||
return ;
|
||||
}
|
||||
|
||||
accounts = _importEngine->ParseFile();
|
||||
_importEngine->ParseFile(accounts, categories);
|
||||
|
||||
if (accounts.size())
|
||||
{
|
||||
@@ -190,7 +210,37 @@ void ImportPanel::ProcessFile()
|
||||
_accountsGrid->AutoSize();
|
||||
_accountsGrid->Layout();
|
||||
}
|
||||
else
|
||||
|
||||
if (categories.size())
|
||||
{
|
||||
int nb_categories = user->GetCategoriesNumber();
|
||||
userCategories = new wxString[nb_categories+1];
|
||||
|
||||
userCategories[0] = _("Create one");
|
||||
|
||||
for(i=0; i<nb_categories; i++)
|
||||
userCategories[i+1] = user->_categories[i].name;
|
||||
|
||||
categoryEditor = new wxGridCellChoiceEditor(nb_categories+1, userCategories, false);
|
||||
|
||||
_buttonLoadOperations->Enable();
|
||||
|
||||
_categoriesGrid->AppendRows(categories.size());
|
||||
|
||||
for (i=0; i<(int)categories.size(); i++)
|
||||
{
|
||||
_categoriesGrid->SetCellValue(i, 0, categories[i].name);
|
||||
_categoriesGrid->SetReadOnly(i, 0);
|
||||
_categoriesGrid->SetCellValue(i, 2, userCategories[0]);
|
||||
|
||||
_categoriesGrid->SetCellEditor(i, 2, categoryEditor);
|
||||
}
|
||||
|
||||
_categoriesGrid->AutoSize();
|
||||
_categoriesGrid->Layout();
|
||||
}
|
||||
|
||||
if (!accounts.size() && !categories.size())
|
||||
{
|
||||
OnLoadOperations(event);
|
||||
}
|
||||
@@ -200,27 +250,44 @@ void ImportPanel::ProcessFile()
|
||||
void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
std::map<wxString, wxString> resolvedAccounts;
|
||||
int i, nbAccounts;
|
||||
std::map<wxString, wxString> resolvedCategories;
|
||||
int i, nbAccounts=0, nbCategories=0;
|
||||
User* user = _kiss->GetUser();
|
||||
Account account;
|
||||
Category category;
|
||||
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
resolvedAccounts[_accountsGrid->GetCellValue(i, 0)] =
|
||||
user->GetAccountId(_accountsGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
nbAccounts = 0;
|
||||
for(i=0; i<_accountsGrid->GetNumberRows(); i++)
|
||||
{
|
||||
if (_accountsGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
nbAccounts++;
|
||||
else
|
||||
resolvedAccounts[_accountsGrid->GetCellValue(i, 0)] =
|
||||
user->GetAccountId(_accountsGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
if (nbAccounts)
|
||||
for(i=0; i<_categoriesGrid->GetNumberRows(); i++)
|
||||
{
|
||||
wxString message = wxString::Format(wxT("%d"), nbAccounts);
|
||||
message += _(" account(s) will be created, is it ok ?");
|
||||
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
nbCategories++;
|
||||
else
|
||||
resolvedCategories[_categoriesGrid->GetCellValue(i, 0)] =
|
||||
user->GetAccountId(_categoriesGrid->GetCellValue(i, 1));
|
||||
}
|
||||
|
||||
if (nbAccounts || nbCategories)
|
||||
{
|
||||
wxString message;
|
||||
|
||||
if (nbAccounts)
|
||||
{
|
||||
message += wxString::Format(wxT("%d accounts"), nbAccounts);
|
||||
if (nbCategories) message += wxT(" and ");
|
||||
}
|
||||
|
||||
if (nbCategories)
|
||||
message += wxString::Format(wxT("%d categories"), nbCategories);
|
||||
|
||||
message += _(" will be created, is it ok ?");
|
||||
|
||||
wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
@@ -247,10 +314,29 @@ void ImportPanel::OnLoadOperations(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
_accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows ());
|
||||
|
||||
for(i=0; i<_categoriesGrid->GetNumberRows(); i++)
|
||||
{
|
||||
if (_categoriesGrid->GetCellValue(i, 2) == _("Create one"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
_categoriesGrid->DeleteRows(0, _categoriesGrid->GetNumberRows ());
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
_operations = _importEngine->GetOperations(resolvedAccounts);
|
||||
_operations = _importEngine->GetOperations(resolvedAccounts, resolvedCategories);
|
||||
|
||||
if (_operations->size())
|
||||
{
|
||||
|
Reference in New Issue
Block a user