#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) { 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); ChangeUser(); Fit(); SetMinSize(GetSize()); } void AccountPanel::ChangeUser() { User* user = _kiss->GetUser(); int curYear = -1; std::map >* >::iterator it; wxDateTime curDate; curDate.SetToCurrent(); for(it = user->_operations.begin(); it != user->_operations.end(); it++) { if ((int)it->first <= curDate.GetYear()) curYear = it->first; _tree.AddRoot(wxString::Format(wxT("%d"), it->first)); } if (curYear != -1) LoadYear(curYear); } void AccountPanel::LoadYear(int year) { User* user = _kiss->GetUser(); int curMonth = -1; std::map >::iterator it; wxDateTime curDate; wxTreeItemId parentNode, curMonthNode; if (user->_operations[year] != NULL) { ShowMonth(year, 0); return; } _kiss->LoadYear(year); curDate.SetToCurrent(); parentNode = _tree.GetSelection(); for (it = user->_operations[year]->begin(); it != user->_operations[year]->end(); it++) { if (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth()) { curMonth = it->first; curMonthNode = _tree.AppendItem(parentNode, months[it->first]); } else if(curMonth == -1) { curMonthNode = _tree.AppendItem(parentNode, months[it->first]); curMonth++; } else _tree.AppendItem(parentNode, months[it->first]); } _tree.Expand(parentNode); _tree.SelectItem(curMonthNode, true); ShowMonth(year, curMonth); } #define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color);\ } void AccountPanel::ShowMonth(int year, int month) { std::list operations; std::list::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::map::iterator categoryIt; std::map::iterator accountIt; wxGridCellChoiceEditor* categoryEditor, *accountEditor; wxString* categories, *accounts; int i; _wxUI->SetTitle(user->_name + _(" - ") + months[month]); // Operations are ordered operations = (*user->_operations[year])[month]; _grid->CreateGrid(1, NUMBER_COLS); // Creating headers _grid->SetColSize (0, _grid->GetColSize(0)*3); _grid->SetDefaultCellFont(font); font.SetWeight(wxFONTWEIGHT_BOLD); for(i=0; iSetCellValue(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); // GetColSize (int col) const ; // SetColSize (int col, int width); // 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] = 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; 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, 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++; } _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()); accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false); _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); _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, 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++; } _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()); 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()); }