2010-07-10 16:34:30 +02:00
|
|
|
/*
|
2012-02-01 11:02:54 +01:00
|
|
|
Copyright 2010-2012 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
|
|
|
*/
|
|
|
|
|
2011-08-20 11:43:12 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2011-08-20 14:02:47 +02:00
|
|
|
#include "KissCount.hpp"
|
2011-08-20 11:43:12 +02:00
|
|
|
|
2011-08-20 14:02:47 +02:00
|
|
|
#include <view/view.hpp>
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ImportEngine*> * KissCount::_importEngines;
|
|
|
|
std::vector<ExportEngine*> * KissCount::_exportEngines;
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-09-04 11:21:30 +02:00
|
|
|
KissCount::KissCount(int argc, char** argv) : QApplication(argc, argv), _user(0)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2011-11-16 15:47:49 +01:00
|
|
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
|
2012-02-26 14:24:04 +01:00
|
|
|
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
|
2011-11-16 15:47:49 +01:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
_wxUI = new wxUI(this, "KissCount");
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2011-09-04 11:21:30 +02:00
|
|
|
_wxUI->showMaximized();
|
|
|
|
_wxUI->setDisabled(true);
|
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
|
|
|
{
|
2011-09-04 11:21:30 +02:00
|
|
|
_db = new Database((argc == 2) ? argv[1] : 0, 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
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
_wxUI->close();
|
2012-04-26 20:45:01 +02:00
|
|
|
throw s;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->ChangeUser();
|
2011-09-04 11:21:30 +02:00
|
|
|
_wxUI->setDisabled(false);
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KissCount::~KissCount()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete _db;
|
|
|
|
delete _wxUI;
|
2011-07-03 07:56:48 +02:00
|
|
|
delete _importEngines;
|
|
|
|
delete _exportEngines;
|
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_user) delete _user;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
std::list<QString> KissCount::GetUsers()
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
return _db->GetUsers();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
bool KissCount::IsValidUser(const QString& user, const QString& 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
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::LoadUser(const QString& 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
|
|
|
{
|
2011-08-14 17:47:16 +02:00
|
|
|
if (!force && _user->_operations[year] != 0) return;
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2011-08-14 17:47:16 +02:00
|
|
|
if (_user->_operations[year] != 0)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
delete _user->_operations[year];
|
2011-08-14 17:47:16 +02:00
|
|
|
_user->_operations[year] = 0;
|
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
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
int KissCount::GetAccountAmount(int id, int month, int year, bool* had_value)
|
2010-06-02 22:14:11 +02:00
|
|
|
{
|
2012-04-28 12:25:17 +02:00
|
|
|
return _db->GetAccountAmount(id, month, year, had_value);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
int KissCount::CalcAccountAmount(int id, int month, int year, bool* had_values)
|
2011-01-29 20:53:44 +01:00
|
|
|
{
|
|
|
|
return _db->CalcAccountAmount(id, month, year, had_values);
|
|
|
|
}
|
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
// Unlink
|
2011-07-04 20:23:00 +02:00
|
|
|
if (checkTransfert)
|
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
op.transfert = 0;
|
2011-07-04 20:23:00 +02:00
|
|
|
_user->LinkOrUnlinkOperation(op);
|
|
|
|
}
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
_db->UpdateOperation(_user, op, checkTransfert);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
// Link
|
2011-07-04 20:23:00 +02:00
|
|
|
if (checkTransfert)
|
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
int KissCount::AddOperation(Operation& op, bool checkTransfert)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
int ret = _db->AddOperation(_user, op, checkTransfert);
|
2010-08-21 09:25:35 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
if (checkTransfert && op.transfert)
|
2010-08-26 21:28:15 +02:00
|
|
|
_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
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
if (op.transfert)
|
2010-08-21 09:25:35 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
op.transfert = 0;
|
2010-08-26 21:28:15 +02:00
|
|
|
_user->LinkOrUnlinkOperation(op);
|
2010-08-21 09:25:35 +02:00
|
|
|
}
|
2011-02-14 20:56:59 +01:00
|
|
|
_db->DeleteOperation(_user, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
int KissCount::MetaAmount(int id)
|
2010-10-24 16:04:56 +02:00
|
|
|
{
|
|
|
|
return _db->MetaAmount(id);
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
int KissCount::MetaPositiveAmount(int id)
|
2010-10-24 16:04:56 +02:00
|
|
|
{
|
|
|
|
return _db->MetaPositiveAmount(id);
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
void KissCount::SetAccountAmount(int accountId, int month, int year, int amount)
|
2010-06-12 15:59:27 +02:00
|
|
|
{
|
2011-07-04 20:23:00 +02:00
|
|
|
_db->SetAccountAmount(accountId, month, year, amount);
|
2010-06-12 15:59:27 +02:00
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
int KissCount::AddAccount(Account& ac)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
QDate curDate = QDate::currentDate();
|
2010-11-29 20:11:11 +01:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
ac.id = _db->AddAccount(_user, ac);
|
2011-08-14 21:03:48 +02:00
|
|
|
_user->AddAccount(ac);
|
2010-11-29 20:11:11 +01:00
|
|
|
|
2012-04-28 12:25:17 +02:00
|
|
|
SetAccountAmount(ac.id, curDate.month()-1, curDate.year(), 0.0);
|
2010-11-29 20:11:11 +01: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
|
|
|
_db->UpdateAccount(ac);
|
2011-08-14 21:03:48 +02:00
|
|
|
_user->UpdateAccount(ac);
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void KissCount::DeleteAccount(Account& ac, int replacement)
|
2010-06-21 10:53:43 +02:00
|
|
|
{
|
2011-02-08 21:17:35 +01:00
|
|
|
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it2;
|
2010-06-21 13:02:02 +02:00
|
|
|
|
2011-02-08 21:17:35 +01:00
|
|
|
_db->DeleteAccount(_user, ac, replacement);
|
2011-08-14 21:03:48 +02:00
|
|
|
_user->DeleteAccount(ac);
|
2011-02-08 21:17:35 +01:00
|
|
|
|
|
|
|
for (it2= _user->_operations.begin();
|
2011-08-14 21:03:48 +02:00
|
|
|
it2 != _user->_operations.end();
|
|
|
|
it2++)
|
|
|
|
LoadYear(it2->first, true);
|
2010-06-21 10:53:43 +02:00
|
|
|
}
|
2010-06-22 11:35:21 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::AddSharedAccount(Account& ac, const QString& granted)
|
2010-10-20 20:54:23 +02:00
|
|
|
{
|
|
|
|
_db->AddSharedAccount(ac, granted);
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::RemoveSharedAccount(Account& ac, int granted)
|
2010-10-24 16:04:56 +02:00
|
|
|
{
|
|
|
|
_db->RemoveSharedAccount(ac, granted);
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
std::map<QString, QString> KissCount::getSharedAccountOwners(int account)
|
2010-10-24 16:04:56 +02:00
|
|
|
{
|
|
|
|
return _db->getSharedAccountOwners(account);
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QString KissCount::getSharedAccountOwner(int account)
|
2010-10-24 16:04:56 +02:00
|
|
|
{
|
|
|
|
return _db->getSharedAccountOwner(account);
|
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
int KissCount::AddCategory(Category& category)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2011-08-14 21:03:48 +02:00
|
|
|
category.id = _db->AddCategory(_user, category);
|
|
|
|
_user->AddCategory(category);
|
2010-06-27 21:39:49 +02:00
|
|
|
|
2011-08-14 21:03:48 +02:00
|
|
|
return category.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);
|
2011-08-14 21:03:48 +02:00
|
|
|
_user->UpdateCategory(category);
|
2010-06-22 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void KissCount::DeleteCategory(Category& category, int replacement)
|
2010-06-22 11:35:21 +02:00
|
|
|
{
|
2011-02-08 21:17:35 +01:00
|
|
|
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
|
|
|
|
|
|
|
|
_db->DeleteCategory(_user, category, replacement);
|
2011-08-14 21:03:48 +02:00
|
|
|
_user->DeleteCategory(category);
|
2011-02-08 21:17:35 +01:00
|
|
|
|
|
|
|
for (it= _user->_operations.begin();
|
|
|
|
it != _user->_operations.end();
|
|
|
|
it++)
|
|
|
|
LoadYear(it->first, true);
|
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;
|
2011-08-25 17:45:41 +02:00
|
|
|
std::map<int, int> 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();
|
2011-02-14 20:56:59 +01:00
|
|
|
op._virtual = false;
|
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
|
2011-01-06 20:19:03 +01:00
|
|
|
for(it = (*_user->_operations[yearTo])[monthTo].begin();
|
|
|
|
it != (*_user->_operations[yearTo])[monthTo].end();
|
2010-10-01 20:09:15 +02:00
|
|
|
it++)
|
2010-09-22 21:02:29 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
if (it->parent)
|
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);
|
|
|
|
|
2011-01-06 20:19:03 +01:00
|
|
|
for(it2 = (*_user->_operations[yearTo])[monthTo].begin();
|
|
|
|
it2 != (*_user->_operations[yearTo])[monthTo].end();
|
2010-10-01 20:09:15 +02:00
|
|
|
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
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::ChangePassword(const QString& 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
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
bool KissCount::UserExists(const QString& 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
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::ChangeName(const QString& 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
|
|
|
}
|
|
|
|
|
2011-02-15 19:17:18 +01:00
|
|
|
// To enable translation during xgettext
|
2011-08-27 18:35:36 +02:00
|
|
|
QString default_cats[] = {
|
2011-04-25 17:36:58 +02:00
|
|
|
_("Fix"), _("Groceries"), _("Hobbies"), _("Car"),
|
2011-02-15 19:17:18 +01:00
|
|
|
_("Unexpected"), _("Other")
|
|
|
|
};
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::NewUser(const QString& name)
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
2012-04-28 12:25:17 +02:00
|
|
|
// QDate curDate = QDate::currentDate();
|
2010-11-15 13:32:17 +01:00
|
|
|
Account ac = {
|
2011-08-25 17:45:41 +02:00
|
|
|
/*.id = */0,
|
2010-11-15 21:12:31 +01:00
|
|
|
/*.name = */_("Account 1"),
|
2011-08-25 17:45:41 +02:00
|
|
|
/*.number = */0,
|
2010-11-15 21:12:31 +01:00
|
|
|
/*.shared = */false,
|
|
|
|
/*.blocked = */false,
|
|
|
|
/*._default = */true,
|
|
|
|
/*.is_owner = */true};
|
2010-08-26 21:28:15 +02:00
|
|
|
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
|
|
|
AddAccount(ac);
|
2010-07-07 21:19:47 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Fix" ; cat.backcolor = view::OWN_YELLOW ; cat.forecolor = Qt::black; cat.fix_cost = true;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Groceries" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Hobbies" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Car" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Unexpected" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2011-08-25 17:45:41 +02:00
|
|
|
cat.parent = 0 ; cat.name = "Other" ; cat.backcolor = view::OWN_GREEN; cat.forecolor = Qt::black; cat.fix_cost = false;
|
2010-08-26 21:28:15 +02:00
|
|
|
AddCategory(cat);
|
2010-07-07 21:19:47 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
SetOperationOrder("ASC");
|
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;
|
2011-08-14 17:47:16 +02:00
|
|
|
_user = 0;
|
2010-08-26 21:28:15 +02:00
|
|
|
_wxUI->ChangeUser();
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::SetLanguage(QString language)
|
2010-07-07 21:04:38 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
_user->_preferences["language"] = language;
|
2011-08-25 17:45:41 +02:00
|
|
|
_db->UpdatePreference(_user, "language");
|
2010-07-27 22:31:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ASC (default) or DESC
|
2010-08-26 21:28:15 +02:00
|
|
|
*/
|
2011-08-27 18:35:36 +02:00
|
|
|
void KissCount::SetOperationOrder(const QString& order)
|
2010-07-27 22:31:56 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
_user->_preferences["operation_order"] = order;
|
|
|
|
_db->UpdatePreference(_user, "operation_order");
|
2010-07-07 21:04:38 +02:00
|
|
|
}
|
2010-07-14 16:22:02 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
const QString& KissCount::GetOperationOrder()
|
2011-03-20 19:08:24 +01:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
return _user->_preferences["operation_order"] ;
|
2011-03-20 19:08:24 +01:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
std::vector<Operation>* KissCount::Search(QString* description, QDate* dateFrom, QDate* dateTo,
|
2012-04-30 21:15:51 +02:00
|
|
|
int* amountFrom, int* amountTo,
|
2011-08-25 17:45:41 +02:00
|
|
|
std::vector<int> categories, int types, std::vector<int> accounts)
|
2010-07-14 16:22:02 +02:00
|
|
|
{
|
|
|
|
|
2010-12-01 20:30:34 +01:00
|
|
|
return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, types, accounts, true);
|
2010-07-14 16:22:02 +02:00
|
|
|
}
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2012-04-11 19:28:35 +02:00
|
|
|
bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month, int year, bool limitToType, int index)
|
2010-07-17 12:33:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
std::vector<Operation>* operations;
|
|
|
|
//wxDateSpan threeMonths(0, 3); Not working :(
|
2011-08-27 18:35:36 +02:00
|
|
|
std::vector<int> v;
|
2010-12-02 19:12:27 +01:00
|
|
|
int i;
|
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
|
|
|
}
|
|
|
|
|
2012-04-11 19:28:35 +02:00
|
|
|
QDate date = QDate(year, month, 0);
|
2010-07-17 12:33:39 +02:00
|
|
|
|
2011-03-20 19:08:24 +01:00
|
|
|
if (limitToType)
|
2012-04-11 19:28:35 +02:00
|
|
|
operations = _db->Search(_user, &op.description, &date, 0, 0, 0, v, op.fix_cost ? +Database::FIX_OP : +Database::NON_FIX_OP, v, false);
|
2011-03-20 19:08:24 +01:00
|
|
|
else
|
2012-04-11 19:28:35 +02:00
|
|
|
operations = _db->Search(_user, &op.description, &date, 0, 0, 0, v, Database::ALL_OP, v, false);
|
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-12-02 19:12:27 +01:00
|
|
|
for(i=operations->size()-1; i>=0; i--)
|
2012-04-11 19:28:35 +02:00
|
|
|
if (!(*operations)[i].meta && index--)
|
2010-12-02 19:12:27 +01:00
|
|
|
{
|
|
|
|
*res = (*operations)[i];
|
|
|
|
delete operations;
|
|
|
|
return true;
|
|
|
|
}
|
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-12-02 19:12:27 +01:00
|
|
|
return false;
|
2010-07-17 12:33:39 +02:00
|
|
|
}
|
2010-08-17 18:59:19 +02:00
|
|
|
|
2012-02-26 21:16:45 +01:00
|
|
|
void KissCount::GetHistory(int month, int year, QStringList& list)
|
|
|
|
{
|
|
|
|
month -= 3;
|
|
|
|
if (month < 0)
|
|
|
|
{
|
|
|
|
year -= 1;
|
|
|
|
month += 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
_db->GetHistory(month, year, list);
|
|
|
|
}
|
|
|
|
|
2010-08-17 18:59:19 +02:00
|
|
|
void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo,
|
2012-04-30 21:15:51 +02:00
|
|
|
std::map<int, std::map<int, std::map<int, int> > >* accountAmounts,
|
|
|
|
std::map<int, int>* categories)
|
2010-08-17 18:59:19 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
_db->GetStats(_user, monthFrom, yearFrom, monthTo, yearTo, accountAmounts, categories);
|
2010-08-17 18:59:19 +02:00
|
|
|
}
|
2010-08-21 11:49:03 +02:00
|
|
|
|
2010-11-19 19:58:02 +01:00
|
|
|
void KissCount::GetMonthStats(int month, int year, int nbDays,
|
2012-04-30 21:15:51 +02:00
|
|
|
std::map<int, std::vector<int> >* operations,
|
|
|
|
std::map<int, int>* categories)
|
2010-11-19 19:58:02 +01:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
_db->GetMonthStats(_user, month, year, nbDays, operations, categories);
|
2010-11-19 19:58:02 +01:00
|
|
|
}
|
|
|
|
|
2011-11-01 18:01:17 +01:00
|
|
|
void KissCount::UpdateStats()
|
|
|
|
{
|
|
|
|
_wxUI->UpdateStats();
|
|
|
|
}
|
2010-11-19 19:58:02 +01:00
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
std::map<int, int>* KissCount::GetNotChecked(int month, int year)
|
2010-08-21 11:49:03 +02:00
|
|
|
{
|
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
|
|
|
|
2012-04-30 21:15:51 +02:00
|
|
|
std::map<int, int>* KissCount::GetVirtualAmount(int month, int year)
|
2011-02-14 20:56:59 +01:00
|
|
|
{
|
|
|
|
return _db->GetVirtualAmount(_user, month, year);
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QFont KissCount::ExtractFont(QString strFont)
|
2010-09-08 11:02:03 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
long int pointSize, weight, family, style;
|
|
|
|
QString faceName;
|
2010-09-08 11:02:03 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
if (!strFont.size())
|
2010-09-08 11:02:03 +02:00
|
|
|
{
|
|
|
|
DEFAULT_FONT(f);
|
|
|
|
return f;
|
|
|
|
}
|
2011-08-27 18:35:36 +02:00
|
|
|
QStringList list = strFont.split(";");
|
2010-09-08 11:02:03 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
pointSize = list[0].toInt();
|
|
|
|
family = list[1].toInt();
|
|
|
|
style = list[2].toInt();
|
|
|
|
weight = list[3].toInt();
|
|
|
|
faceName = list[4];
|
2010-09-08 11:02:03 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
return QFont(faceName, pointSize, weight);
|
2010-09-08 11:02:03 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QString KissCount::CompactFont(const QFont& font)
|
2010-09-08 11:02:03 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
QString res ;
|
|
|
|
res = res.sprintf("%d;%d;%d;%d;", font.pointSize(), 0, 0, font.weight());
|
2011-08-25 17:45:41 +02:00
|
|
|
res += font.family();
|
2010-09-08 11:02:03 +02:00
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
return res;
|
2010-09-08 11:02:03 +02:00
|
|
|
}
|
2011-03-13 19:15:21 +01:00
|
|
|
|
|
|
|
void KissCount::UnRegisterImportEngine(ImportEngine* engine)
|
|
|
|
{
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-08-14 21:03:48 +02:00
|
|
|
std::vector<ImportEngine*>::iterator it = std::find(importEngines->begin(), importEngines->end(), engine);
|
|
|
|
|
|
|
|
if (it!=importEngines->end()) importEngines->erase(it);
|
2011-03-13 19:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::RegisterImportEngine(ImportEngine* engine)
|
|
|
|
{
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
|
|
|
|
|
|
|
importEngines->push_back(engine);
|
2011-03-13 19:15:21 +01:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QString KissCount::GetImportEngineExtensions()
|
2011-03-13 19:15:21 +01:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
QString res;
|
2011-03-13 19:15:21 +01:00
|
|
|
std::vector<ImportEngine*>::iterator it;
|
|
|
|
int i;
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-07-03 07:56:48 +02:00
|
|
|
for(i=0; i<(int)importEngines->size()-1; i++)
|
2012-02-12 10:20:02 +01:00
|
|
|
res = res + (*importEngines)[i]->GetFileExt() + ";;" ;
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-07-03 07:56:48 +02:00
|
|
|
if (importEngines->size())
|
|
|
|
res = res + (*importEngines)[i]->GetFileExt();
|
2011-03-13 19:15:21 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-02-20 21:27:51 +01:00
|
|
|
ImportEngine* KissCount::GetImportEngine(QString path)
|
2011-03-13 19:15:21 +01:00
|
|
|
{
|
|
|
|
std::vector<ImportEngine*>::iterator it;
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-07-03 07:56:48 +02:00
|
|
|
for(it=importEngines->begin(); it!=importEngines->end(); it++)
|
2012-02-12 10:20:02 +01:00
|
|
|
{
|
2012-02-20 21:27:51 +01:00
|
|
|
if ((*it)->HandleFile(path, _user, _db, this))
|
|
|
|
return *it;
|
2012-02-12 10:20:02 +01:00
|
|
|
}
|
2011-03-13 19:15:21 +01:00
|
|
|
|
2011-08-14 17:47:16 +02:00
|
|
|
return 0;
|
2011-03-13 19:15:21 +01:00
|
|
|
}
|
2011-03-23 20:35:29 +01:00
|
|
|
|
|
|
|
void KissCount::UpdateImportPattern()
|
|
|
|
{
|
|
|
|
_db->UpdateImportPattern(_user);
|
|
|
|
}
|
2011-07-03 07:56:48 +02:00
|
|
|
|
|
|
|
void KissCount::UnRegisterExportEngine(ExportEngine* engine)
|
|
|
|
{
|
|
|
|
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
|
|
|
|
|
2011-08-14 21:03:48 +02:00
|
|
|
std::vector<ExportEngine*>::iterator it = std::find(exportEngines->begin(), exportEngines->end(), engine);
|
|
|
|
|
|
|
|
if (it!=exportEngines->end()) exportEngines->erase(it);
|
2011-07-03 07:56:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KissCount::RegisterExportEngine(ExportEngine* engine)
|
|
|
|
{
|
|
|
|
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
|
|
|
|
|
|
|
|
exportEngines->push_back(engine);
|
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QString KissCount::GetExportEngineExtensions()
|
2011-07-03 07:56:48 +02:00
|
|
|
{
|
2011-08-27 18:35:36 +02:00
|
|
|
QString res;
|
2011-07-03 07:56:48 +02:00
|
|
|
std::vector<ExportEngine*>::iterator it;
|
|
|
|
int i;
|
|
|
|
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
|
|
|
|
|
|
|
|
for(i=0; i<(int)exportEngines->size()-1; i++)
|
2012-02-12 10:20:02 +01:00
|
|
|
res = res + (*exportEngines)[i]->GetFileExt() + ";;" ;
|
2011-07-03 07:56:48 +02:00
|
|
|
|
|
|
|
if (exportEngines->size())
|
|
|
|
res = res + (*exportEngines)[i]->GetFileExt();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-02-12 10:20:02 +01:00
|
|
|
ExportEngine* KissCount::GetExportEngine(QString path, QString filter)
|
2011-07-03 07:56:48 +02:00
|
|
|
{
|
|
|
|
std::vector<ExportEngine*>::iterator it;
|
|
|
|
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
|
2012-02-12 10:20:02 +01:00
|
|
|
QString tmp;
|
2011-07-03 07:56:48 +02:00
|
|
|
|
|
|
|
for(it=exportEngines->begin(); it!=exportEngines->end(); it++)
|
2012-02-12 10:20:02 +01:00
|
|
|
{
|
|
|
|
if (filter == (*it)->GetFileExt())
|
|
|
|
{
|
|
|
|
tmp = path;
|
|
|
|
if (!tmp.endsWith((*it)->GetShortExt()))
|
|
|
|
tmp += (*it)->GetShortExt();
|
|
|
|
if ((*it)->HandleFile(tmp, _user, _db, this))
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
}
|
2011-07-03 07:56:48 +02:00
|
|
|
|
2011-08-14 17:47:16 +02:00
|
|
|
return 0;
|
2011-07-03 07:56:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ImportEngine*>* KissCount::GetImportEngines()
|
|
|
|
{
|
|
|
|
if (!_importEngines)
|
|
|
|
_importEngines = new std::vector<ImportEngine*>;
|
|
|
|
|
|
|
|
return _importEngines;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ExportEngine*>* KissCount::GetExportEngines()
|
|
|
|
{
|
|
|
|
if (!_exportEngines)
|
|
|
|
_exportEngines = new std::vector<ExportEngine*>;
|
|
|
|
|
|
|
|
return _exportEngines;
|
|
|
|
}
|
2012-03-20 20:57:45 +01:00
|
|
|
|
|
|
|
bool KissCount::ChangeDatabase(QString filename)
|
|
|
|
{
|
|
|
|
return _db->ChangeDatabase(filename);
|
|
|
|
}
|
2012-03-27 21:12:55 +02:00
|
|
|
|
|
|
|
QLocale* KissCount::GetLocale()
|
|
|
|
{
|
|
|
|
return _wxUI->GetLocale();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString KissCount::GetDateFormat()
|
|
|
|
{
|
|
|
|
return _wxUI->GetDateFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString KissCount::FormatDate(int day, int month, int year)
|
|
|
|
{
|
|
|
|
return QDate(year, month, day).toString(_wxUI->GetDateFormat());
|
|
|
|
}
|