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:
parent
de0e7fa1d9
commit
cc70c0f804
|
@ -294,3 +294,36 @@ std::vector<Operation>* 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<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;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ class KissCount
|
|||
std::vector<Operation>* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
||||
wxString* amountFrom, wxString* amountTo,
|
||||
std::vector<wxString> categories, std::vector<wxString> accounts);
|
||||
|
||||
bool SearchPreviousOperation(Operation* res, wxString& description, int month, int year);
|
||||
private:
|
||||
wxUI* _wxUI;
|
||||
Database* _db;
|
||||
|
|
|
@ -935,7 +935,7 @@ std::vector<Operation>* 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<Operation>* 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<Operation>* 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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -106,6 +106,9 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
|||
std::vector<Operation>::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
|
||||
|
|
|
@ -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<Account>::iterator accountIt;
|
||||
std::vector<Category>::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++)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user