2010-05-14 15:04:01 +02:00
|
|
|
#include "AccountPanel.h"
|
|
|
|
|
|
|
|
|
|
|
|
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1), _grid(this, -1)
|
|
|
|
{
|
|
|
|
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxChartPanel* chart ;
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
SetSizer(hbox);
|
|
|
|
|
|
|
|
_pie = new PiePlot();
|
|
|
|
_grid.CreateGrid(10, 7);
|
2010-05-16 10:35:34 +02:00
|
|
|
_grid.SetColLabelSize(0);
|
|
|
|
_grid.SetRowLabelSize(0);
|
|
|
|
//_grid.EnableGridLines(false);
|
2010-05-14 15:04:01 +02:00
|
|
|
|
|
|
|
chart = new wxChartPanel(this);
|
|
|
|
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
|
|
|
hbox->Add(&_tree, 0);
|
|
|
|
hbox->Add(&_grid, 0);
|
|
|
|
hbox->Add(chart, 0);
|
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
ChangeUser();
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
Fit();
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
}
|
2010-05-16 10:35:34 +02:00
|
|
|
|
|
|
|
void AccountPanel::ChangeUser()
|
|
|
|
{
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
int curYear;
|
|
|
|
std::map<unsigned int, std::map<unsigned int, std::list<operation> >* >::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));
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadYear(curYear);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccountPanel::LoadYear(int year)
|
|
|
|
{
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
int curMonth = -1;
|
|
|
|
std::map<unsigned int, std::list<operation> >::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccountPanel::ShowMonth(int year, int month)
|
|
|
|
{
|
|
|
|
std::list<operation> operations;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
|
|
|
|
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
|
|
|
|
|
|
|
|
// Operations are ordered
|
|
|
|
operations = (*user->_operations[year])[month];
|
|
|
|
|
|
|
|
_grid.CreateGrid(10, 7);
|
|
|
|
// Creating headers
|
|
|
|
_grid.SetColSize (0, _grid.GetColSize(0)*4);
|
|
|
|
// 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)
|
|
|
|
Fit();
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
}
|
|
|
|
|