Possibility to work on multiple operations (rename, change category, change account)
New database version (2) : fix_cost for categories virtual account
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2010 Grégory Soutadé
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
@@ -19,13 +19,17 @@
|
||||
|
||||
#include "AccountPanel.h"
|
||||
|
||||
enum {SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID};
|
||||
enum {SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID,
|
||||
CHANGE_ACCOUNT_ID, CHANGE_CATEGORY_ID, RENAME_ID};
|
||||
|
||||
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
||||
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
||||
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
|
||||
EVT_BUTTON(CHANGE_ACCOUNT_ID, SearchPanel::OnButtonChangeAccount)
|
||||
EVT_BUTTON(CHANGE_CATEGORY_ID, SearchPanel::OnButtonChangeCategory)
|
||||
EVT_BUTTON(RENAME_ID, SearchPanel::OnButtonRename)
|
||||
EVT_SHOW(SearchPanel::OnShow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
@@ -44,6 +48,9 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
wxRect rect = wxDisplay().GetGeometry();
|
||||
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
SetSizer(vbox);
|
||||
|
||||
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
|
||||
@@ -113,7 +120,19 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent
|
||||
|
||||
_grid = new GridAccount(_kiss, this, GRID_ID);
|
||||
|
||||
vbox->Add(_grid, 0, wxGROW|wxALL, 5);
|
||||
hbox->Add(_grid, 0, wxGROW|wxALL, 5);
|
||||
|
||||
_changeAccountButton = new wxButton(this, CHANGE_ACCOUNT_ID, _("Change account"));
|
||||
_changeCategoryButton = new wxButton(this, CHANGE_CATEGORY_ID, _("Change category"));
|
||||
_renameButton = new wxButton(this, RENAME_ID, _("Rename"));
|
||||
|
||||
vbox2->Add(_changeAccountButton, wxALL, 15);
|
||||
vbox2->Add(_changeCategoryButton, wxALL, 15);
|
||||
vbox2->Add(_renameButton, wxALL, 15);
|
||||
|
||||
hbox->Add(vbox2, 0, wxALL, 15);
|
||||
|
||||
vbox->Add(hbox, 0, wxGROW|wxALL, 5);
|
||||
|
||||
Fit();
|
||||
|
||||
@@ -145,7 +164,7 @@ wxString SearchPanel::GetToolTip()
|
||||
return _("Search");
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
void SearchPanel::Search()
|
||||
{
|
||||
wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL;
|
||||
std::vector<wxString> categories, accounts;
|
||||
@@ -240,6 +259,11 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
delete _operations;
|
||||
|
||||
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
{
|
||||
Search();
|
||||
|
||||
if (_operations->size() > 1)
|
||||
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
||||
@@ -256,6 +280,131 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
||||
static void ChangeAccount(Operation* op, void** params)
|
||||
{
|
||||
wxString* account = (wxString*) params[0];
|
||||
|
||||
op->account = *account;
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonChangeAccount(wxCommandEvent& event)
|
||||
{
|
||||
int i, a;
|
||||
std::vector<int> rows;
|
||||
User* user = _kiss->GetUser();
|
||||
wxString *accounts = new wxString[user->GetAccountsNumber()+1];
|
||||
std::vector<Operation>::iterator it;
|
||||
wxString account;
|
||||
void * params[] = {&account};
|
||||
|
||||
if (!_operations) return;
|
||||
|
||||
_grid->GetSelectedOperations(&rows);
|
||||
|
||||
accounts[0] = _("None");
|
||||
a = 0;
|
||||
for(i=0; i < user->GetAccountsNumber(); i++)
|
||||
accounts[++a] = user->_accounts[i].name;
|
||||
|
||||
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new account"), wxT("KissCount"), user->GetAccountsNumber()+1, accounts);
|
||||
|
||||
if (dialog.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
a = dialog.GetSelection();
|
||||
account = (a) ? user->_accounts[a-1].id : wxT("0");
|
||||
|
||||
_grid->MassUpdate(rows, ChangeAccount, params);
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
static void ChangeCategory(Operation* op, void** params)
|
||||
{
|
||||
wxString* category = (wxString*) params[0];
|
||||
bool* fix = (bool*) params[1];
|
||||
|
||||
op->category = *category;
|
||||
op->fix_cost = * fix;
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonChangeCategory(wxCommandEvent& event)
|
||||
{
|
||||
int i, a;
|
||||
std::vector<int> rows;
|
||||
User* user = _kiss->GetUser();
|
||||
wxString *categories = new wxString[user->GetCategoriesNumber()+1];
|
||||
std::vector<Operation>::iterator it;
|
||||
wxString category;
|
||||
bool fix;
|
||||
void * params[] = {&category, &fix};
|
||||
|
||||
if (!_operations) return;
|
||||
|
||||
_grid->GetSelectedOperations(&rows);
|
||||
|
||||
categories[0] = _("None");
|
||||
a = 0;
|
||||
for(i=0; i < user->GetCategoriesNumber(); i++)
|
||||
categories[++a] = user->_categories[i].name;
|
||||
|
||||
wxSingleChoiceDialog dialog(_wxUI, _("Choose a new category"), wxT("KissCount"), user->GetCategoriesNumber()+1, categories);
|
||||
|
||||
if (dialog.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
a = dialog.GetSelection();
|
||||
|
||||
if (a)
|
||||
{
|
||||
category = user->_categories[a-1].id ;
|
||||
fix = user->_categories[a-1].fix_cost;
|
||||
}
|
||||
else
|
||||
{
|
||||
category = wxT("0");
|
||||
fix = false;
|
||||
}
|
||||
|
||||
_grid->MassUpdate(rows, ChangeCategory, params);
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
static void ChangeName(Operation* op, void** params)
|
||||
{
|
||||
wxString* description = (wxString*) params[0];
|
||||
|
||||
op->description = *description;
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonRename(wxCommandEvent& event)
|
||||
{
|
||||
std::vector<int> rows;
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Operation>::iterator it;
|
||||
wxString category;
|
||||
wxString description;
|
||||
void * params[] = {&description};
|
||||
|
||||
if (!_operations) return;
|
||||
|
||||
_grid->GetSelectedOperations(&rows);
|
||||
|
||||
wxTextEntryDialog u(this, wxT(""), _("Enter a new description"));
|
||||
|
||||
if (u.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
description = u.GetValue();
|
||||
|
||||
if (!description.size()) return;
|
||||
|
||||
_grid->MassUpdate(rows, ChangeName, params);
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
void SearchPanel::OnShow(wxShowEvent& event)
|
||||
{
|
||||
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search"));
|
||||
|
||||
Reference in New Issue
Block a user