Add checked/not checked criteria into search

This commit is contained in:
Grégory Soutadé 2010-12-01 20:30:34 +01:00
parent 765483ff15
commit 84bd6d8b42
7 changed files with 44 additions and 22 deletions

4
TODO
View File

@ -36,3 +36,7 @@ BUGS
* When we broke a transfert into a meta operation and re create it,
it's not taken in account by UpdateStats
* If a sub operation is found using SearchPanel but not its parent
it will not be displayed. In this case we must load whole meta.
This bug can't be resolved without use of hashtable because of
complexity in searching this issue.

View File

@ -400,10 +400,10 @@ void KissCount::SetOperationOrder(const wxString& order)
std::vector<Operation>* KissCount::Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int Fix, std::vector<wxString> accounts)
std::vector<wxString> categories, int types, std::vector<wxString> accounts)
{
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, Fix, accounts, true);
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, types, accounts, true);
}
bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month, int year)

View File

@ -82,7 +82,7 @@ public:
std::vector<Operation>* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int Fix, std::vector<wxString> accounts);
std::vector<wxString> categories, int types, std::vector<wxString> accounts);
bool SearchPreviousOperation(Operation* res, Operation& op, int month, int year);

View File

@ -1239,7 +1239,7 @@ void Database::UpdatePreference(User* user, const wxString& preference)
std::vector<Operation>* Database::Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int Fix, std::vector<wxString> accounts, bool wildcards)
std::vector<wxString> categories, int types, std::vector<wxString> accounts, bool wildcards)
{
wxSQLite3ResultSet set;
wxString req;
@ -1326,15 +1326,27 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
req += wxT("')");
}
if (Fix == FIX_OP)
if (types)
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT(" fix_cost='1'");
}
else if (Fix == NON_FIX_OP)
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT(" fix_cost='0'");
if ((types & FIX_OP) ^ (types & NON_FIX_OP))
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
if (types & FIX_OP)
req += wxT(" fix_cost='1'");
else
req += wxT(" fix_cost='0'");
}
if ((types & CHECKED_OP) ^ (types & NOT_CHECKED_OP))
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
if (types & CHECKED_OP)
req += wxT(" checked='1'");
else
req += wxT(" checked='0'");
}
}
if (firstCond) req += wxT(" AND ") ; else firstCond = true;

View File

@ -33,7 +33,10 @@
#define BDD_FILE "kc.bdd"
#define INIT_SCRIPT "init.sql"
enum {BOTH, FIX_OP, NON_FIX_OP};
#define FIX_OP (1 << 0)
#define NON_FIX_OP (1 << 1)
#define CHECKED_OP (1 << 2)
#define NOT_CHECKED_OP (1 << 3)
class KissCount;
class User;
@ -83,7 +86,7 @@ public:
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, int Fix, std::vector<wxString> accounts, bool wildcards);
std::vector<wxString> categories, int types, std::vector<wxString> accounts, bool wildcards);
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,

View File

@ -73,8 +73,9 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*pa
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
_category->Append(categoryIt->name);
wxString fixop[] = {_("Both"), _("Fix"), _("Non fix")};
_fix = new wxRadioBox(this, wxID_ANY, _("Operations"), wxDefaultPosition, wxDefaultSize, 3, fixop);
wxString stypes[] = {_("Fix"), _("Non fix"), _("Checked"), _("Not checked")};
_optype = new wxCheckListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, stypes);
_optype->Check(0); _optype->Check(1); _optype->Check(2); _optype->Check(3);
_account = new wxCheckListBox(this, wxID_ANY);
for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
@ -100,7 +101,7 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*pa
gridBagSizer->Add(_amountTo, wxGBPosition(1, 4));
gridBagSizer->Add(labelCategory, wxGBPosition(0, 5));
gridBagSizer->Add(_category, wxGBPosition(1, 5));
gridBagSizer->Add(_fix, wxGBPosition(1, 6));
gridBagSizer->Add(_optype, wxGBPosition(1, 6));
gridBagSizer->Add(labelAccount, wxGBPosition(0, 7));
gridBagSizer->Add(_account, wxGBPosition(1, 7));
gridBagSizer->Add(_searchButton, wxGBPosition(2, 0));
@ -131,7 +132,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
std::vector<wxString> categories, accounts;
wxDateTime *dateFrom=NULL, *dateTo=NULL;
User* user= _kiss->GetUser();
int i, fix;
int i, types=0;
std::vector<Operation>::iterator it;
double af, at;
@ -207,7 +208,10 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
if (_category->IsChecked(i))
categories.push_back(user->_categories[i].id);
fix = _fix->GetSelection();
types |= (_optype->IsChecked(0)) ? FIX_OP : 0;
types |= (_optype->IsChecked(1)) ? NON_FIX_OP : 0;
types |= (_optype->IsChecked(2)) ? CHECKED_OP : 0;
types |= (_optype->IsChecked(3)) ? NOT_CHECKED_OP : 0;
for(i=0; i<user->GetAccountsNumber(); i++)
if (_account->IsChecked(i))
@ -216,7 +220,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
if (_operations)
delete _operations;
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,fix, accounts);
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
if (_operations->size() > 1)
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);

View File

@ -58,8 +58,7 @@ private:
GridAccount *_grid;
wxCheckBox *_checkDateFrom, *_checkDateTo;
wxTextCtrl* _description, *_amountFrom, *_amountTo;
wxCheckListBox* _category, *_account;
wxRadioBox* _fix;
wxCheckListBox* _category, *_account, *_optype;
wxButton* _searchButton;
DECLARE_EVENT_TABLE();
};