wip
This commit is contained in:
parent
22cef5fe16
commit
f73c80fc6a
|
@ -43,6 +43,7 @@ void KissCount::LoadUser(wxString user)
|
|||
{
|
||||
if (_user) delete _user;
|
||||
_user = _db->LoadUser(user) ;
|
||||
if (_user)
|
||||
_wxUI->LoadUser();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
#include <model/User.h>
|
||||
#include <model/Account.h>
|
||||
#include <model/Database.h>
|
||||
#include <model/model.h>
|
||||
#include <view/wxUI.h>
|
||||
|
||||
class wxUI;
|
||||
|
|
23
init.sql
23
init.sql
|
@ -4,18 +4,19 @@ CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(i
|
|||
CREATE TABLE operation(id INTEGER PRIMARY KEY, user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount INTEGER, description VARCHAR(255), category REFERENCES preference(id), fix_cost CHAR(1));
|
||||
CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
|
||||
CREATE TABLE default_preference(id INTEGER PRIMARY KEY, type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
|
||||
INSERT INTO default_preference ("type", "value") VALUES ("category", "Fixe");
|
||||
INSERT INTO default_preference ("type", "value") VALUES ("category", "Courses");
|
||||
INSERT INTO default_preference ("type", "value") VALUES ("category", "Loisirs");
|
||||
INSERT INTO default_preference ("type", "value") VALUES ("category", "Frais de fonctionnement");
|
||||
INSERT INTO default_preference ("type", "value") VALUES ("category", "Exceptionnel");
|
||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Fixe");
|
||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Courses");
|
||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Loisirs");
|
||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Frais de fonctionnement");
|
||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Exceptionnel");
|
||||
-- No password
|
||||
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte courant", "000" , "0", "1");
|
||||
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
|
||||
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("0", "0", "2010", "0", "1000");
|
||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "0", "0", "1234", "Opé 1", "0", "1");
|
||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("1", "0", "0", "2010", "0", "1", "5678", "Opé 2", "1", "0");
|
||||
INSERT INTO preference ("type", "value") VALUES ("category", "Fixe");
|
||||
INSERT INTO preference ("type", "value") VALUES ("category", "Courses");
|
||||
INSERT INTO preference ("type", "value") VALUES ("category", "Loisirs");
|
||||
INSERT INTO preference ("type", "value") VALUES ("category", "Frais de fonctionnement");
|
||||
INSERT INTO preference ("type", "value") VALUES ("category", "Exceptionnel");
|
||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Fixe");
|
||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Courses");
|
||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Loisirs");
|
||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Frais de fonctionnement");
|
||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Exceptionnel");
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include "Account.h"
|
||||
|
||||
|
||||
Account::~Account()
|
||||
{
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef ACCOUNT_H
|
||||
#define ACCOUNT_H
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <wx/wx.h>
|
||||
|
||||
class Account
|
||||
{
|
||||
public:
|
||||
~Account();
|
||||
|
||||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _number;
|
||||
int _amount;
|
||||
bool _shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -131,8 +131,8 @@ User* Database::LoadUser(wxString name)
|
|||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
User* user;
|
||||
Account* account;
|
||||
std::list<Account*>::iterator it;
|
||||
struct Account account;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
|
||||
req = _("SELECT * FROM user WHERE name='") + name + _("'");
|
||||
|
||||
|
@ -155,25 +155,23 @@ User* Database::LoadUser(wxString name)
|
|||
|
||||
while (set.NextRow())
|
||||
{
|
||||
account = new Account();
|
||||
account->_id = set.GetAsString(_("id"));
|
||||
account->_name = set.GetAsString(_("name"));
|
||||
account->_number = set.GetAsString(_("number"));
|
||||
account->_amount = set.GetInt(_("amount"));
|
||||
account->_shared = set.GetBool(_("shared"));
|
||||
account->_default = set.GetBool(_("default_account"));
|
||||
user->_accounts.push_back(account);
|
||||
account.id = set.GetAsString(_("id"));
|
||||
account.name = set.GetAsString(_("name"));
|
||||
account.number = set.GetAsString(_("number"));
|
||||
account.shared = set.GetBool(_("shared"));
|
||||
account._default = set.GetBool(_("default_account"));
|
||||
user->_accounts[account.id] = account;
|
||||
}
|
||||
set.Finalize();
|
||||
|
||||
if (!user->_accounts.empty())
|
||||
{
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT DISTINCT year FROM operation WHERE account IN('") + (*it)->_id;
|
||||
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->first;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + (*it)->_id ;
|
||||
req += _("', '") + it->first ;
|
||||
}
|
||||
req += _("') ORDER BY year ASC");
|
||||
|
||||
|
@ -186,6 +184,14 @@ User* Database::LoadUser(wxString name)
|
|||
set.Finalize();
|
||||
}
|
||||
|
||||
req = _("SELECT id, value FROM preference WHERE type='category' AND name='name' AND user='") + user->_id + _("' ORDER BY value ASC");
|
||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||
|
||||
while (set.NextRow())
|
||||
user->_preferences._categories[set.GetAsString(_("id"))] = set.GetAsString(_("value"));
|
||||
|
||||
set.Finalize();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
@ -193,17 +199,17 @@ void Database::LoadYear(User* user, int year)
|
|||
{
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
std::list<Account*>::iterator it;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
|
||||
if (user->_operations[year] == NULL)
|
||||
user->_operations[year] = new std::map<unsigned int, std::list<operation> >();
|
||||
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + (*it)->_id;
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + it->first;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + (*it)->_id ;
|
||||
req += _("', '") + it->first ;
|
||||
}
|
||||
req += _("') ORDER BY fix_cost DESC, year,month,day ASC");
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class Preferences
|
|||
{
|
||||
public:
|
||||
std::map<wxString, wxColour> _colors;
|
||||
std::list<wxString> _categories;
|
||||
std::map<wxString, wxString> _categories;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,12 +5,6 @@ User::~User()
|
|||
{
|
||||
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* >::iterator it;
|
||||
|
||||
while (!_accounts.empty())
|
||||
{
|
||||
delete _accounts.front();
|
||||
_accounts.pop_front();
|
||||
}
|
||||
|
||||
for (it = _operations.begin(); it != _operations.end(); it++)
|
||||
{
|
||||
if (_operations[it->first])
|
||||
|
@ -19,3 +13,17 @@ User::~User()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxString User::GetCategoryName(wxString catId)
|
||||
{
|
||||
if (_preferences._categories.find(catId) == _preferences._categories.end())
|
||||
return _("Unknown") ;
|
||||
return _preferences._categories[catId];
|
||||
}
|
||||
|
||||
wxString User::GetAccountName(wxString accountId)
|
||||
{
|
||||
if (_accounts.find(accountId) == _accounts.end())
|
||||
return _("Unknown") ;
|
||||
return _accounts[accountId].name;
|
||||
}
|
||||
|
|
17
model/User.h
17
model/User.h
|
@ -2,8 +2,7 @@
|
|||
#define USER_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "Account.h"
|
||||
#include <wx/wx.h>
|
||||
#include "Preferences.h"
|
||||
|
||||
struct operation {
|
||||
|
@ -18,6 +17,15 @@ struct operation {
|
|||
wxString account;
|
||||
} ;
|
||||
|
||||
struct Account {
|
||||
wxString id;
|
||||
wxString name;
|
||||
wxString number;
|
||||
int amount;
|
||||
bool shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
class User
|
||||
{
|
||||
public:
|
||||
|
@ -26,9 +34,12 @@ public:
|
|||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _password;
|
||||
std::list<Account*> _accounts;
|
||||
std::map<wxString, Account> _accounts;
|
||||
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* > _operations;
|
||||
Preferences _preferences;
|
||||
|
||||
wxString GetCategoryName(wxString catId);
|
||||
wxString GetAccountName(wxString accountId);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define MODEL_H
|
||||
|
||||
#include "User.h"
|
||||
#include "Account.h"
|
||||
#include "Preferences.h"
|
||||
#include "Database.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,17 +6,42 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|||
{
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxChartPanel* chart ;
|
||||
|
||||
double data[] = {1.0, 2.0, 3.0} ;
|
||||
wxString cats[] = {_("cat1"), _("cat2"), _("cat3")};
|
||||
wxColour colours[] = {OWN_CYAN, OWN_YELLOW, OWN_GREEN} ;
|
||||
double value;
|
||||
SetSizer(hbox);
|
||||
|
||||
_pie = new PiePlot();
|
||||
CategorySimpleDataset* set = new CategorySimpleDataset(cats, 3);
|
||||
value = 1.0;
|
||||
//set->AddSerie(new CategorySerie(_("cat1"), &value, 1)) ;
|
||||
set->AddSerie(_("série 1"), data, 3);
|
||||
// value = 2.0;
|
||||
// set->AddSerie(new CategorySerie(_("cat2"), &value, 1)) ;
|
||||
// value = 3.0;
|
||||
// set->AddSerie(new CategorySerie(_("cat3"), &value, 1)) ;
|
||||
// set->SetRenderer(new XYLineRenderer());
|
||||
// set serie names to be displayed on legend
|
||||
//dataset->SetSerieName(0, wxT("Serie 0"));
|
||||
//dataset->SetSerieName(1, wxT("Serie 1"));
|
||||
|
||||
_pie->SetDataset(set);
|
||||
_pie->SetColorScheme(new ColorScheme(colours, 3));
|
||||
|
||||
// set legend
|
||||
_pie->SetLegend(new Legend(wxCENTER, wxTOP));
|
||||
|
||||
_grid = new GridAccount(this, -1);
|
||||
_grid->CreateGrid(1, NUMBER_COLS);
|
||||
_grid->SetColLabelSize(0);
|
||||
_grid->SetRowLabelSize(0);
|
||||
|
||||
chart = new wxChartPanel(this);
|
||||
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
||||
chart->Fit();
|
||||
chart->Layout();
|
||||
chart->SetMinSize(// chart->GetSize()
|
||||
wxSize(200,200));
|
||||
hbox->Add(&_tree, 0);
|
||||
hbox->Add(_grid, 0);
|
||||
hbox->Add(chart, 0);
|
||||
|
@ -30,7 +55,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|||
void AccountPanel::ChangeUser()
|
||||
{
|
||||
User* user = _kiss->GetUser();
|
||||
int curYear;
|
||||
int curYear = -1;
|
||||
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* >::iterator it;
|
||||
wxDateTime curDate;
|
||||
|
||||
|
@ -42,6 +67,7 @@ void AccountPanel::ChangeUser()
|
|||
_tree.AddRoot(wxString::Format(wxT("%d"), it->first));
|
||||
}
|
||||
|
||||
if (curYear != -1)
|
||||
LoadYear(curYear);
|
||||
}
|
||||
|
||||
|
@ -99,9 +125,10 @@ void AccountPanel::ShowMonth(int year, int month)
|
|||
int curLine = 0;
|
||||
User* user = _kiss->GetUser();
|
||||
wxFont font(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT);
|
||||
std::list<wxString>::iterator categoryIt;
|
||||
wxGridCellChoiceEditor* categoryEditor;
|
||||
wxString* categories;
|
||||
std::map<wxString, wxString>::iterator categoryIt;
|
||||
std::map<wxString, Account>::iterator accountIt;
|
||||
wxGridCellChoiceEditor* categoryEditor, *accountEditor;
|
||||
wxString* categories, *accounts;
|
||||
int i;
|
||||
|
||||
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
|
||||
|
@ -132,15 +159,21 @@ void AccountPanel::ShowMonth(int year, int month)
|
|||
// SetReadOnly(row, col, bool)
|
||||
|
||||
categories = new wxString[user->_preferences._categories.size()+1];
|
||||
categories[0] = _("unknown");
|
||||
categories[0] = _("Unknown");
|
||||
for (i=1,
|
||||
categoryIt = user->_preferences._categories.begin();
|
||||
categoryIt != user->_preferences._categories.end();
|
||||
categoryIt++,
|
||||
i++)
|
||||
categories[i] = *categoryIt;
|
||||
categoryIt++, i++)
|
||||
categories[i] = user->_preferences._categories[categoryIt->first];
|
||||
|
||||
accounts = new wxString[user->_accounts.size()+1];
|
||||
accounts[0] = _("Unknown");
|
||||
for (i=1,
|
||||
accountIt = user->_accounts.begin();
|
||||
accountIt != user->_accounts.end();
|
||||
accountIt++, i++)
|
||||
accounts[i] = user->_accounts[accountIt->first].name;
|
||||
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
|
||||
it = operations.begin();
|
||||
|
||||
|
@ -174,7 +207,10 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, it->account);
|
||||
_grid->SetCellValue(curLine, CATEGORY, user->GetCategoryName(it->category));
|
||||
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
||||
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
|
||||
it++;
|
||||
}
|
||||
|
||||
|
@ -185,6 +221,8 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
||||
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
||||
|
||||
_grid->_fixCosts = ++fixCosts;
|
||||
|
||||
|
@ -204,7 +242,10 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|||
_grid->SetCellValue(curLine, CATEGORY, it->category);
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, it->account);
|
||||
_grid->SetCellValue(curLine, CATEGORY, user->GetCategoryName(it->category));
|
||||
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
||||
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
|
||||
it++;
|
||||
}
|
||||
|
||||
|
@ -215,8 +256,14 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
||||
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
||||
|
||||
delete[] categories;
|
||||
delete[] accounts;
|
||||
|
||||
_grid->AutoSizeColumn(CATEGORY, false);
|
||||
_grid->AutoSizeColumn(ACCOUNT, false);
|
||||
|
||||
Fit();
|
||||
SetMinSize(GetSize());
|
||||
|
|
|
@ -20,6 +20,7 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|||
#include "wxUI.h"
|
||||
#include <model/model.h>
|
||||
#include "GridAccount.h"
|
||||
#include <wx/category/categorysimpledataset.h>
|
||||
|
||||
class wxUI;
|
||||
class KissCount;
|
||||
|
|
Loading…
Reference in New Issue
Block a user