A lot of work done

This commit is contained in:
Grégory Soutadé 2010-06-16 17:29:07 +02:00
parent c353c02d5b
commit 742c95b2c7
10 changed files with 152 additions and 21 deletions

View File

@ -9,17 +9,26 @@ INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "na
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");
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Fixe", "#FFFF99");
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Courses", "#3DEB3D");
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Loisirs", "#3DEB3D");
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Frais de fonctionnement", "#3DEB3D");
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Exceptionnel", "#3DEB3D");
-- 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_amount("id", "account", "year", "month", "amount") VALUES("0", "0", "2010", "5", "1000");
-- Fix operation
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1");
-- Others operations
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("1", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("2", "0", "0", "2010", "5", "29", "-2056", "Opé 3", "3", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("2", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("3", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0");
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");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Fixe", "#FFFF99");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Courses", "#3DEB3D");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Loisirs", "#3DEB3D");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Frais de fonctionnement", "#3DEB3D");
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Exceptionnel", "#3DEB3D");

0
model/Account.cpp Executable file → Normal file
View File

0
model/Account.h Executable file → Normal file
View File

View File

@ -208,6 +208,14 @@ User* Database::LoadUser(wxString name)
set.Finalize();
req = _("SELECT name, value FROM preference WHERE type='category_color' 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._colors[set.GetAsString(_("name"))] = wxColour(set.GetAsString(_("value")));
set.Finalize();
return user;
}

0
model/Preferences.cpp Normal file → Executable file
View File

View File

@ -1,6 +1,6 @@
#include "AccountPanel.h"
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _("")};
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _(""), _("")};
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
@ -80,8 +80,6 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
_accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value"));
_accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value"));
_accountsGrid->AutoSizeColumns(true);
_statsGrid = new wxGrid(this, -1);
_statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2);
_statsGrid->SetColLabelSize(0);
@ -134,8 +132,10 @@ void AccountPanel::InitStatsGrid(User* user)
_statsGrid->AutoSizeColumn(0, false);
for(i=0; i<user->GetCategoriesNumber(); i++)
_statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]);
{
_statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]);
_statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
font.SetWeight(wxFONTWEIGHT_BOLD);
_statsGrid->SetCellFont(CUR_CREDIT, 0, font);
_statsGrid->SetCellFont(CUR_DEBIT, 0, font);
@ -145,6 +145,12 @@ void AccountPanel::InitStatsGrid(User* user)
_statsGrid->SetCellValue(CUR_CREDIT, 0, _("Cur Credit"));
_statsGrid->SetCellValue(CUR_DEBIT, 0, _("Cur Debit"));
_statsGrid->SetCellValue(REMAINS, 0, _("Remains"));
_statsGrid->SetCellAlignment(CUR_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_statsGrid->SetCellAlignment(CUR_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_statsGrid->SetCellAlignment(TOTAL_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_statsGrid->SetCellAlignment(TOTAL_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
_statsGrid->SetCellAlignment(REMAINS, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
void AccountPanel::ChangeUser()
@ -224,6 +230,7 @@ void AccountPanel::ShowMonth(int year, int month)
std::map<wxString, wxString>::iterator categoryIt;
//wxGridCellChoiceEditor* categoryEditor, *accountEditor;
int i;
wxBitmap bitmap(_(DELETE_ICON));
_curMonth = month;
_wxUI->SetTitle(user->_name + _(" - ") + months[month] + _(" ") + wxString::Format(wxT("%d"), year));
@ -244,7 +251,9 @@ void AccountPanel::ShowMonth(int year, int month)
_grid->SetCellBackgroundColour(0, i, OWN_CYAN);
_grid->SetCellFont(0, i, font);
_grid->SetReadOnly(0, i, true);
_grid->SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
}
_grid->SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(bitmap));
// SetCellBackgroundColour (int row, int col, const wxColour &colour);
// SetCellFont (int row, int col, const wxFont &font);
// SetCellValue (int row, int col, const wxString &s);
@ -266,7 +275,7 @@ struct operation {
wxString description;
wxString category;
bool fix_cost;
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS};
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, NUMBER_COLS_OPS};
} ;
*/
for (;it->fix_cost && it != _curOperations->end(); it++)
@ -281,7 +290,10 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS
InsertOperation(user, NULL, ++curLine, false);
_grid->AutoSizeColumn(CATEGORY, false);
_grid->AutoSizeColumn(DATE, false);
_grid->AutoSizeColumn(ACCOUNT, false);
_grid->AutoSizeColumn(DELETE, false);
_grid->AutoSizeColumn(VIEW, false);
InitAccountsGrid(user, month, year);
@ -293,6 +305,9 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS
void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix)
{
std::vector<operation>::iterator it;
int curLine, curWeek, week, i;
_grid->InsertRows(line, 1);
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
@ -306,18 +321,13 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
if (fix)
{
_fixCosts++;
SET_ROW_COLOR(line, OWN_YELLOW);
_grid->SetCellValue(line, CATEGORY, _("Fixe"));
_grid->SetReadOnly(line, CATEGORY);
}
else
{
SET_ROW_COLOR(line, OWN_GREEN);
}
if (op)
{
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
_grid->SetCellValue(line, DESCRIPTION, op->description);
_grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
if (op->amount < 0)
@ -327,11 +337,48 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
_grid->SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
if (!fix)
_grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
_grid->SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
_grid->SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
_grid->SetCellRenderer(line, VIEW, new wxGridCellBoolRenderer ());
_grid->SetCellEditor(line, VIEW, new wxGridCellBoolEditor ());
SET_ROW_COLOR(line, user->_preferences._colors[user->GetCategoryName(op->category)]);
}
else
{
_grid->SetCellEditor(line, DATE, new CalendarEditor(1, _curMonth, _curYear));
_grid->SetCellEditor(line, DATE, new CalendarEditor(1, _curMonth, _curYear));
if (fix)
SET_ROW_COLOR(line, OWN_YELLOW)
else
SET_ROW_COLOR(line, OWN_GREEN)
}
_grid->SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
_grid->SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
_grid->SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
_grid->SetCellAlignment(line, VIEW, wxALIGN_CENTRE, wxALIGN_CENTRE);
if (op)
{
for (it = _curOperations->begin(), curLine=1;
it->fix_cost && it != _curOperations->end();
it++, curLine++) ;
if (it == _curOperations->end()) return;
curLine++;
curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
for (i=1, it++; it != _curOperations->end(); it++, curLine++)
{
week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
if (week != curWeek)
{
_grid->SetWeek(i++, curLine);
curWeek = week;
}
}
}
}
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
@ -361,8 +408,12 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
_accountsIndexes[it->first] = i;
_accountsInitValues[it->first] = value;
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE);
}
_accountsGrid->AutoSizeColumns(true);
}
void AccountPanel::UpdateStats()
@ -443,12 +494,15 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
{
User* user = _kiss->GetUser();
int row = event.GetRow()-1;
int col = event.GetCol();
struct operation new_op, cur_op;
int op_complete = 5, i;
wxString value ;
wxDateTime date;
bool need_insertion = false, fix_op=false;
static bool inModification = false ;
wxColour color ;
unsigned char r, g, b;
// Avoid recursives calls
if (inModification) return;
@ -506,11 +560,47 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
op_complete--;
}
if (col == VIEW || col == CATEGORY)
{
color = _grid->GetCellBackgroundColour(event.GetRow(), col);
if (_grid->GetCellValue(event.GetRow(), col) == _("1"))
{
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
color.Set(r, g, b, color.Alpha());
}
else
{
color = user->_preferences._colors[user->GetCategoryName(new_op.category)];
}
SET_ROW_COLOR(event.GetRow(), color);
inModification = false;
if (col == VIEW)
return ;
}
// Penser au fix implosif
// Modify a fix operation
if (row < _fixCosts)
{
cur_op = (*_curOperations)[row] ;
if (col == DELETE)
{
_grid->DeleteRows(event.GetRow(), 1);
_curOperations->erase(_curOperations->begin()+row);
_kiss->DeleteOperation(cur_op);
_grid->_fixCosts = _fixCosts--;
UpdateStats();
inModification = false ;
return ;
}
new_op.id = cur_op.id;
if (cur_op.day != new_op.day)
{
@ -539,6 +629,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
if (i == CATEGORY) continue;
_grid->SetCellValue(event.GetRow(), i, _(""));
}
_kiss->AddOperation(new_op);
}
// Modify an operation
else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
@ -546,6 +637,17 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
row--;
cur_op = (*_curOperations)[row] ;
new_op.id = cur_op.id;
if (col == DELETE)
{
_grid->DeleteRows(event.GetRow(), 1);
_curOperations->erase(_curOperations->begin()+row);
_kiss->DeleteOperation(cur_op);
UpdateStats();
inModification = false ;
return ;
}
if (cur_op.day != new_op.day)
{
need_insertion = true;
@ -570,6 +672,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
{
_grid->SetCellValue(event.GetRow(), i, _(""));
}
_kiss->AddOperation(new_op);
}
if (need_insertion)

