diff --git a/init.sql b/init.sql index 4a00ddc..ef7e4b3 100644 --- a/init.sql +++ b/init.sql @@ -13,8 +13,9 @@ INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "na 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", "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 operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "4", "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", "4", "1", "-56", "Opé 2", "1", "0"); +INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("2", "0", "0", "2010", "4", "29", "-2056", "Opé 3", "2", "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"); diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 5fc74fa..8f61fe0 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -5,11 +5,13 @@ static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1) { wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxChartPanel* chart ; int i ; User* user = _kiss->GetUser(); std::map::iterator accountIt; std::map::iterator it; + DEFAULT_FONT(font); wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86), wxColour(0xFF, 0x3E, 0x0E), wxColour(0xFF, 0xD3, 0x20), @@ -49,7 +51,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _categoriesValues = new double[user->GetCategoriesNumber()+1]; for(i=0; iGetCategoriesNumber()+1; i++) - _categoriesValues[i] = 1.0; + _categoriesValues[i] = 0.0; _dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber()+1); _dataset->SetRenderer(new CategoryRenderer(*colorScheme)); @@ -62,15 +64,46 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _grid->CreateGrid(1, NUMBER_COLS); _grid->SetColLabelSize(0); _grid->SetRowLabelSize(0); + + _statsGrid = new wxGrid(this, -1); + _statsGrid->CreateGrid(user->GetCategoriesNumber()+1+6, 2); + _statsGrid->SetColLabelSize(0); + _statsGrid->SetRowLabelSize(0); + _statsGrid->EnableEditing(false); + + _statsGrid->SetDefaultCellFont(font); + + _statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit")); + _statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit")); + + _statsGrid->AutoSizeColumn(0, false); + + for(i=0; iGetCategoriesNumber()+1; i++) + _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]); + + font.SetWeight(wxFONTWEIGHT_BOLD); + _statsGrid->SetCellFont(CUR_CREDIT, 0, font); + _statsGrid->SetCellFont(CUR_DEBIT, 0, font); + _statsGrid->SetCellFont(REMAINS, 0, font); + _statsGrid->SetCellFont(REMAINS, 1, font); + + _statsGrid->SetCellValue(CUR_CREDIT, 0, _("Cur Credit")); + _statsGrid->SetCellValue(CUR_DEBIT, 0, _("Cur Debit")); + _statsGrid->SetCellValue(REMAINS, 0, _("Remains")); + chart = new wxChartPanel(this); chart->SetChart(new Chart(_pie, _("Cost repartition"))); chart->Fit(); chart->Layout(); chart->SetMinSize(// chart->GetSize() - wxSize(200,500)); + wxSize(200,250)); hbox->Add(&_tree, 0); hbox->Add(_grid, 0); - hbox->Add(chart, 0); + vbox->Add(_statsGrid, 0); + vbox->Add(-1, 10); + vbox->Add(chart, 0); + hbox->Add(-1, 10); + hbox->Add(vbox, 0); ChangeUser(); @@ -158,7 +191,7 @@ void AccountPanel::ShowMonth(int year, int month) int fixCosts = 0; int curLine = 0; User* user = _kiss->GetUser(); - wxFont font(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT); + DEFAULT_FONT(font); std::map::iterator categoryIt; wxGridCellChoiceEditor* categoryEditor, *accountEditor; int i; @@ -206,7 +239,7 @@ struct operation { enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS}; } ; */ - while (it->fix_cost) + for (;it->fix_cost && it != _curOperations->end(); it++) { _grid->AppendRows(); curLine++; @@ -226,7 +259,6 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS}; accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); - it++; } _grid->AppendRows(); @@ -241,7 +273,7 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS}; _grid->_fixCosts = ++fixCosts; - for (; it != _curOperations->begin(); it++) + for (; it != _curOperations->end(); it++) { _grid->AppendRows(); curLine++; @@ -260,7 +292,6 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS}; accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); - it++; } _grid->AppendRows(); @@ -276,31 +307,55 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS}; _grid->AutoSizeColumn(CATEGORY, false); _grid->AutoSizeColumn(ACCOUNT, false); - UpdateChart(); + UpdateStats(); Fit(); SetMinSize(GetSize()); } -void AccountPanel::UpdateChart() +void AccountPanel::UpdateStats() { int i; User* user = _kiss->GetUser(); std::list::iterator it; + double curCredit, curDebit, totalCredit, totalDebit, remains; + wxDateTime curDate; - //_dataset->BeginUpdate(); - for (i=0; iGetCategoriesNumber(); i++) + curDate.SetToCurrent(); + + curCredit = curDebit = totalCredit = totalDebit = 0.0; + + for (i=0; iGetCategoriesNumber()+1; i++) _categoriesValues[i] = 0.0; - // _categoriesValues[0] += 1.0; - // _categoriesValues[1] += 2.0; - // _categoriesValues[2] += 3.0; for (it=_curOperations->begin(); it!=_curOperations->end(); it++) { if (it->amount > 0) - _categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += it->amount ; - //std::cout << _categoriesValues[_categoriesIndexes[it->category]] << "\n"; + { + if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year) + curCredit += it->amount; + totalCredit += it->amount; + } + else + { + _categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ; + if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year) + curDebit += -it->amount; + totalDebit += -it->amount; + } } - //_dataset->EndUpdate(); + + remains = totalCredit - totalDebit; + _statsGrid->SetCellValue(CUR_CREDIT, 1, wxString::Format(wxT("%.2lf"), curCredit)); + _statsGrid->SetCellValue(CUR_DEBIT, 1, wxString::Format(wxT("%.2lf"), curDebit)); + _statsGrid->SetCellValue(TOTAL_CREDIT, 1, wxString::Format(wxT("%.2lf"), totalCredit)); + _statsGrid->SetCellValue(TOTAL_DEBIT, 1, wxString::Format(wxT("%.2lf"), totalDebit)); + + _statsGrid->SetCellTextColour(REMAINS, 1, (remains >= 0) ? wxColor(0x00, 0xFF, 0x00) : wxColor(0xFF, 0x00, 0x00)); + _statsGrid->SetCellValue(REMAINS, 1, wxString::Format(wxT("%.2lf"), remains)); + + for(i=0; iGetCategoriesNumber()+1; i++) + _statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf"), _categoriesValues[i])); + _pie->DatasetChanged(_dataset); } diff --git a/view/AccountPanel.h b/view/AccountPanel.h index 552c908..0e76a2e 100644 --- a/view/AccountPanel.h +++ b/view/AccountPanel.h @@ -11,10 +11,12 @@ #define OWN_YELLOW wxColour(0xFF, 0xFF, 0x99) #define OWN_GREEN wxColour(0x3D, 0xEB, 0x3D) -#define DEFAULT_FONT _("Liberation Sans") +#define DEFAULT_FONT_NAME _("Liberation Sans") #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}; +enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS}; #include #include "wxUI.h" @@ -39,6 +41,7 @@ private: wxUI* _wxUI; wxTreeCtrl _tree; GridAccount* _grid; + wxGrid *_statsGrid; PiePlot* _pie; double *_categoriesValues; std::map _categoriesIndexes; @@ -47,7 +50,7 @@ private: wxString* _categories, *_accounts; CategorySimpleDataset* _dataset; - void UpdateChart(); + void UpdateStats(); }; #endif