|
|
|
@ -6,31 +6,57 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
int i ;
|
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
|
std::map<wxString, Account>::iterator accountIt;
|
|
|
|
|
std::map<wxString, wxString>::iterator it;
|
|
|
|
|
wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86),
|
|
|
|
|
wxColour(0xFF, 0x3E, 0x0E),
|
|
|
|
|
wxColour(0xFF, 0xD3, 0x20),
|
|
|
|
|
wxColour(0x58, 0x9D, 0x1B),
|
|
|
|
|
wxColour(0x7E, 0x00, 0x21),
|
|
|
|
|
wxColour(0x83, 0xCC, 0xFF),
|
|
|
|
|
wxColour(0x31, 0x40, 0x04),
|
|
|
|
|
wxColour(0xB0, 0xCF, 0x00),
|
|
|
|
|
wxColour(0x4B, 0x1F, 0x6F),
|
|
|
|
|
wxColour(0xFF, 0x93, 0x0E),
|
|
|
|
|
wxColour(0xC5, 0x00, 0x0D),
|
|
|
|
|
wxColour(0x00, 0x84, 0xD1)};
|
|
|
|
|
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));
|
|
|
|
|
ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors));
|
|
|
|
|
|
|
|
|
|
// set legend
|
|
|
|
|
_pie->SetLegend(new Legend(wxCENTER, wxTOP));
|
|
|
|
|
_pie = new PiePlot();
|
|
|
|
|
|
|
|
|
|
_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;
|
|
|
|
|
|
|
|
|
|
_categories = new wxString[user->GetCategoriesNumber()+1] ;
|
|
|
|
|
_categories[0] = _("Unknown");
|
|
|
|
|
_categoriesIndexes[_("Unknown")] = 0;
|
|
|
|
|
for(i=1, it = user->_preferences._categories.begin(); it != user->_preferences._categories.end(); it++, i++)
|
|
|
|
|
{
|
|
|
|
|
_categories[i] = it->second ;
|
|
|
|
|
_categoriesIndexes[it->second] = i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber()+1);
|
|
|
|
|
|
|
|
|
|
_categoriesValues = new double[user->GetCategoriesNumber()+1];
|
|
|
|
|
for(i=0; i<user->GetCategoriesNumber()+1; i++)
|
|
|
|
|
_categoriesValues[i] = 1.0;
|
|
|
|
|
|
|
|
|
|
_dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber()+1);
|
|
|
|
|
_dataset->SetRenderer(new CategoryRenderer(*colorScheme));
|
|
|
|
|
_pie->SetDataset(_dataset);
|
|
|
|
|
_pie->SetColorScheme(colorScheme);
|
|
|
|
|
|
|
|
|
|
_pie->SetLegend(new Legend(wxBOTTOM, wxCENTER));
|
|
|
|
|
|
|
|
|
|
_grid = new GridAccount(this, -1);
|
|
|
|
|
_grid->CreateGrid(1, NUMBER_COLS);
|
|
|
|
@ -41,7 +67,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|
|
|
|
chart->Fit();
|
|
|
|
|
chart->Layout();
|
|
|
|
|
chart->SetMinSize(// chart->GetSize()
|
|
|
|
|
wxSize(200,200));
|
|
|
|
|
wxSize(200,500));
|
|
|
|
|
hbox->Add(&_tree, 0);
|
|
|
|
|
hbox->Add(_grid, 0);
|
|
|
|
|
hbox->Add(chart, 0);
|
|
|
|
@ -52,6 +78,13 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccountPanel::~AccountPanel()
|
|
|
|
|
{
|
|
|
|
|
delete[] _categoriesValues;
|
|
|
|
|
delete[] _categories;
|
|
|
|
|
delete[] _accounts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountPanel::ChangeUser()
|
|
|
|
|
{
|
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
@ -79,7 +112,8 @@ void AccountPanel::LoadYear(int year)
|
|
|
|
|
wxDateTime curDate;
|
|
|
|
|
wxTreeItemId parentNode, curMonthNode;
|
|
|
|
|
|
|
|
|
|
if (user->_operations[year] != NULL)
|
|
|
|
|
_curYear = year ;
|
|
|
|
|
if (user->_operations[year] != NULL)
|
|
|
|
|
{
|
|
|
|
|
ShowMonth(year, 0);
|
|
|
|
|
return;
|
|
|
|
@ -108,7 +142,7 @@ void AccountPanel::LoadYear(int year)
|
|
|
|
|
|
|
|
|
|
_tree.Expand(parentNode);
|
|
|
|
|
_tree.SelectItem(curMonthNode, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowMonth(year, curMonth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,15 +160,14 @@ void AccountPanel::ShowMonth(int year, int month)
|
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
|
wxFont font(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT);
|
|
|
|
|
std::map<wxString, wxString>::iterator categoryIt;
|
|
|
|
|
std::map<wxString, Account>::iterator accountIt;
|
|
|
|
|
wxGridCellChoiceEditor* categoryEditor, *accountEditor;
|
|
|
|
|
wxString* categories, *accounts;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
_curMonth = month;
|
|
|
|
|
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
|
|
|
|
|
|
|
|
|
|
// Operations are ordered
|
|
|
|
|
operations = (*user->_operations[year])[month];
|
|
|
|
|
_curOperations = &((*user->_operations[year])[month]);
|
|
|
|
|
|
|
|
|
|
_grid->CreateGrid(1, NUMBER_COLS);
|
|
|
|
|
// Creating headers
|
|
|
|
@ -158,24 +191,7 @@ void AccountPanel::ShowMonth(int year, int month)
|
|
|
|
|
// 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();
|
|
|
|
|
it = _curOperations->begin();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
struct operation {
|
|
|
|
@ -199,16 +215,15 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|
|
|
|
_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));
|
|
|
|
|
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -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->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount));
|
|
|
|
|
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()+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);
|
|
|
|
|
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
|
|
|
|
|
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
|
|
|
|
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
|
|
|
|
|
it++;
|
|
|
|
@ -217,16 +232,16 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|
|
|
|
_grid->AppendRows();
|
|
|
|
|
curLine++;
|
|
|
|
|
SET_ROW_COLOR(curLine, OWN_YELLOW);
|
|
|
|
|
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
|
|
|
|
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, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
|
|
|
|
|
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
|
|
|
|
|
|
|
|
|
_grid->_fixCosts = ++fixCosts;
|
|
|
|
|
|
|
|
|
|
for (; it != operations.begin(); it++)
|
|
|
|
|
for (; it != _curOperations->begin(); it++)
|
|
|
|
|
{
|
|
|
|
|
_grid->AppendRows();
|
|
|
|
|
curLine++;
|
|
|
|
@ -234,16 +249,15 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|
|
|
|
_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));
|
|
|
|
|
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -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->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount));
|
|
|
|
|
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()+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);
|
|
|
|
|
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
|
|
|
|
|
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
|
|
|
|
|
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
|
|
|
|
|
it++;
|
|
|
|
@ -252,20 +266,41 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
|
|
|
|
_grid->AppendRows();
|
|
|
|
|
curLine++;
|
|
|
|
|
SET_ROW_COLOR(curLine, OWN_GREEN);
|
|
|
|
|
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
|
|
|
|
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, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
UpdateChart();
|
|
|
|
|
|
|
|
|
|
Fit();
|
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccountPanel::UpdateChart()
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
|
std::list<operation>::iterator it;
|
|
|
|
|
|
|
|
|
|
//_dataset->BeginUpdate();
|
|
|
|
|
for (i=0; i<user->GetCategoriesNumber(); 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";
|
|
|
|
|
}
|
|
|
|
|
//_dataset->EndUpdate();
|
|
|
|
|
_pie->DatasetChanged(_dataset);
|
|
|
|
|
}
|
|
|
|
|