View File

@ -7,6 +7,7 @@
#include <wx/pie/pieplot.h>
#include <wx/chartpanel.h>
#include "CalendarEditor.h"
#include "wxGridCellBitmapRenderer.h"
#define OWN_CYAN wxColour(0x99, 0xCC, 0xFF)
#define OWN_YELLOW wxColour(0xFF, 0xFF, 0x99)
@ -16,11 +17,14 @@
#define DEFAULT_FONT_SIZE 12
#define DEFAULT_FONT(font_name) wxFont font_name(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT_NAME);
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS};
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, VIEW, NUMBER_COLS_OPS};
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS};
enum {CALENDAR_TREE_ID=10, OPS_GRID_ID, ACCOUNTS_GRID_ID};
#define DELETE_ICON "ressources/process-stop.png"
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>

0
view/CalendarEditor.cpp Normal file → Executable file
View File

0
view/CalendarEditor.h Normal file → Executable file
View File

View File

@ -13,9 +13,9 @@ public:
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))
row == _week1 ||
row == _week2 ||
row == _week3)
return wxPen(*wxBLACK, 1, wxSOLID);
if (row <= _fixCosts)
@ -24,6 +24,13 @@ public:
return wxPen(OWN_GREEN, 1, wxSOLID);
}
void SetWeek(int week, int line) {
switch (week) {
case 1: _week1 = line; break;
case 2: _week2 = line; break;
case 3: _week3 = line; break;
}
}
int _fixCosts;
int _week1, _week2, _week3;
private: