2010-07-14 16:22:02 +02:00
|
|
|
/*
|
2010-08-26 21:28:15 +02:00
|
|
|
Copyright 2010 Grégory Soutadé
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
KissCount is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-14 16:22:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AccountPanel.h"
|
|
|
|
|
2010-07-16 18:38:13 +02:00
|
|
|
enum {SEARCH_ID, GRID_ID, CALENDAR_FROM_ID, CALENDAR_TO_ID};
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
|
|
|
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
2010-07-16 18:38:13 +02:00
|
|
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_FROM_ID, SearchPanel::OnCalendarFromChange)
|
|
|
|
EVT_CALENDAR_SEL_CHANGED(CALENDAR_TO_ID, SearchPanel::OnCalendarToChange)
|
2010-07-16 19:28:36 +02:00
|
|
|
EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
|
|
|
|
EVT_SHOW(SearchPanel::OnShow)
|
2010-07-14 16:22:02 +02:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-09-05 12:08:48 +02:00
|
|
|
#define UNESCAPE_CHARS(s) { \
|
|
|
|
s.Replace(wxT("\\\""), wxT("\""), true); \
|
|
|
|
s.Replace(wxT("\\\'"), wxT("\'"), true); \
|
|
|
|
}
|
|
|
|
|
2010-07-14 16:22:02 +02:00
|
|
|
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
DEFAULT_FONT(font);
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
std::vector<Account>::iterator accountIt;
|
|
|
|
std::vector<Category>::iterator categoryIt;
|
|
|
|
wxDateTime firstOfMonth;
|
2010-09-22 21:02:29 +02:00
|
|
|
wxRect rect = wxDisplay().GetGeometry();
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
|
|
|
SetSizer(vbox);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
|
|
|
|
_checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to"));
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom->SetValue(wxT("1"));
|
|
|
|
_checkDateTo->SetValue(wxT("1"));
|
2010-07-27 22:31:56 +02:00
|
|
|
|
2010-10-30 20:52:53 +02:00
|
|
|
wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 10);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
firstOfMonth.SetToCurrent();
|
|
|
|
firstOfMonth.SetDay(1);
|
|
|
|
_calendarFrom = new wxCalendarCtrl(this, CALENDAR_FROM_ID, firstOfMonth, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxCAL_MONDAY_FIRST);
|
|
|
|
_calendarTo = new wxCalendarCtrl(this, CALENDAR_TO_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxCAL_MONDAY_FIRST);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_description = new wxTextCtrl(this, wxID_ANY);
|
|
|
|
wxSize size = _description->GetSize();
|
|
|
|
size.SetWidth(size.GetWidth()*2);
|
|
|
|
_description->SetMinSize(size);
|
|
|
|
_amountFrom = new wxTextCtrl(this, wxID_ANY);
|
|
|
|
_amountTo = new wxTextCtrl(this, wxID_ANY);
|
|
|
|
|
|
|
|
_category = new wxCheckListBox(this, wxID_ANY);
|
|
|
|
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
|
|
|
_category->Append(categoryIt->name);
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
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);
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_account = new wxCheckListBox(this, wxID_ANY);
|
|
|
|
for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
|
|
|
|
_account->Append(accountIt->name);
|
|
|
|
|
|
|
|
_searchButton = new wxButton(this, SEARCH_ID, _("Search"));
|
|
|
|
|
|
|
|
wxStaticText* labelDescription = new wxStaticText(this, wxID_ANY, _("Description"));
|
|
|
|
wxStaticText* labelAmountFrom = new wxStaticText(this, wxID_ANY, _("Amount from"));
|
|
|
|
wxStaticText* labelAmountTo = new wxStaticText(this, wxID_ANY, _("Amount to"));
|
|
|
|
wxStaticText* labelCategory = new wxStaticText(this, wxID_ANY, _("Category"));
|
|
|
|
wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account"));
|
|
|
|
|
|
|
|
gridBagSizer->Add(labelDescription, wxGBPosition(0, 0));
|
|
|
|
gridBagSizer->Add(_description, wxGBPosition(1, 0));
|
|
|
|
gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1));
|
|
|
|
gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1));
|
|
|
|
gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2));
|
|
|
|
gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2));
|
|
|
|
gridBagSizer->Add(labelAmountFrom, wxGBPosition(0, 3));
|
|
|
|
gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3));
|
|
|
|
gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4));
|
|
|
|
gridBagSizer->Add(_amountTo, wxGBPosition(1, 4));
|
|
|
|
gridBagSizer->Add(labelCategory, wxGBPosition(0, 5));
|
|
|
|
gridBagSizer->Add(_category, wxGBPosition(1, 5));
|
2010-12-01 20:30:34 +01:00
|
|
|
gridBagSizer->Add(_optype, wxGBPosition(1, 6));
|
2010-10-30 20:52:53 +02:00
|
|
|
gridBagSizer->Add(labelAccount, wxGBPosition(0, 7));
|
|
|
|
gridBagSizer->Add(_account, wxGBPosition(1, 7));
|
2010-08-26 21:28:15 +02:00
|
|
|
gridBagSizer->Add(_searchButton, wxGBPosition(2, 0));
|
|
|
|
|
|
|
|
vbox->Add(gridBagSizer);
|
|
|
|
vbox->Add(-1, 20);
|
|
|
|
|
|
|
|
_grid = new GridAccount(_kiss, this, GRID_ID);
|
|
|
|
|
|
|
|
vbox->Add(_grid);
|
|
|
|
|
|
|
|
Fit();
|
|
|
|
|
2010-09-22 21:02:29 +02:00
|
|
|
SetMinSize(wxSize(rect.width-rect.x, rect.height-rect.y-128));
|
2010-08-26 21:28:15 +02:00
|
|
|
SetScrollbars(10, 10, 100/10, 100/10);
|
|
|
|
|
|
|
|
Hide();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchPanel::~SearchPanel()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_operations) delete _operations;
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL;
|
|
|
|
std::vector<wxString> categories, accounts;
|
|
|
|
wxDateTime *dateFrom=NULL, *dateTo=NULL;
|
|
|
|
User* user= _kiss->GetUser();
|
2010-12-01 20:30:34 +01:00
|
|
|
int i, types=0;
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
double af, at;
|
|
|
|
|
|
|
|
if (_calendarFrom->GetDate() > _calendarTo->GetDate())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_amountFrom->GetLineText(0).Length())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
amountFrom = new wxString;
|
|
|
|
*amountFrom = _amountFrom->GetLineText(0);
|
|
|
|
if (!amountFrom->ToDouble(&af))
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-26 21:03:22 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (af < 0) af *= -1;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_amountTo->GetLineText(0).Length())
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
amountTo = new wxString;
|
|
|
|
*amountTo = _amountTo->GetLineText(0);
|
|
|
|
if (!amountTo->ToDouble(&at))
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
delete amountTo;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-26 21:03:22 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (at < 0) at *= -1;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (amountFrom && amountTo && af > at)
|
2010-07-14 18:56:07 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
delete amountFrom;
|
|
|
|
delete amountTo;
|
|
|
|
return;
|
2010-07-14 18:56:07 +02:00
|
|
|
}
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_description->GetLineText(0).Length())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
description = new wxString;
|
|
|
|
*description = _description->GetLineText(0);
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_checkDateFrom->IsChecked())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
dateFrom = new wxDateTime;
|
|
|
|
*dateFrom = _calendarFrom->GetDate();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_checkDateTo->IsChecked())
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
dateTo = new wxDateTime;
|
|
|
|
*dateTo = _calendarTo->GetDate();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (dateFrom && dateTo && *dateFrom > *dateTo)
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
;
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for(i=0; i<user->GetCategoriesNumber(); i++)
|
|
|
|
if (_category->IsChecked(i))
|
|
|
|
categories.push_back(user->_categories[i].id);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
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;
|
2010-10-30 20:52:53 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for(i=0; i<user->GetAccountsNumber(); i++)
|
|
|
|
if (_account->IsChecked(i))
|
|
|
|
accounts.push_back(user->_accounts[i].id);
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_operations)
|
|
|
|
delete _operations;
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories,types, accounts);
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_operations->size() > 1)
|
|
|
|
wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
|
|
|
else if (_operations->size() == 1)
|
|
|
|
wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
|
|
|
else
|
2010-07-17 12:33:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK);
|
|
|
|
return;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2010-09-12 18:10:40 +02:00
|
|
|
_grid->LoadOperations(_operations, false, false, 0, 0);
|
2010-07-14 18:56:07 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->Layout();
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnShow(wxShowEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search"));
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 18:38:13 +02:00
|
|
|
void SearchPanel::OnCalendarFromChange(wxCalendarEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateFrom->SetValue(true);
|
2010-07-16 18:38:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnCalendarToChange(wxCalendarEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_checkDateTo->SetValue(true);
|
2010-07-16 18:38:13 +02:00
|
|
|
}
|
2010-07-16 19:28:36 +02:00
|
|
|
|
|
|
|
void SearchPanel::OnOperationModified(wxGridEvent& event)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->NeedReload();
|
2010-07-16 19:28:36 +02:00
|
|
|
}
|