2010-05-14 15:04:01 +02:00
|
|
|
#include "AccountPanel.h"
|
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _("")};
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
|
|
|
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
wxChartPanel* chart ;
|
2010-05-24 20:14:15 +02:00
|
|
|
double data[] = {1.0, 2.0, 3.0} ;
|
|
|
|
wxString cats[] = {_("cat1"), _("cat2"), _("cat3")};
|
|
|
|
wxColour colours[] = {OWN_CYAN, OWN_YELLOW, OWN_GREEN} ;
|
|
|
|
double value;
|
2010-05-14 15:04:01 +02:00
|
|
|
SetSizer(hbox);
|
|
|
|
|
|
|
|
_pie = new PiePlot();
|
2010-05-24 20:14:15 +02:00
|
|
|
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));
|
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
_grid = new GridAccount(this, -1);
|
|
|
|
_grid->CreateGrid(1, NUMBER_COLS);
|
|
|
|
_grid->SetColLabelSize(0);
|
|
|
|
_grid->SetRowLabelSize(0);
|
2010-05-14 15:04:01 +02:00
|
|
|
chart = new wxChartPanel(this);
|
|
|
|
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
2010-05-24 20:14:15 +02:00
|
|
|
chart->Fit();
|
|
|
|
chart->Layout();
|
|
|
|
chart->SetMinSize(// chart->GetSize()
|
|
|
|
wxSize(200,200));
|
2010-05-14 15:04:01 +02:00
|
|
|
hbox->Add(&_tree, 0);
|
2010-05-16 20:09:18 +02:00
|
|
|
hbox->Add(_grid, 0);
|
2010-05-14 15:04:01 +02:00
|
|
|
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();
|
2010-05-24 20:14:15 +02:00
|
|
|
int curYear = -1;
|
2010-05-16 10:35:34 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2010-05-24 20:14:15 +02:00
|
|
|
if (curYear != -1)
|
|
|
|
LoadYear(curYear);
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS; i++) \
|
|
|
|
{\
|
|
|
|
_grid->SetCellBackgroundColour(row, i, color);\
|
|
|
|
}
|
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
void AccountPanel::ShowMonth(int year, int month)
|
|
|
|
{
|
|
|
|
std::list<operation> operations;
|
2010-05-16 20:09:18 +02:00
|
|
|
std::list<operation>::iterator it;
|
|
|
|
int fixCosts = 0;
|
|
|
|
int curLine = 0;
|
2010-05-16 10:35:34 +02:00
|
|
|
User* user = _kiss->GetUser();
|
2010-05-16 20:09:18 +02:00
|
|
|
wxFont font(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT);
|
2010-05-24 20:14:15 +02:00
|
|
|
std::map<wxString, wxString>::iterator categoryIt;
|
|
|
|
std::map<wxString, Account>::iterator accountIt;
|
|
|
|
wxGridCellChoiceEditor* categoryEditor, *accountEditor;
|
|
|
|
wxString* categories, *accounts;
|
2010-05-16 20:09:18 +02:00
|
|
|
int i;
|
2010-05-16 10:35:34 +02:00
|
|
|
|
|
|
|
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
|
|
|
|
|
|
|
|
// Operations are ordered
|
|
|
|
operations = (*user->_operations[year])[month];
|
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
_grid->CreateGrid(1, NUMBER_COLS);
|
2010-05-16 10:35:34 +02:00
|
|
|
// Creating headers
|
2010-05-16 20:09:18 +02:00
|
|
|
_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);
|
|
|
|
}
|
2010-05-16 10:35:34 +02:00
|
|
|
// 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)
|
2010-05-16 20:09:18 +02:00
|
|
|
|
|
|
|
categories = new wxString[user->_preferences._categories.size()+1];
|
2010-05-24 20:14:15 +02:00
|
|
|
categories[0] = _("Unknown");
|
2010-05-16 20:09:18 +02:00
|
|
|
for (i=1,
|
|
|
|
categoryIt = user->_preferences._categories.begin();
|
|
|
|
categoryIt != user->_preferences._categories.end();
|
2010-05-24 20:14:15 +02:00
|
|
|
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;
|
|
|
|
|
2010-05-16 20:09:18 +02:00
|
|
|
|
|
|
|
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);
|
2010-05-24 20:14:15 +02:00
|
|
|
_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));
|
2010-05-16 20:09:18 +02:00
|
|
|
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());
|
2010-05-24 20:14:15 +02:00
|
|
|
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
|
|
|
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
|
|
|
_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);
|
2010-05-24 20:14:15 +02:00
|
|
|
_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));
|
2010-05-16 20:09:18 +02:00
|
|
|
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());
|
2010-05-24 20:14:15 +02:00
|
|
|
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, accounts, false);
|
|
|
|
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
|
|
|
delete[] categories;
|
2010-05-24 20:14:15 +02:00
|
|
|
delete[] accounts;
|
|
|
|
|
|
|
|
_grid->AutoSizeColumn(CATEGORY, false);
|
|
|
|
_grid->AutoSizeColumn(ACCOUNT, false);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
Fit();
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
}
|
|
|
|
|