Fix two bugs (No entry in Search Panel and Date in Search (Database))

Add auto detection for account and category using description
Auto add date with curMonth & curYear for new operation
This commit is contained in:
Grégory Soutadé 2010-07-17 12:33:39 +02:00
parent de0e7fa1d9
commit cc70c0f804
6 changed files with 72 additions and 9 deletions

View File

@ -294,3 +294,36 @@ std::vector<Operation>* KissCount::Search(wxString* description, wxDateTime* dat
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts);
} }
bool KissCount::SearchPreviousOperation(Operation* res, wxString& description, int month, int year)
{
std::vector<Operation>* operations;
wxDateTime* date ;
//wxDateSpan threeMonths(0, 3); Not working :(
std::vector<wxString> v;
month -= 3;
if (month < 0)
{
year -= 1;
month += 12;
}
date = new wxDateTime(0, (wxDateTime::Month)month, year);
operations = Search(&description, date, NULL, NULL, NULL, v, v);
delete date;
if (!operations->size())
{
delete operations;
return false;
}
*res = (*operations)[operations->size()-1];
delete operations;
return true;
}

View File

@ -70,6 +70,8 @@ class KissCount
std::vector<Operation>* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, std::vector<Operation>* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
wxString* amountFrom, wxString* amountTo, wxString* amountFrom, wxString* amountTo,
std::vector<wxString> categories, std::vector<wxString> accounts); std::vector<wxString> categories, std::vector<wxString> accounts);
bool SearchPreviousOperation(Operation* res, wxString& description, int month, int year);
private: private:
wxUI* _wxUI; wxUI* _wxUI;
Database* _db; Database* _db;

View File

@ -935,7 +935,7 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
if (firstCond) req += wxT(" AND ") ; else firstCond = true; if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT("("); req += wxT("(");
req += wxT(" year >= '") + wxString::Format(wxT("%d"), dateFrom->GetYear()) + wxT("'"); req += wxT(" year >= '") + wxString::Format(wxT("%d"), dateFrom->GetYear()) + wxT("'");
req += wxT(" AND month >= '") + wxString::Format(wxT("%d"), dateFrom->GetMonth()) + wxT("'"); //req += wxT(" AND month >= '") + wxString::Format(wxT("%d"), dateFrom->GetMonth()) + wxT("'");
// req += wxT(" AND day >= '") + wxString::Format(wxT("%d"), dateFrom->GetDay()) + wxT("'"); // req += wxT(" AND day >= '") + wxString::Format(wxT("%d"), dateFrom->GetDay()) + wxT("'");
req += wxT(")"); req += wxT(")");
} }
@ -945,7 +945,7 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
if (firstCond) req += wxT(" AND ") ; else firstCond = true; if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT("("); req += wxT("(");
req += wxT(" year <= '") + wxString::Format(wxT("%d"), dateTo->GetYear()) + wxT("'"); req += wxT(" year <= '") + wxString::Format(wxT("%d"), dateTo->GetYear()) + wxT("'");
req += wxT(" AND month <= '") + wxString::Format(wxT("%d"), dateTo->GetMonth()) + wxT("'"); //req += wxT(" AND month <= '") + wxString::Format(wxT("%d"), dateTo->GetMonth()) + wxT("'");
// req += wxT(" AND day <= '") + wxString::Format(wxT("%d"), dateTo->GetDay()) + wxT("'"); // req += wxT(" AND day <= '") + wxString::Format(wxT("%d"), dateTo->GetDay()) + wxT("'");
req += wxT(")"); req += wxT(")");
} }
@ -1024,14 +1024,14 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
op.checked = set.GetBool(wxT("checked")); op.checked = set.GetBool(wxT("checked"));
if (dateFrom && if (dateFrom &&
(int)op.month == dateFrom->GetMonth() &&
(int)op.year == dateFrom->GetYear() && (int)op.year == dateFrom->GetYear() &&
(int)op.month < dateFrom->GetMonth() &&
(int)op.day < dateFrom->GetDay()-1) (int)op.day < dateFrom->GetDay()-1)
continue; continue;
if (dateTo && if (dateTo &&
(int)op.month == dateTo->GetMonth() &&
(int)op.year == dateTo->GetYear() && (int)op.year == dateTo->GetYear() &&
(int)op.month > dateTo->GetMonth() &&
(int)op.day > dateTo->GetDay()-1) (int)op.day > dateTo->GetDay()-1)
continue; continue;

View File

@ -522,7 +522,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
int row = event.GetRow()-1; int row = event.GetRow()-1;
int col = event.GetCol(); int col = event.GetCol();
Operation new_op, cur_op; Operation new_op, cur_op, op_tmp;
int op_complete = 6, i; int op_complete = 6, i;
wxString value ; wxString value ;
wxDateTime date; wxDateTime date;
@ -594,6 +594,20 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
new_op.checked = false; new_op.checked = false;
op_complete--; op_complete--;
if (event.GetCol() == DESCRIPTION &&
_grid->GetCellValue(event.GetRow(), CATEGORY) == wxT("") &&
_grid->GetCellValue(event.GetRow(), ACCOUNT) == wxT(""))
{
if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth-3, _curYear))
{
new_op.category = op_tmp.category;
new_op.account = op_tmp.account;
_grid->SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category));
_grid->SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account));
op_complete -= 2;
}
}
if (col == CHECKED || col == CATEGORY) if (col == CHECKED || col == CATEGORY)
{ {
color = user->GetCategory(new_op.category).color; color = user->GetCategory(new_op.category).color;

View File

@ -106,6 +106,9 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
std::vector<Operation>::iterator it; std::vector<Operation>::iterator it;
int r, g, b; int r, g, b;
wxColour color; wxColour color;
wxDateTime curDate;
curDate.SetToCurrent();
if (!op && !user->_accounts.size()) return; if (!op && !user->_accounts.size()) return;
@ -157,6 +160,15 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
else else
{ {
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear)); SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
if (curDate.GetMonth() == curMonth &&
curDate.GetYear() == curYear)
{
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
}
else
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
if (fix) if (fix)
SET_ROW_COLOR(line, OWN_YELLOW) SET_ROW_COLOR(line, OWN_YELLOW)
else else

View File

@ -36,13 +36,12 @@ END_EVENT_TABLE()
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL) SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL)
{ {
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
DEFAULT_FONT(font); DEFAULT_FONT(font);
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt; std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt; std::vector<Category>::iterator categoryIt;
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
SetSizer(vbox); SetSizer(vbox);
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from")); _checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
@ -206,7 +205,10 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
else if (_operations->size() == 1) else if (_operations->size() == 1)
wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
else else
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); {
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
return;
}
for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++) for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++)
{ {