From cc70c0f80413657350c7b3d988cb7d94f6ced35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 17 Jul 2010 12:33:39 +0200 Subject: [PATCH] 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 --- src/controller/KissCount.cpp | 33 +++++++++++++++++++++++++++++++++ src/controller/KissCount.h | 2 ++ src/model/Database.cpp | 8 ++++---- src/view/AccountPanel.cpp | 18 ++++++++++++++++-- src/view/GridAccount.cpp | 12 ++++++++++++ src/view/SearchPanel.cpp | 8 +++++--- 6 files changed, 72 insertions(+), 9 deletions(-) diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 2e773da..b4e39b5 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -294,3 +294,36 @@ std::vector* KissCount::Search(wxString* description, wxDateTime* dat return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); } + +bool KissCount::SearchPreviousOperation(Operation* res, wxString& description, int month, int year) +{ + std::vector* operations; + wxDateTime* date ; + //wxDateSpan threeMonths(0, 3); Not working :( + std::vector 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; +} diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index 282a720..a2738a6 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -70,6 +70,8 @@ class KissCount std::vector* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, wxString* amountFrom, wxString* amountTo, std::vector categories, std::vector accounts); + + bool SearchPreviousOperation(Operation* res, wxString& description, int month, int year); private: wxUI* _wxUI; Database* _db; diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 21797cc..7a0ffe5 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -935,7 +935,7 @@ std::vector* Database::Search(User* user, wxString* description, wxDa if (firstCond) req += wxT(" AND ") ; else firstCond = true; req += 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(")"); } @@ -945,7 +945,7 @@ std::vector* Database::Search(User* user, wxString* description, wxDa if (firstCond) req += wxT(" AND ") ; else firstCond = true; req += 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(")"); } @@ -1024,14 +1024,14 @@ std::vector* Database::Search(User* user, wxString* description, wxDa op.checked = set.GetBool(wxT("checked")); if (dateFrom && - (int)op.month == dateFrom->GetMonth() && (int)op.year == dateFrom->GetYear() && + (int)op.month < dateFrom->GetMonth() && (int)op.day < dateFrom->GetDay()-1) continue; if (dateTo && - (int)op.month == dateTo->GetMonth() && (int)op.year == dateTo->GetYear() && + (int)op.month > dateTo->GetMonth() && (int)op.day > dateTo->GetDay()-1) continue; diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index ea41bda..e272c4b 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -522,7 +522,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) User* user = _kiss->GetUser(); int row = event.GetRow()-1; int col = event.GetCol(); - Operation new_op, cur_op; + Operation new_op, cur_op, op_tmp; int op_complete = 6, i; wxString value ; wxDateTime date; @@ -535,7 +535,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) if (inModification) return; inModification = true ; - + if (event.GetCol() == DEBIT) _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); else if (event.GetCol() == CREDIT) @@ -594,6 +594,20 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) new_op.checked = false; 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) { color = user->GetCategory(new_op.category).color; diff --git a/src/view/GridAccount.cpp b/src/view/GridAccount.cpp index 7c5eb85..471bd97 100644 --- a/src/view/GridAccount.cpp +++ b/src/view/GridAccount.cpp @@ -106,6 +106,9 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, std::vector::iterator it; int r, g, b; wxColour color; + wxDateTime curDate; + + curDate.SetToCurrent(); if (!op && !user->_accounts.size()) return; @@ -157,6 +160,15 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, else { 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) SET_ROW_COLOR(line, OWN_YELLOW) else diff --git a/src/view/SearchPanel.cpp b/src/view/SearchPanel.cpp index e7ce80f..5f5b752 100644 --- a/src/view/SearchPanel.cpp +++ b/src/view/SearchPanel.cpp @@ -36,13 +36,12 @@ END_EVENT_TABLE() SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL) { - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - DEFAULT_FONT(font); User* user = _kiss->GetUser(); std::vector::iterator accountIt; std::vector::iterator categoryIt; + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); SetSizer(vbox); _checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from")); @@ -206,7 +205,10 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event) else if (_operations->size() == 1) wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); 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++) {