2010-07-10 16:34:30 +02:00
|
|
|
/*
|
|
|
|
Copyright 2010 Grégory Soutadé
|
|
|
|
|
|
|
|
This file is part of KissCount.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-05-15 11:21:42 +02:00
|
|
|
#include "User.h"
|
|
|
|
|
|
|
|
User::~User()
|
|
|
|
{
|
2010-07-03 11:48:53 +02:00
|
|
|
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
|
2010-05-15 11:21:42 +02:00
|
|
|
|
|
|
|
for (it = _operations.begin(); it != _operations.end(); it++)
|
|
|
|
{
|
|
|
|
if (_operations[it->first])
|
|
|
|
{
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-24 20:14:15 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
Category User::GetCategory(wxString& catId)
|
2010-06-22 12:29:36 +02:00
|
|
|
{
|
2010-07-03 11:48:53 +02:00
|
|
|
Category cat;
|
|
|
|
std::vector<Category>::iterator it;
|
2010-06-22 12:29:36 +02:00
|
|
|
|
2010-07-02 21:40:32 +02:00
|
|
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
2010-06-22 12:29:36 +02:00
|
|
|
if (it->id == catId)
|
|
|
|
return *it;
|
|
|
|
|
2010-07-03 11:19:02 +02:00
|
|
|
cat.id = wxT("0");
|
|
|
|
cat.parent = wxT("0");
|
2010-07-02 21:40:32 +02:00
|
|
|
cat.name = _("Unknown");
|
2010-07-03 11:19:02 +02:00
|
|
|
cat.font = wxT("");
|
2010-07-02 21:40:32 +02:00
|
|
|
cat.color = wxColour(0xFF, 0xFF, 0xFF);
|
2010-06-22 12:29:36 +02:00
|
|
|
|
2010-07-02 21:40:32 +02:00
|
|
|
return cat;
|
2010-06-22 12:29:36 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString User::GetCategoryName(wxString& catId)
|
2010-05-24 20:14:15 +02:00
|
|
|
{
|
2010-07-03 11:48:53 +02:00
|
|
|
std::vector<Category>::iterator it;
|
2010-07-02 21:40:32 +02:00
|
|
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
2010-06-22 12:29:36 +02:00
|
|
|
if (it->id == catId)
|
|
|
|
return it->name;
|
|
|
|
|
|
|
|
return _("Unknown") ;
|
2010-05-24 20:14:15 +02:00
|
|
|
}
|
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString User::GetCategoryId(wxString& catName)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-07-03 11:48:53 +02:00
|
|
|
std::vector<Category>::iterator it;
|
2010-07-02 21:40:32 +02:00
|
|
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
2010-06-22 12:29:36 +02:00
|
|
|
if (it->name == catName)
|
|
|
|
return it->id;
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-07-04 16:33:25 +02:00
|
|
|
return wxT("0") ;
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 18:59:19 +02:00
|
|
|
wxString User::GetAccountName(const wxString& accountId)
|
2010-05-24 20:14:15 +02:00
|
|
|
{
|
2010-07-04 16:33:25 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
|
|
|
if (it->id == accountId)
|
|
|
|
return it->name;
|
2010-06-21 13:02:02 +02:00
|
|
|
|
2010-07-04 16:33:25 +02:00
|
|
|
return _("Unknown") ;
|
2010-05-24 20:14:15 +02:00
|
|
|
}
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-07-05 18:35:12 +02:00
|
|
|
wxString User::GetAccountId(wxString& accountName)
|
2010-06-03 18:28:38 +02:00
|
|
|
{
|
2010-07-04 16:33:25 +02:00
|
|
|
std::vector<Account>::iterator it;
|
|
|
|
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
|
|
|
if (it->name == accountName)
|
|
|
|
return it->id;
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-07-04 16:33:25 +02:00
|
|
|
return wxT("0") ;
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
int User::GetCategoriesNumber()
|
|
|
|
{
|
2010-07-02 21:40:32 +02:00
|
|
|
return _categories.size();
|
2010-05-27 21:09:02 +02:00
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
|
|
|
|
int User::GetAccountsNumber()
|
|
|
|
{
|
|
|
|
return _accounts.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int User::GetOperationsNumber(int month, int year)
|
|
|
|
{
|
|
|
|
return (*_operations[year])[month].size();
|
|
|
|
}
|
2010-07-06 20:59:02 +02:00
|
|
|
|
|
|
|
wxLanguage User::GetLanguage()
|
|
|
|
{
|
|
|
|
wxString res = _preferences[wxT("language")];
|
|
|
|
long val;
|
|
|
|
|
2010-08-21 09:54:04 +02:00
|
|
|
if (!res.Length())
|
2010-07-07 21:04:38 +02:00
|
|
|
return wxLANGUAGE_ENGLISH ;
|
2010-07-06 20:59:02 +02:00
|
|
|
|
|
|
|
res.ToLong(&val);
|
|
|
|
|
|
|
|
return (wxLanguage)val;
|
|
|
|
}
|
2010-08-21 09:25:35 +02:00
|
|
|
|
|
|
|
void User::LinkOrUnlinkOperation(Operation& op)
|
|
|
|
{
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
|
|
|
|
// Not Linked
|
|
|
|
if (!op.transfert.Length())
|
|
|
|
{
|
|
|
|
for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++)
|
|
|
|
{
|
|
|
|
if (it->id != op.id && it->transfert == op.id)
|
|
|
|
{
|
|
|
|
it->transfert = wxT("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Linked
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++)
|
|
|
|
{
|
|
|
|
if (it->id != op.id && it->id == op.transfert)
|
|
|
|
{
|
|
|
|
it->transfert = op.id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
op.transfert = wxT("");
|
|
|
|
}
|
|
|
|
}
|