2010-07-10 16:34:30 +02:00
|
|
|
/*
|
2010-08-26 21:28:15 +02:00
|
|
|
Copyright 2010 Grégory Soutadé
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-10 16:34:30 +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-10 16:34:30 +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-10 16:34:30 +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-10 16:34:30 +02:00
|
|
|
*/
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
#include "KissCount.h"
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2010-08-22 16:35:12 +02:00
|
|
|
KissCount::KissCount(const char* bdd_filename) : _user(NULL)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-09-22 21:02:29 +02:00
|
|
|
wxRect rect = wxDisplay().GetGeometry();
|
|
|
|
|
|
|
|
_wxUI = new wxUI(this, wxT("KissCount"), wxPoint(50, 50), wxSize(rect.width-rect.x, rect.height-rect.y));
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->SetLanguage(wxLocale::GetSystemLanguage());
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->Show(true);
|
|
|
|
_wxUI->Centre();
|
|
|
|
_wxUI->Disable();
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
try
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-09-08 11:02:03 +02:00
|
|
|
_db = new Database(bdd_filename, this);
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-08-26 21:28:15 +02:00
|
|
|
catch (std::string s)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->Close(true);
|
|
|
|
throw s;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->ChangeUser();
|
|
|
|
_wxUI->Enable();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KissCount::~KissCount()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete _db;
|
|
|
|
delete _wxUI;
|
|
|
|
if (_user) delete _user;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::list<wxString> KissCount::GetUsers()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->GetUsers();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
bool KissCount::IsValidUser(const wxString& user, const wxString& password)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->IsValidUser(user, password) ;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::LoadUser(const wxString& user)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_user) delete _user;
|
|
|
|
_user = _db->LoadUser(user) ;
|
|
|
|
if (_user)
|
|
|
|
_wxUI->LoadUser();
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-05-17 18:03:21 +02:00
|
|
|
void KissCount::LoadYear(int year, bool force)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (!force && _user->_operations[year] != NULL) return;
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_user->_operations[year] != NULL)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete _user->_operations[year];
|
|
|
|
_user->_operations[year] = NULL;
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->LoadYear(_user, year);
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
User* KissCount::GetUser()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _user;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
double KissCount::GetAccountAmount(const wxString& id, int month, int year)
|
2010-06-02 22:14:11 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->GetAccountAmount(id, month, year);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::UpdateOperation(Operation& op)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
// Unlink
|
|
|
|
op.transfert = wxT("");
|
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->UpdateOperation(op);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// Link
|
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString KissCount::AddOperation(Operation& op)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString ret = _db->AddOperation(_user, op);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (op.transfert.Length())
|
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
return ret;
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::DeleteOperation(Operation& op)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
if (op.transfert.Length())
|
2010-08-21 09:25:35 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
op.transfert = wxT("");
|
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-08-21 09:25:35 +02:00
|
|
|
}
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->DeleteOperation(op);
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
2010-06-12 15:59:27 +02:00
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
void KissCount::DeleteOperations(int month, int year)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->DeleteOperations(_user, month, year);
|
|
|
|
if (month != -1)
|
|
|
|
(*_user->_operations[year]).erase(month);
|
2010-06-24 21:02:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (month == -1 || !_user->_operations[year]->size())
|
2010-06-24 21:02:42 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete _user->_operations[year];
|
|
|
|
_user->_operations.erase(year);
|
2010-06-24 21:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::SetAccountAmount(int month, int year, const wxString& accountId, double amount)
|
2010-06-12 15:59:27 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->SetAccountAmount(month, year, accountId, amount);
|
2010-06-12 15:59:27 +02:00
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString KissCount::AddAccount(Account& ac)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
ac.id = _db->AddAccount(_user, ac);
|
|
|
|
_user->_accounts.push_back(ac);
|
2010-07-03 12:22:46 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
return ac.id;
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::UpdateAccount(Account& ac)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
int i;
|
2010-06-21 13:02:02 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->UpdateAccount(ac);
|
|
|
|
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
|
|
|
if (it->id == ac.id)
|
|
|
|
_user->_accounts[i] = ac;
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::DeleteAccount(Account& ac)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
int i;
|
2010-06-21 13:02:02 +02:00
|
|
|
|
2010-10-20 20:54:23 +02:00
|
|
|
_db->DeleteAccount(_user, ac);
|
2010-08-26 21:28:15 +02:00
|
|
|
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
|
|
|
if (it->id == ac.id)
|
|
|
|
{
|
|
|
|
_user->_accounts.erase(_user->_accounts.begin()+i);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
2010-06-22 11:35:21 +02:00
|
|
|
|
2010-10-20 20:54:23 +02:00
|
|
|
void KissCount::AddSharedAccount(Account& ac, const wxString& granted)
|
|
|
|
{
|
|
|
|
_db->AddSharedAccount(ac, granted);
|
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString KissCount::AddCategory(Category& category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString id;
|
|
|
|
id = _db->AddCategory(_user, category);
|
|
|
|
category.id = id;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_user->_categories.push_back(category);
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
return id;
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::UpdateCategory(Category& category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->UpdateCategory(category);
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
|
|
|
if (_user->_categories[i].id == category.id)
|
|
|
|
{
|
|
|
|
_user->_categories[i] = category;
|
2010-09-08 11:02:03 +02:00
|
|
|
_user->_categoriesFonts[i] = ExtractFont(category.font);
|
2010-08-26 21:28:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::DeleteCategory(Category& category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->DeleteCategory(_user, category);
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
|
|
|
if (_user->_categories[i].id == category.id)
|
|
|
|
{
|
|
|
|
_user->_categories.erase(_user->_categories.begin()+i);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
2010-06-23 14:25:00 +02:00
|
|
|
|
|
|
|
std::map<int, std::vector<int> > KissCount::GetAllOperations()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->GetAllOperations(_user);
|
2010-06-23 14:25:00 +02:00
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
|
|
|
|
void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo)
|
|
|
|
{
|
2010-10-01 20:09:15 +02:00
|
|
|
std::vector<Operation>::iterator it, it2;
|
2010-09-22 21:02:29 +02:00
|
|
|
std::map<wxString, wxString> meta;
|
2010-08-26 21:28:15 +02:00
|
|
|
Operation op;
|
2010-06-23 19:32:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo);
|
2010-06-24 21:02:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (!_user->_operations[yearTo])
|
|
|
|
_user->_operations[yearTo] = new std::map<unsigned int, std::vector<Operation> >();
|
2010-06-24 21:02:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (monthFrom != -1 && yearFrom != -1)
|
2010-06-23 19:32:42 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
LoadYear(yearFrom, false);
|
2010-06-24 21:02:42 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
for(it = (*_user->_operations[yearFrom])[monthFrom].begin();
|
2010-10-01 20:09:15 +02:00
|
|
|
it != (*_user->_operations[yearFrom])[monthFrom].end();
|
|
|
|
it++)
|
2010-06-23 19:32:42 +02:00
|
|
|
{
|
2010-10-01 20:09:15 +02:00
|
|
|
if (!it->fix_cost) continue;
|
2010-08-26 21:28:15 +02:00
|
|
|
op = *it;
|
|
|
|
op.month = monthTo;
|
|
|
|
op.year = yearTo;
|
2010-09-08 11:02:03 +02:00
|
|
|
op.checked = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
op.id = AddOperation(op);
|
2010-10-01 20:09:15 +02:00
|
|
|
op.childs.clear();
|
2010-09-22 21:02:29 +02:00
|
|
|
if (op.meta)
|
|
|
|
meta[it->id] = op.id;
|
2010-08-26 21:28:15 +02:00
|
|
|
(*_user->_operations[yearTo])[monthTo].push_back(op);
|
2010-06-23 19:32:42 +02:00
|
|
|
}
|
2010-09-22 21:02:29 +02:00
|
|
|
|
|
|
|
// Re Generate parents
|
2010-10-01 20:09:15 +02:00
|
|
|
for(it = (*_user->_operations[yearFrom])[monthTo].begin();
|
|
|
|
it != (*_user->_operations[yearFrom])[monthTo].end();
|
|
|
|
it++)
|
2010-09-22 21:02:29 +02:00
|
|
|
{
|
|
|
|
if (it->parent.Length())
|
2010-10-01 20:09:15 +02:00
|
|
|
{
|
2010-09-22 21:02:29 +02:00
|
|
|
it->parent = meta[it->parent];
|
2010-10-01 20:09:15 +02:00
|
|
|
UpdateOperation(*it);
|
|
|
|
|
|
|
|
for(it2 = (*_user->_operations[yearFrom])[monthTo].begin();
|
|
|
|
it2 != (*_user->_operations[yearFrom])[monthTo].end();
|
|
|
|
it2++)
|
|
|
|
if (it2->id == it->parent)
|
|
|
|
{
|
2010-10-03 20:31:06 +02:00
|
|
|
it2->childs.push_back(it->id);
|
2010-10-01 20:09:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 21:02:29 +02:00
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
}
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->GenerateMonth(monthTo, yearTo);
|
2010-06-23 19:32:42 +02:00
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::ChangePassword(const wxString& password)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->ChangePassword(_user, password);
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
bool KissCount::UserExists(const wxString& name)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->UserExists(name);
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::ChangeName(const wxString& name)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->ChangeName(_user, name);
|
|
|
|
_user->_name = name;
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
void KissCount::NewUser(const wxString& name)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxDateTime curDate;
|
|
|
|
Account ac = {wxT(""), wxT("Account 1"), wxT(""), false, true};
|
|
|
|
Category cat ;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->NewUser(name);
|
|
|
|
if (_user) delete _user;
|
|
|
|
_user = _db->LoadUser(name) ;
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
curDate.SetToCurrent();
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
AddAccount(ac);
|
2010-07-07 21:19:47 +02:00
|
|
|
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Fix") ; cat.backcolor = OWN_YELLOW ; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Groceries") ; cat.backcolor = OWN_GREEN; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Hobbies") ; cat.backcolor = OWN_GREEN; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Operating exepense") ; cat.backcolor = OWN_GREEN; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Unexpected") ; cat.backcolor = OWN_GREEN; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-09-09 20:54:00 +02:00
|
|
|
cat.parent = wxT("0") ; cat.name = _("Other") ; cat.backcolor = OWN_GREEN; cat.forecolor = *wxBLACK;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-07-07 21:19:47 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
SetOperationOrder(wxT("ASC"));
|
2010-08-24 22:23:56 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::KillMe()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->KillMe();
|
|
|
|
_db->KillMe(_user);
|
|
|
|
delete _user;
|
|
|
|
_user = NULL;
|
|
|
|
_wxUI->ChangeUser();
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
2010-07-07 21:04:38 +02:00
|
|
|
|
|
|
|
void KissCount::SetLanguage(wxLanguage language)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ;
|
|
|
|
_db->UpdatePreference(_user, wxT("language"));
|
2010-07-27 22:31:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ASC (default) or DESC
|
2010-08-26 21:28:15 +02:00
|
|
|
*/
|
2010-07-27 22:31:56 +02:00
|
|
|
void KissCount::SetOperationOrder(const wxString& order)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_user->_preferences[wxT("operation_order")] = order;
|
|
|
|
_db->UpdatePreference(_user, wxT("operation_order"));
|
2010-07-07 21:04:38 +02:00
|
|
|
}
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
std::vector<Operation>* KissCount::Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
|
|
|
wxString* amountFrom, wxString* amountTo,
|
|
|
|
std::vector<wxString> categories, std::vector<wxString> accounts)
|
|
|
|
{
|
|
|
|
|
2010-08-29 09:29:34 +02:00
|
|
|
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts, true);
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
2010-07-17 12:33:39 +02:00
|
|
|
|
|
|
|
bool KissCount::SearchPreviousOperation(Operation* res, wxString& description, int month, int year)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Operation>* operations;
|
|
|
|
wxDateTime* date ;
|
|
|
|
//wxDateSpan threeMonths(0, 3); Not working :(
|
|
|
|
std::vector<wxString> v;
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
month -= 3;
|
|
|
|
if (month < 0)
|
2010-07-17 12:33:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
year -= 1;
|
|
|
|
month += 12;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
date = new wxDateTime(0, (wxDateTime::Month)month, year);
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-29 09:29:34 +02:00
|
|
|
operations = _db->Search(_user, &description, date, NULL, NULL, NULL, v, v, false);
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
delete date;
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (!operations->size())
|
2010-07-17 12:33:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete operations;
|
|
|
|
return false;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
*res = (*operations)[operations->size()-1];
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
delete operations;
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
return true;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
2010-08-17 18:59:19 +02:00
|
|
|
|
|
|
|
void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
|
2010-08-26 21:28:15 +02:00
|
|
|
std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
|
|
|
std::map<wxString, double>* categories)
|
2010-08-17 18:59:19 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
wxString monthF = wxString::Format(wxT("%d"), monthFrom);
|
|
|
|
wxString monthT = wxString::Format(wxT("%d"), monthTo);
|
|
|
|
wxString yearF = wxString::Format(wxT("%d"), yearFrom);
|
|
|
|
wxString yearT = wxString::Format(wxT("%d"), yearTo);
|
2010-08-17 18:59:19 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_db->GetStats(_user, monthF, yearF, monthT, yearT, accountAmounts, categories);
|
2010-08-17 18:59:19 +02:00
|
|
|
}
|
2010-08-21 11:49:03 +02:00
|
|
|
|
|
|
|
std::map<wxString, double>* KissCount::GetNotChecked(int month, int year)
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->GetNotChecked(_user, month, year);
|
2010-08-21 11:49:03 +02:00
|
|
|
}
|
2010-09-08 11:02:03 +02:00
|
|
|
|
|
|
|
wxFont KissCount::ExtractFont(wxString strFont)
|
|
|
|
{
|
|
|
|
long int pos, pointSize, family, style, weight;
|
|
|
|
wxString faceName;
|
|
|
|
|
|
|
|
if (!strFont.Length())
|
|
|
|
{
|
|
|
|
DEFAULT_FONT(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = strFont.Find(wxT(";"));
|
|
|
|
|
|
|
|
if (pos != -1)
|
|
|
|
{
|
|
|
|
strFont.SubString(0, pos).ToLong(&pointSize);
|
|
|
|
strFont = strFont.SubString(pos+1, strFont.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = strFont.Find(wxT(";"));
|
|
|
|
|
|
|
|
if (pos != -1)
|
|
|
|
{
|
|
|
|
strFont.SubString(0, pos).ToLong(&family);
|
|
|
|
strFont = strFont.SubString(pos+1, strFont.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = strFont.Find(wxT(";"));
|
|
|
|
|
|
|
|
if (pos != -1)
|
|
|
|
{
|
|
|
|
strFont.SubString(0, pos).ToLong(&style);
|
|
|
|
strFont = strFont.SubString(pos+1, strFont.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = strFont.Find(wxT(";"));
|
|
|
|
|
|
|
|
if (pos != -1)
|
|
|
|
{
|
|
|
|
strFont.SubString(0, pos).ToLong(&weight);
|
|
|
|
strFont = strFont.SubString(pos+1, strFont.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
faceName = strFont;
|
|
|
|
|
|
|
|
return wxFont(pointSize, family, style, weight, false, faceName) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString KissCount::CompactFont(const wxFont& font)
|
|
|
|
{
|
|
|
|
wxString res = wxString::Format(wxT("%d;%d;%d;%d;"), font.GetPointSize(), font.GetFamily(), font.GetStyle(), font.GetWeight());
|
|
|
|
res += font.GetFaceName();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|