This commit is contained in:
Grégory Soutadé 2010-05-16 20:09:18 +02:00
parent c4b3938cda
commit 47bd0da612
6 changed files with 172 additions and 12 deletions

View File

@ -1,7 +1,7 @@
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), amount INTEGER, shared CHAR(1), default_account CHAR(1));
CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount INTEGER);
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 VARCHAR(255), fix_cost CHAR(1));
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");
@ -12,5 +12,10 @@ INSERT INTO default_preference ("type", "value") VALUES ("category", "Exceptionn
-- No password
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
INSERT INTO account ("id", "user", "name", "number", "amount", "shared", "default_account") VALUES ("0", "0", "Compte courant", "000", "1234", "0", "1");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "0", "0", "1234", "Opé 1", "Cat 1", "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", "Cat 2", "0");
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");

View File

@ -213,6 +213,7 @@ void Database::LoadYear(User* user, int year)
{
operation op;
op.id = set.GetAsString(_("id"));
op.account = set.GetAsString(_("account"));
op.day = set.GetInt(_("day"));
op.month = set.GetInt(_("month"));
op.year = set.GetInt(_("year"));

View File

@ -15,6 +15,7 @@ struct operation {
wxString description;
wxString category;
bool fix_cost;
wxString account;
} ;
class User

View File

@ -1,7 +1,8 @@
#include "AccountPanel.h"
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _("")};
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1), _grid(this, -1)
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1)
{
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxChartPanel* chart ;
@ -9,15 +10,15 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
SetSizer(hbox);
_pie = new PiePlot();
_grid.CreateGrid(10, 7);
_grid.SetColLabelSize(0);
_grid.SetRowLabelSize(0);
//_grid.EnableGridLines(false);
_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")));
hbox->Add(&_tree, 0);
hbox->Add(&_grid, 0);
hbox->Add(_grid, 0);
hbox->Add(chart, 0);
ChangeUser();
@ -85,19 +86,42 @@ void AccountPanel::LoadYear(int year)
ShowMonth(year, curMonth);
}
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS; i++) \
{\
_grid->SetCellBackgroundColour(row, i, color);\
}
void AccountPanel::ShowMonth(int year, int month)
{
std::list<operation> operations;
std::list<operation>::iterator it;
int fixCosts = 0;
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;
int i;
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
// Operations are ordered
operations = (*user->_operations[year])[month];
_grid.CreateGrid(10, 7);
_grid->CreateGrid(1, NUMBER_COLS);
// Creating headers
_grid.SetColSize (0, _grid.GetColSize(0)*4);
_grid->SetColSize (0, _grid->GetColSize(0)*3);
_grid->SetDefaultCellFont(font);
font.SetWeight(wxFONTWEIGHT_BOLD);
for(i=0; i<NUMBER_COLS; i++)
{
_grid->SetCellValue(0, i, colsName[i]);
_grid->SetCellBackgroundColour(0, i, OWN_CYAN);
_grid->SetCellFont(0, i, font);
_grid->SetReadOnly(0, i, true);
}
// SetCellBackgroundColour (int row, int col, const wxColour &colour);
// SetCellFont (int row, int col, const wxFont &font);
// SetCellValue (int row, int col, const wxString &s);
@ -106,6 +130,94 @@ void AccountPanel::ShowMonth(int year, int month)
// AppendRows (int numRows=1, bool updateLabels=true);
// InsertRows (int pos=0, int numRows=1, bool updateLabels=true);
// SetReadOnly(row, col, bool)
categories = new wxString[user->_preferences._categories.size()+1];
categories[0] = _("unknown");
for (i=1,
categoryIt = user->_preferences._categories.begin();
categoryIt != user->_preferences._categories.end();
categoryIt++,
i++)
categories[i] = *categoryIt;
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
it = operations.begin();
/*
struct operation {
wxString id;
unsigned int day;
unsigned int month;
unsigned int year;
int amount;
wxString description;
wxString category;
bool fix_cost;
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
} ;
*/
while (it->fix_cost)
{
_grid->AppendRows();
curLine++;
fixCosts++;
SET_ROW_COLOR(curLine, OWN_YELLOW);
_grid->SetCellValue(curLine, DESCRIPTION, it->description);
_grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year));
if (it->amount < 0)
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%d"), -it->amount));
else
_grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%d"), it->amount));
_grid->SetCellValue(curLine, CATEGORY, it->category);
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
_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);
it++;
}
_grid->AppendRows();
curLine++;
SET_ROW_COLOR(curLine, OWN_YELLOW);
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
_grid->_fixCosts = ++fixCosts;
for (; it != operations.begin(); it++)
{
_grid->AppendRows();
curLine++;
SET_ROW_COLOR(curLine, OWN_GREEN);
_grid->SetCellValue(curLine, DESCRIPTION, it->description);
_grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year));
if (it->amount < 0)
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%d"), -it->amount));
else
_grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%d"), it->amount));
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
_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);
it++;
}
_grid->AppendRows();
curLine++;
SET_ROW_COLOR(curLine, OWN_GREEN);
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
delete[] categories;
Fit();
SetMinSize(GetSize());
}

View File

@ -7,6 +7,15 @@
#include <wx/pie/pieplot.h>
#include <wx/chartpanel.h>
#define OWN_CYAN wxColour(0x99, 0xCC, 0xFF)
#define OWN_YELLOW wxColour(0xFF, 0xFF, 0x99)
#define OWN_GREEN wxColour(0x3D, 0xEB, 0x3D)
#define DEFAULT_FONT _("Liberation Sans")
#define DEFAULT_FONT_SIZE 12
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>
@ -27,7 +36,7 @@ private:
KissCount* _kiss;
wxUI* _wxUI;
wxTreeCtrl _tree;
GridAccount _grid;
GridAccount* _grid;
PiePlot* _pie;
};

32
view/GridAccount.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef GRIDACCOUNT_H
#define GRIDACCOUNT_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <list>
#include "AccountPanel.h"
class GridAccount : public wxGrid
{
public:
GridAccount(wxWindow *parent, wxWindowID id) : wxGrid(parent, id) {}
wxPen GetColGridLinePen (int col) {return wxPen(*wxBLACK, 1, wxSOLID);}
wxPen GetRowGridLinePen (int row) {
if (row == 0 || row == _fixCosts ||
row == (_fixCosts + _week1) ||
row == (_fixCosts + _week2) ||
row == (_fixCosts + _week3))
return wxPen(*wxBLACK, 1, wxSOLID);
if (row <= _fixCosts)
return wxPen(OWN_YELLOW, 1, wxSOLID);
return wxPen(OWN_GREEN, 1, wxSOLID);
}
int _fixCosts;
int _week1, _week2, _week3;
private:
std::list<int> _col;
};
#endif