2010-05-14 15:04:01 +02:00
|
|
|
#include "AccountPanel.h"
|
|
|
|
|
2010-06-21 10:53:43 +02:00
|
|
|
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS};
|
|
|
|
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
|
|
|
|
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS};
|
2010-06-23 14:25:00 +02:00
|
|
|
enum {CALENDAR_TREE_ID=10, OPS_GRID_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID};
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2010-06-16 17:29:07 +02:00
|
|
|
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _(""), _("")};
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
|
2010-06-22 15:51:51 +02:00
|
|
|
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
|
|
|
|
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, AccountPanel::OnAccountModified)
|
|
|
|
EVT_TREE_ITEM_RIGHT_CLICK(CALENDAR_TREE_ID, AccountPanel::OnTreeRightClick)
|
|
|
|
EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
|
|
|
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
2010-06-23 14:25:00 +02:00
|
|
|
EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
|
|
|
|
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
|
2010-06-27 21:39:49 +02:00
|
|
|
EVT_SHOW(AccountPanel::OnShow)
|
2010-06-02 22:14:11 +02:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _curMonth(-1), _curYear(-1), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
|
|
|
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
2010-05-27 22:32:35 +02:00
|
|
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
2010-06-02 22:14:11 +02:00
|
|
|
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
2010-05-14 15:04:01 +02:00
|
|
|
wxChartPanel* chart ;
|
2010-05-27 21:09:02 +02:00
|
|
|
int i ;
|
2010-06-02 22:14:11 +02:00
|
|
|
DEFAULT_FONT(font);
|
2010-05-27 21:09:02 +02:00
|
|
|
User* user = _kiss->GetUser();
|
2010-06-21 13:02:02 +02:00
|
|
|
std::vector<Account>::iterator accountIt;
|
2010-06-22 12:29:36 +02:00
|
|
|
std::vector<category>::iterator categoryIt;
|
2010-05-27 21:09:02 +02:00
|
|
|
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)};
|
2010-06-22 15:51:51 +02:00
|
|
|
wxBitmap bitmap(_(DELETE_ICON));
|
2010-05-14 15:04:01 +02:00
|
|
|
SetSizer(hbox);
|
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors));
|
|
|
|
|
2010-05-14 15:04:01 +02:00
|
|
|
_pie = new PiePlot();
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
_accounts = new wxString[user->GetAccountsNumber()];
|
2010-06-12 15:01:58 +02:00
|
|
|
for (i=0,
|
2010-05-27 21:09:02 +02:00
|
|
|
accountIt = user->_accounts.begin();
|
|
|
|
accountIt != user->_accounts.end();
|
|
|
|
accountIt++, i++)
|
2010-06-21 13:02:02 +02:00
|
|
|
_accounts[i] = accountIt->name;
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
_categories = new wxString[user->GetCategoriesNumber()] ;
|
2010-06-22 12:29:36 +02:00
|
|
|
for(i=0, categoryIt = user->_preferences._categories.begin();
|
|
|
|
categoryIt != user->_preferences._categories.end();
|
|
|
|
categoryIt++, i++)
|
2010-05-27 21:09:02 +02:00
|
|
|
{
|
2010-06-22 12:29:36 +02:00
|
|
|
_categories[i] = categoryIt->name ;
|
|
|
|
_categoriesIndexes[categoryIt->name] = i;
|
2010-05-27 21:09:02 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
_dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber());
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
_categoriesValues = new double[user->GetCategoriesNumber()];
|
|
|
|
for(i=0; i<user->GetCategoriesNumber(); i++)
|
2010-05-27 22:32:35 +02:00
|
|
|
_categoriesValues[i] = 0.0;
|
2010-05-24 20:14:15 +02:00
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
_dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber());
|
2010-05-27 21:09:02 +02:00
|
|
|
_dataset->SetRenderer(new CategoryRenderer(*colorScheme));
|
|
|
|
_pie->SetDataset(_dataset);
|
|
|
|
_pie->SetColorScheme(colorScheme);
|
2010-05-24 20:14:15 +02:00
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
_pie->SetLegend(new Legend(wxBOTTOM, wxCENTER));
|
2010-05-24 20:14:15 +02:00
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
_grid = new GridAccount(this, OPS_GRID_ID);
|
|
|
|
_grid->CreateGrid(1, NUMBER_COLS_OPS);
|
2010-05-16 20:09:18 +02:00
|
|
|
_grid->SetColLabelSize(0);
|
|
|
|
_grid->SetRowLabelSize(0);
|
2010-05-27 22:32:35 +02:00
|
|
|
|
2010-06-22 15:51:51 +02:00
|
|
|
_grid->CreateGrid(1, NUMBER_COLS_OPS);
|
|
|
|
_grid->SetColSize (0, _grid->GetColSize(0)*3);
|
|
|
|
_grid->SetDefaultCellFont(font);
|
|
|
|
|
|
|
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
for(i=0; i<NUMBER_COLS_OPS; i++)
|
|
|
|
{
|
|
|
|
_grid->SetCellValue(0, i, colsName[i]);
|
|
|
|
_grid->SetCellBackgroundColour(0, i, OWN_CYAN);
|
|
|
|
_grid->SetCellFont(0, i, font);
|
|
|
|
_grid->SetReadOnly(0, i, true);
|
|
|
|
_grid->SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
|
|
|
}
|
|
|
|
_grid->SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(bitmap));
|
|
|
|
|
|
|
|
font.SetWeight(wxFONTWEIGHT_NORMAL);
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
_accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID);
|
|
|
|
_accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNTS);
|
|
|
|
_accountsGrid->SetRowLabelSize(0);
|
|
|
|
|
|
|
|
_accountsGrid->SetDefaultCellFont(font);
|
|
|
|
|
|
|
|
_accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Account number"));
|
|
|
|
_accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Account name"));
|
|
|
|
_accountsGrid->SetColLabelValue(ACCOUNT_INIT, _("Initial value"));
|
|
|
|
_accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value"));
|
|
|
|
_accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value"));
|
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
_accountsGrid->AutoSizeColumns(true);
|
2010-05-27 22:32:35 +02:00
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
_statsGrid = new wxGrid(this, -1);
|
2010-05-27 22:32:35 +02:00
|
|
|
|
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()
|
2010-05-27 22:32:35 +02:00
|
|
|
wxSize(200,250));
|
2010-05-14 15:04:01 +02:00
|
|
|
hbox->Add(&_tree, 0);
|
2010-06-02 22:14:11 +02:00
|
|
|
vbox2->Add(_accountsGrid, 0);
|
|
|
|
vbox2->Add(-1, 10);
|
|
|
|
vbox2->Add(_grid, 0);
|
|
|
|
hbox->Add(vbox2, 0);
|
2010-05-27 22:32:35 +02:00
|
|
|
vbox->Add(_statsGrid, 0);
|
|
|
|
vbox->Add(-1, 10);
|
|
|
|
vbox->Add(chart, 0);
|
|
|
|
hbox->Add(-1, 10);
|
|
|
|
hbox->Add(vbox, 0);
|
2010-05-14 15:04:01 +02:00
|
|
|
|
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
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
AccountPanel::~AccountPanel()
|
|
|
|
{
|
|
|
|
delete[] _categoriesValues;
|
|
|
|
delete[] _categories;
|
|
|
|
delete[] _accounts;
|
|
|
|
}
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
void AccountPanel::InitStatsGrid(User* user)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DEFAULT_FONT(font);
|
|
|
|
|
2010-06-22 15:51:51 +02:00
|
|
|
if (!_statsGrid->GetNumberRows())
|
|
|
|
{
|
|
|
|
_statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2);
|
|
|
|
_statsGrid->SetColLabelSize(0);
|
|
|
|
_statsGrid->SetRowLabelSize(0);
|
|
|
|
_statsGrid->EnableEditing(false);
|
|
|
|
}
|
|
|
|
else
|
2010-06-27 21:39:49 +02:00
|
|
|
{
|
|
|
|
_statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
|
|
|
|
_statsGrid->InsertRows(0, user->GetCategoriesNumber()+6);
|
|
|
|
}
|
2010-06-22 15:51:51 +02:00
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
_statsGrid->SetDefaultCellFont(font);
|
|
|
|
|
|
|
|
_statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit"));
|
|
|
|
_statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit"));
|
|
|
|
|
|
|
|
_statsGrid->AutoSizeColumn(0, false);
|
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
for(i=0; i<user->GetCategoriesNumber(); i++)
|
2010-06-16 17:29:07 +02:00
|
|
|
{
|
|
|
|
_statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]);
|
|
|
|
_statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
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"));
|
2010-06-16 17:29:07 +02:00
|
|
|
|
|
|
|
_statsGrid->SetCellAlignment(CUR_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_statsGrid->SetCellAlignment(CUR_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_statsGrid->SetCellAlignment(TOTAL_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_statsGrid->SetCellAlignment(TOTAL_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_statsGrid->SetCellAlignment(REMAINS, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
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-06-03 18:28:38 +02:00
|
|
|
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* >::iterator it;
|
2010-05-16 10:35:34 +02:00
|
|
|
wxDateTime curDate;
|
2010-06-22 20:46:30 +02:00
|
|
|
wxTreeItemId rootNode, curNode;
|
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
InitStatsGrid(user);
|
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
_tree.DeleteAllItems();
|
|
|
|
rootNode = _tree.AddRoot(_(""));
|
2010-05-16 10:35:34 +02:00
|
|
|
|
|
|
|
curDate.SetToCurrent();
|
|
|
|
for(it = user->_operations.begin(); it != user->_operations.end(); it++)
|
|
|
|
{
|
|
|
|
if ((int)it->first <= curDate.GetYear())
|
2010-06-22 20:46:30 +02:00
|
|
|
{
|
|
|
|
curYear = it->first;
|
|
|
|
curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-05-24 20:14:15 +02:00
|
|
|
if (curYear != -1)
|
2010-06-22 20:46:30 +02:00
|
|
|
{
|
|
|
|
_tree.SelectItem(curNode, true);
|
|
|
|
LoadYear(curYear);
|
|
|
|
}
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
void AccountPanel::LoadYear(int year, bool showMonth)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
int curMonth = -1;
|
|
|
|
wxDateTime curDate;
|
|
|
|
wxTreeItemId parentNode, curMonthNode;
|
2010-06-23 20:30:42 +02:00
|
|
|
std::map<int, std::vector<int> > ops ;
|
|
|
|
std::vector<int>::iterator it;
|
2010-06-23 19:32:42 +02:00
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
if (user->_operations[year])
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-06-22 20:46:30 +02:00
|
|
|
if (showMonth)
|
2010-06-23 19:32:42 +02:00
|
|
|
ShowMonth(-1, year);
|
2010-05-16 10:35:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
_curYear = year ;
|
2010-05-16 10:35:34 +02:00
|
|
|
_kiss->LoadYear(year);
|
2010-06-23 20:30:42 +02:00
|
|
|
ops = _kiss->GetAllOperations();
|
2010-05-16 10:35:34 +02:00
|
|
|
|
|
|
|
curDate.SetToCurrent();
|
|
|
|
parentNode = _tree.GetSelection();
|
|
|
|
|
2010-06-23 20:30:42 +02:00
|
|
|
for (it = ops[year].begin(); it != ops[year].end(); it++)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-06-23 20:30:42 +02:00
|
|
|
if (curMonth == -1 || (year == curDate.GetYear() && *it <= curDate.GetMonth()))
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-06-23 20:30:42 +02:00
|
|
|
curMonth = *it;
|
|
|
|
curMonthNode = _tree.AppendItem(parentNode, months[*it]);
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
else
|
2010-06-23 20:30:42 +02:00
|
|
|
_tree.AppendItem(parentNode, months[*it]);
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_tree.Expand(parentNode);
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
if (showMonth)
|
|
|
|
{
|
|
|
|
_tree.SelectItem(curMonthNode, true);
|
2010-06-23 19:32:42 +02:00
|
|
|
ShowMonth(curMonth, year);
|
2010-06-22 20:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_wxUI->Layout();
|
2010-05-16 10:35:34 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
2010-05-16 20:09:18 +02:00
|
|
|
{\
|
|
|
|
_grid->SetCellBackgroundColour(row, i, color);\
|
|
|
|
}
|
|
|
|
|
2010-06-23 19:32:42 +02:00
|
|
|
void AccountPanel::ShowMonth(int month, int year)
|
2010-05-16 10:35:34 +02:00
|
|
|
{
|
2010-06-03 18:28:38 +02:00
|
|
|
std::vector<operation> operations;
|
|
|
|
std::vector<operation>::iterator it;
|
2010-06-02 22:14:11 +02:00
|
|
|
_fixCosts = 0;
|
2010-05-16 20:09:18 +02:00
|
|
|
int curLine = 0;
|
2010-05-16 10:35:34 +02:00
|
|
|
User* user = _kiss->GetUser();
|
2010-05-27 22:32:35 +02:00
|
|
|
DEFAULT_FONT(font);
|
2010-06-22 12:29:36 +02:00
|
|
|
std::vector<category>::iterator categoryIt;
|
2010-06-22 20:46:30 +02:00
|
|
|
std::map<unsigned int, std::vector<operation> >::iterator monthIt;
|
|
|
|
wxDateTime curDate;
|
|
|
|
curDate.SetToCurrent();
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
if (month == -1)
|
|
|
|
{
|
|
|
|
// Near month
|
|
|
|
if (year == curDate.GetYear())
|
|
|
|
{
|
|
|
|
for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++)
|
|
|
|
{
|
|
|
|
if ((int)monthIt->first <= curDate.GetMonth())
|
|
|
|
{
|
|
|
|
month = monthIt->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// First month
|
|
|
|
if (month == -1)
|
|
|
|
{
|
|
|
|
monthIt = user->_operations[year]->begin();
|
|
|
|
month = monthIt->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_curYear = year;
|
2010-05-27 21:09:02 +02:00
|
|
|
_curMonth = month;
|
2010-06-02 22:14:11 +02:00
|
|
|
_wxUI->SetTitle(user->_name + _(" - ") + months[month] + _(" ") + wxString::Format(wxT("%d"), year));
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-06-22 15:51:51 +02:00
|
|
|
if (_grid->GetNumberRows() > 1)
|
|
|
|
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
// Operations are ordered
|
2010-05-27 21:09:02 +02:00
|
|
|
_curOperations = &((*user->_operations[year])[month]);
|
2010-05-16 10:35:34 +02:00
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
it = _curOperations->begin();
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-06-22 20:46:30 +02:00
|
|
|
for (;it != _curOperations->end() && it->fix_cost; it++)
|
2010-06-10 19:15:25 +02:00
|
|
|
InsertOperation(user, &(*it), ++curLine, true);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
InsertOperation(user, NULL, ++curLine, true);
|
|
|
|
_grid->_fixCosts = _fixCosts--;
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-05-27 22:32:35 +02:00
|
|
|
for (; it != _curOperations->end(); it++)
|
2010-06-10 19:15:25 +02:00
|
|
|
InsertOperation(user, &(*it), ++curLine, false);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
InsertOperation(user, NULL, ++curLine, false);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-05-24 20:14:15 +02:00
|
|
|
_grid->AutoSizeColumn(CATEGORY, false);
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->AutoSizeColumn(DATE, false);
|
2010-05-24 20:14:15 +02:00
|
|
|
_grid->AutoSizeColumn(ACCOUNT, false);
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->AutoSizeColumn(DELETE, false);
|
2010-06-16 19:15:49 +02:00
|
|
|
_grid->AutoSizeColumn(CHECKED, false);
|
2010-05-16 20:09:18 +02:00
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
InitAccountsGrid(user, month, year);
|
|
|
|
|
2010-05-27 22:32:35 +02:00
|
|
|
UpdateStats();
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-05-16 10:35:34 +02:00
|
|
|
Fit();
|
|
|
|
SetMinSize(GetSize());
|
|
|
|
}
|
|
|
|
|
2010-06-05 14:33:19 +02:00
|
|
|
void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix)
|
|
|
|
{
|
2010-06-16 17:29:07 +02:00
|
|
|
std::vector<operation>::iterator it;
|
|
|
|
int curLine, curWeek, week, i;
|
2010-06-16 19:15:49 +02:00
|
|
|
int r, g, b;
|
|
|
|
wxColour color;
|
2010-06-16 17:29:07 +02:00
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
if (!op && !user->_accounts.size()) return;
|
|
|
|
|
2010-06-05 14:33:19 +02:00
|
|
|
_grid->InsertRows(line, 1);
|
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
_grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
2010-06-21 13:02:02 +02:00
|
|
|
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->SetCellEditor(line, ACCOUNT, accountEditor);
|
2010-06-12 15:01:58 +02:00
|
|
|
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->SetCellEditor(line, CATEGORY, categoryEditor);
|
2010-06-05 14:33:19 +02:00
|
|
|
|
|
|
|
if (fix)
|
|
|
|
{
|
2010-06-10 19:15:25 +02:00
|
|
|
_fixCosts++;
|
|
|
|
_grid->SetCellValue(line, CATEGORY, _("Fixe"));
|
|
|
|
_grid->SetReadOnly(line, CATEGORY);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (op)
|
|
|
|
{
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->SetCellValue(line, DESCRIPTION, op->description);
|
|
|
|
_grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
|
|
|
if (op->amount < 0)
|
|
|
|
_grid->SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
|
|
|
|
else
|
|
|
|
_grid->SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
|
|
|
|
_grid->SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
|
2010-06-12 15:01:58 +02:00
|
|
|
if (!fix)
|
|
|
|
_grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
|
|
|
|
_grid->SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
|
2010-06-16 19:15:49 +02:00
|
|
|
_grid->SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
|
|
|
_grid->SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ());
|
2010-06-16 17:29:07 +02:00
|
|
|
|
2010-06-22 12:29:36 +02:00
|
|
|
color = user->GetCategory(op->category).color;
|
2010-06-16 19:15:49 +02:00
|
|
|
|
|
|
|
if (op->checked)
|
|
|
|
{
|
|
|
|
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
|
|
|
|
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
|
|
|
|
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
|
|
|
|
color.Set(r, g, b, color.Alpha());
|
|
|
|
_grid->SetCellValue(line, CHECKED, _("1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_ROW_COLOR(line, color);
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
2010-06-10 19:15:25 +02:00
|
|
|
else
|
|
|
|
{
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->SetCellEditor(line, DATE, new CalendarEditor(1, _curMonth, _curYear));
|
|
|
|
if (fix)
|
|
|
|
SET_ROW_COLOR(line, OWN_YELLOW)
|
|
|
|
else
|
2010-06-21 10:53:43 +02:00
|
|
|
SET_ROW_COLOR(line, OWN_GREEN);
|
|
|
|
_grid->SetReadOnly(line, CHECKED, true);
|
|
|
|
_grid->SetReadOnly(line, DELETE, true);
|
2010-06-10 19:15:25 +02:00
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
|
2010-06-16 17:29:07 +02:00
|
|
|
_grid->SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_grid->SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_grid->SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
2010-06-16 19:15:49 +02:00
|
|
|
_grid->SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
2010-06-16 17:29:07 +02:00
|
|
|
|
|
|
|
if (op)
|
|
|
|
{
|
|
|
|
for (it = _curOperations->begin(), curLine=1;
|
|
|
|
it->fix_cost && it != _curOperations->end();
|
|
|
|
it++, curLine++) ;
|
|
|
|
|
|
|
|
if (it == _curOperations->end()) return;
|
|
|
|
|
|
|
|
curLine++;
|
|
|
|
curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
|
|
|
for (i=1, it++; it != _curOperations->end(); it++, curLine++)
|
|
|
|
{
|
|
|
|
week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
|
|
|
if (week != curWeek)
|
|
|
|
{
|
|
|
|
_grid->SetWeek(i++, curLine);
|
|
|
|
curWeek = week;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 10:53:43 +02:00
|
|
|
|
|
|
|
_wxUI->Layout();
|
2010-06-05 14:33:19 +02:00
|
|
|
}
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
|
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
std::vector<Account>::iterator it;
|
2010-06-02 22:14:11 +02:00
|
|
|
int curLine = 0;
|
|
|
|
double value;
|
|
|
|
int i, a;
|
|
|
|
DEFAULT_FONT(font);
|
|
|
|
|
2010-06-22 15:51:51 +02:00
|
|
|
if (_accountsGrid->GetNumberRows())
|
|
|
|
_accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows());
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
|
|
|
|
for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++)
|
|
|
|
{
|
|
|
|
_accountsGrid->AppendRows();
|
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
|
|
|
|
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
|
|
|
|
value = _kiss->GetAccountAmount(it->id, month, year);
|
2010-06-02 22:14:11 +02:00
|
|
|
_accountsGrid->SetCellValue(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
|
|
|
|
_accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));
|
|
|
|
for (a=0; a<NUMBER_COLS_ACCOUNTS; a++)
|
|
|
|
_accountsGrid->SetReadOnly(curLine, a, a != ACCOUNT_INIT);
|
|
|
|
_accountsGrid->SetCellFont(curLine, ACCOUNT_CUR, font);
|
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
_accountsInitValues[it->id] = value;
|
2010-06-16 17:29:07 +02:00
|
|
|
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
2010-06-16 17:29:07 +02:00
|
|
|
|
|
|
|
_accountsGrid->AutoSizeColumns(true);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 22:32:35 +02:00
|
|
|
void AccountPanel::UpdateStats()
|
2010-05-27 21:09:02 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
User* user = _kiss->GetUser();
|
2010-06-03 18:28:38 +02:00
|
|
|
std::vector<operation>::iterator it;
|
2010-06-02 22:14:11 +02:00
|
|
|
double curCredit, curDebit, totalCredit, totalDebit, remains, value;
|
2010-05-27 22:32:35 +02:00
|
|
|
wxDateTime curDate;
|
2010-06-02 22:14:11 +02:00
|
|
|
std::map<wxString, double> curAccountAmount, finalAccountAmount;
|
|
|
|
std::map<wxString, double>::iterator doubleIt;
|
|
|
|
std::map<wxString, int>::iterator intIt;
|
2010-06-21 13:02:02 +02:00
|
|
|
std::vector<Account>::iterator accountIt;
|
2010-05-27 21:09:02 +02:00
|
|
|
|
2010-05-27 22:32:35 +02:00
|
|
|
curDate.SetToCurrent();
|
|
|
|
|
|
|
|
curCredit = curDebit = totalCredit = totalDebit = 0.0;
|
|
|
|
|
2010-06-12 15:01:58 +02:00
|
|
|
for (i=0; i<user->GetCategoriesNumber(); i++)
|
2010-05-27 21:09:02 +02:00
|
|
|
_categoriesValues[i] = 0.0;
|
|
|
|
|
2010-06-02 22:14:11 +02:00
|
|
|
for (doubleIt=_accountsInitValues.begin(); doubleIt!=_accountsInitValues.end(); doubleIt++)
|
|
|
|
{
|
|
|
|
curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
|
|
|
|
finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
for (it=_curOperations->begin(); it!=_curOperations->end(); it++)
|
|
|
|
{
|
|
|
|
if (it->amount > 0)
|
2010-05-27 22:32:35 +02:00
|
|
|
{
|
|
|
|
if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year)
|
2010-06-02 22:14:11 +02:00
|
|
|
{
|
|
|
|
curCredit += it->amount;
|
|
|
|
curAccountAmount[it->account] += it->amount;
|
|
|
|
}
|
2010-05-27 22:32:35 +02:00
|
|
|
totalCredit += it->amount;
|
2010-06-02 22:14:11 +02:00
|
|
|
finalAccountAmount[it->account] += it->amount;
|
2010-05-27 22:32:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ;
|
|
|
|
if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year)
|
2010-06-02 22:14:11 +02:00
|
|
|
{
|
|
|
|
curDebit += -it->amount;
|
|
|
|
curAccountAmount[it->account] += it->amount;
|
|
|
|
}
|
2010-05-27 22:32:35 +02:00
|
|
|
totalDebit += -it->amount;
|
2010-06-02 22:14:11 +02:00
|
|
|
finalAccountAmount[it->account] += it->amount;
|
2010-05-27 22:32:35 +02:00
|
|
|
}
|
2010-05-27 21:09:02 +02:00
|
|
|
}
|
2010-05-27 22:32:35 +02:00
|
|
|
|
|
|
|
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; i<user->GetCategoriesNumber()+1; i++)
|
|
|
|
_statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf"), _categoriesValues[i]));
|
2010-06-02 22:14:11 +02:00
|
|
|
|
2010-06-21 13:02:02 +02:00
|
|
|
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
|
2010-06-02 22:14:11 +02:00
|
|
|
{
|
2010-06-21 13:02:02 +02:00
|
|
|
value = curAccountAmount[accountIt->id];
|
2010-06-02 22:14:11 +02:00
|
|
|
_accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value));
|
|
|
|
_accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
|
2010-06-21 13:02:02 +02:00
|
|
|
value = finalAccountAmount[accountIt->id];
|
2010-06-02 22:14:11 +02:00
|
|
|
_accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf"), value));
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:09:02 +02:00
|
|
|
_pie->DatasetChanged(_dataset);
|
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
|
|
|
|
void AccountPanel::OnOperationModified(wxGridEvent& event)
|
|
|
|
{
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
int row = event.GetRow()-1;
|
2010-06-16 17:29:07 +02:00
|
|
|
int col = event.GetCol();
|
2010-06-03 18:28:38 +02:00
|
|
|
struct operation new_op, cur_op;
|
2010-06-16 19:15:49 +02:00
|
|
|
int op_complete = 6, i;
|
2010-06-03 18:28:38 +02:00
|
|
|
wxString value ;
|
|
|
|
wxDateTime date;
|
2010-06-10 19:15:25 +02:00
|
|
|
bool need_insertion = false, fix_op=false;
|
|
|
|
static bool inModification = false ;
|
2010-06-16 17:29:07 +02:00
|
|
|
wxColour color ;
|
|
|
|
unsigned char r, g, b;
|
2010-06-10 19:15:25 +02:00
|
|
|
|
|
|
|
// Avoid recursives calls
|
|
|
|
if (inModification) return;
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
inModification = true ;
|
|
|
|
|
2010-06-03 18:28:38 +02:00
|
|
|
if (event.GetCol() == DEBIT)
|
|
|
|
_grid->SetCellValue(event.GetRow(), CREDIT, _(""));
|
|
|
|
else if (event.GetCol() == CREDIT)
|
|
|
|
_grid->SetCellValue(event.GetRow(), DEBIT, _(""));
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), DESCRIPTION);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
new_op.description = value;
|
|
|
|
op_complete--;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), DATE);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
date.ParseFormat(value, _("%d/%m/%Y"));
|
|
|
|
new_op.day = date.GetDay()-1;
|
|
|
|
new_op.month = date.GetMonth();
|
|
|
|
new_op.year = date.GetYear();
|
|
|
|
op_complete--;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), DEBIT);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
value.ToDouble(&new_op.amount);
|
|
|
|
new_op.amount *= -1.0;
|
|
|
|
op_complete--;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), CREDIT);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
value.ToDouble(&new_op.amount);
|
|
|
|
op_complete--;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), CATEGORY);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
new_op.category = user->GetCategoryId(value);
|
|
|
|
op_complete--;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = _grid->GetCellValue(event.GetRow(), ACCOUNT);
|
|
|
|
if (value != _(""))
|
|
|
|
{
|
|
|
|
new_op.account = user->GetAccountId(value);
|
|
|
|
op_complete--;
|
|
|
|
}
|
2010-06-02 22:14:11 +02:00
|
|
|
|
2010-06-16 19:15:49 +02:00
|
|
|
value = _grid->GetCellValue(event.GetRow(), CHECKED);
|
2010-06-21 10:53:43 +02:00
|
|
|
if (value != _("") && value != _("0"))
|
2010-06-17 12:34:44 +02:00
|
|
|
new_op.checked = true;
|
|
|
|
else
|
|
|
|
new_op.checked = false;
|
|
|
|
op_complete--;
|
2010-06-16 17:29:07 +02:00
|
|
|
|
2010-06-16 19:15:49 +02:00
|
|
|
if (col == CHECKED || col == CATEGORY)
|
|
|
|
{
|
2010-06-22 12:29:36 +02:00
|
|
|
color = user->GetCategory(new_op.category).color;
|
2010-06-16 19:15:49 +02:00
|
|
|
|
|
|
|
if (new_op.checked)
|
2010-06-16 17:29:07 +02:00
|
|
|
{
|
|
|
|
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
|
|
|
|
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
|
|
|
|
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
|
|
|
|
color.Set(r, g, b, color.Alpha());
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_ROW_COLOR(event.GetRow(), color);
|
2010-06-16 19:15:49 +02:00
|
|
|
}
|
2010-06-16 17:29:07 +02:00
|
|
|
|
2010-06-16 19:15:49 +02:00
|
|
|
if (col == DELETE)
|
|
|
|
{
|
|
|
|
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_op.description, _("KissCount"), wxYES_NO);
|
|
|
|
if (dialog.ShowModal() == wxID_NO)
|
|
|
|
{
|
|
|
|
_grid->SetCellValue(event.GetRow(), event.GetCol(), _("0"));
|
2010-06-21 10:53:43 +02:00
|
|
|
inModification = false;
|
2010-06-16 19:15:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-06-16 17:29:07 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
// Penser au fix implosif
|
2010-06-02 22:14:11 +02:00
|
|
|
// Modify a fix operation
|
|
|
|
if (row < _fixCosts)
|
|
|
|
{
|
2010-06-03 18:28:38 +02:00
|
|
|
cur_op = (*_curOperations)[row] ;
|
2010-06-16 17:29:07 +02:00
|
|
|
|
|
|
|
if (col == DELETE)
|
|
|
|
{
|
|
|
|
_grid->DeleteRows(event.GetRow(), 1);
|
|
|
|
_curOperations->erase(_curOperations->begin()+row);
|
|
|
|
_kiss->DeleteOperation(cur_op);
|
|
|
|
_grid->_fixCosts = _fixCosts--;
|
|
|
|
UpdateStats();
|
|
|
|
inModification = false ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2010-06-03 18:28:38 +02:00
|
|
|
new_op.id = cur_op.id;
|
|
|
|
if (cur_op.day != new_op.day)
|
|
|
|
{
|
|
|
|
need_insertion = true;
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->DeleteRows(event.GetRow(), 1);
|
2010-06-03 18:28:38 +02:00
|
|
|
_curOperations->erase(_curOperations->begin()+row);
|
2010-06-12 15:01:58 +02:00
|
|
|
_fixCosts--;
|
2010-06-03 18:28:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
(*_curOperations)[row] = new_op;
|
|
|
|
_kiss->UpdateOperation(new_op);
|
2010-06-10 19:15:25 +02:00
|
|
|
fix_op = true;
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
|
|
|
// Add a fixCost
|
|
|
|
else if (row == _fixCosts)
|
|
|
|
{
|
2010-06-10 19:15:25 +02:00
|
|
|
if (op_complete) {
|
|
|
|
inModification = false ;
|
|
|
|
return ;
|
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
need_insertion = true;
|
2010-06-10 19:15:25 +02:00
|
|
|
fix_op = true;
|
2010-06-21 13:02:02 +02:00
|
|
|
new_op.fix_cost = true;
|
2010-06-10 19:15:25 +02:00
|
|
|
|
|
|
|
for(i=0; i<NUMBER_COLS_OPS; i++)
|
|
|
|
{
|
|
|
|
if (i == CATEGORY) continue;
|
|
|
|
_grid->SetCellValue(event.GetRow(), i, _(""));
|
|
|
|
}
|
2010-06-21 13:02:02 +02:00
|
|
|
new_op.id = _kiss->AddOperation(new_op);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
|
|
|
// Modify an operation
|
|
|
|
else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
|
|
|
|
{
|
2010-06-03 18:28:38 +02:00
|
|
|
row--;
|
|
|
|
cur_op = (*_curOperations)[row] ;
|
|
|
|
new_op.id = cur_op.id;
|
2010-06-16 17:29:07 +02:00
|
|
|
|
|
|
|
if (col == DELETE)
|
|
|
|
{
|
|
|
|
_grid->DeleteRows(event.GetRow(), 1);
|
|
|
|
_curOperations->erase(_curOperations->begin()+row);
|
|
|
|
_kiss->DeleteOperation(cur_op);
|
|
|
|
UpdateStats();
|
|
|
|
inModification = false ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2010-06-03 18:28:38 +02:00
|
|
|
if (cur_op.day != new_op.day)
|
|
|
|
{
|
|
|
|
need_insertion = true;
|
2010-06-10 19:15:25 +02:00
|
|
|
_grid->DeleteRows(event.GetRow(), 1);
|
2010-06-03 18:28:38 +02:00
|
|
|
_curOperations->erase(_curOperations->begin()+row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(*_curOperations)[row] = new_op;
|
|
|
|
_kiss->UpdateOperation(new_op);
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
|
|
|
// Add an operation
|
|
|
|
else
|
|
|
|
{
|
|
|
|
row--;
|
2010-06-10 19:15:25 +02:00
|
|
|
if (op_complete) {
|
|
|
|
inModification = false ;
|
|
|
|
return ;
|
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
need_insertion = true;
|
2010-06-21 13:02:02 +02:00
|
|
|
fix_op = false;
|
|
|
|
new_op.fix_cost = false;
|
2010-06-03 18:28:38 +02:00
|
|
|
|
2010-06-10 19:15:25 +02:00
|
|
|
for(i=0; i<NUMBER_COLS_OPS; i++)
|
|
|
|
{
|
|
|
|
_grid->SetCellValue(event.GetRow(), i, _(""));
|
|
|
|
}
|
2010-06-21 13:02:02 +02:00
|
|
|
new_op.id = _kiss->AddOperation(new_op);
|
2010-06-10 19:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_insertion)
|
|
|
|
{
|
|
|
|
for(i=0; i<(int)_curOperations->size(); i++)
|
|
|
|
{
|
|
|
|
if ((*_curOperations)[i].fix_cost && !fix_op) continue;
|
|
|
|
if (!(*_curOperations)[i].fix_cost && fix_op) break;
|
|
|
|
if ((*_curOperations)[i].day > new_op.day)
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
// First Operation
|
|
|
|
if ((*_curOperations)[i-1].fix_cost && !fix_op) break;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_curOperations->insert(_curOperations->begin()+i ,new_op);
|
|
|
|
i++; // For header
|
|
|
|
if (!fix_op) i++;
|
|
|
|
InsertOperation(user, &new_op, i, fix_op);
|
|
|
|
if (fix_op)
|
|
|
|
_grid->_fixCosts = _fixCosts+1;
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
2010-06-03 18:28:38 +02:00
|
|
|
|
|
|
|
UpdateStats();
|
2010-06-10 19:15:25 +02:00
|
|
|
|
|
|
|
inModification = false ;
|
2010-06-02 22:14:11 +02:00
|
|
|
}
|
2010-06-12 15:59:27 +02:00
|
|
|
|
|
|
|
void AccountPanel::OnAccountModified(wxGridEvent& event)
|
|
|
|
{
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
int row = event.GetRow();
|
|
|
|
double amount;
|
|
|
|
|
|
|
|
_accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
|
|
|
|
_kiss->SetAccountAmount(_curMonth, _curYear, user->GetAccountId(_accounts[row]), amount);
|
|
|
|
}
|
2010-06-22 15:51:51 +02:00
|
|
|
|
|
|
|
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
|
|
|
{
|
2010-06-23 14:25:00 +02:00
|
|
|
wxMenu menu(0);
|
|
|
|
|
|
|
|
menu.Append(MENU_GENERATE_ID, _("Generate month"));
|
|
|
|
menu.AppendSeparator();
|
|
|
|
if (_tree.GetCount() > 1)
|
|
|
|
menu.Append(MENU_DELETE_ID, _("Delete"));
|
|
|
|
|
|
|
|
PopupMenu(&menu, event.GetPoint());
|
2010-06-22 15:51:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccountPanel::OnTreeChange(wxTreeEvent& event)
|
|
|
|
{
|
2010-06-22 20:46:30 +02:00
|
|
|
int month=-1, year;
|
|
|
|
int i;
|
|
|
|
wxString monthString;
|
|
|
|
static bool inModification = false ;
|
|
|
|
|
|
|
|
if (inModification) return;
|
|
|
|
|
|
|
|
inModification = true;
|
|
|
|
|
|
|
|
monthString = _tree.GetItemText(event.GetItem());
|
|
|
|
for (i=0; i<12; i++)
|
|
|
|
if (monthString == months[i])
|
|
|
|
{
|
|
|
|
month = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (month == -1)
|
|
|
|
{
|
|
|
|
year = wxAtoi(monthString);
|
|
|
|
|
|
|
|
// Error
|
|
|
|
if (year == 0)
|
|
|
|
{
|
|
|
|
inModification = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (year == _curYear)
|
|
|
|
{
|
|
|
|
inModification = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// _tree.CollapseAll();
|
|
|
|
// _tree.Expand(event.GetItem());
|
|
|
|
LoadYear(year, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(event.GetItem())));
|
|
|
|
|
|
|
|
// Error
|
|
|
|
if (year == 0)
|
|
|
|
{
|
|
|
|
inModification = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (year != _curYear || month != _curMonth)
|
|
|
|
{
|
2010-06-23 19:32:42 +02:00
|
|
|
ShowMonth(month, year);
|
2010-06-22 20:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inModification = false;
|
2010-06-22 15:51:51 +02:00
|
|
|
}
|
2010-06-23 14:25:00 +02:00
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
void AccountPanel::GetTreeSelection(int* month, int* year)
|
2010-06-23 14:25:00 +02:00
|
|
|
{
|
|
|
|
wxString monthString;
|
2010-06-24 21:02:42 +02:00
|
|
|
int i;
|
2010-06-23 14:25:00 +02:00
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
*month = -1; *year = -1;
|
2010-06-23 14:25:00 +02:00
|
|
|
|
|
|
|
monthString = _tree.GetItemText(_tree.GetSelection());
|
|
|
|
for (i=0; i<12; i++)
|
|
|
|
if (monthString == months[i])
|
|
|
|
{
|
2010-06-24 21:02:42 +02:00
|
|
|
*month = i;
|
2010-06-23 14:25:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
if (*month == -1)
|
2010-06-23 14:25:00 +02:00
|
|
|
{
|
2010-06-24 21:02:42 +02:00
|
|
|
*year = wxAtoi(monthString);
|
2010-06-23 14:25:00 +02:00
|
|
|
|
|
|
|
// Error
|
|
|
|
if (year == 0)
|
2010-06-24 21:02:42 +02:00
|
|
|
{
|
|
|
|
*month = -1;
|
|
|
|
*year = -1;
|
2010-06-23 14:25:00 +02:00
|
|
|
return;
|
2010-06-24 21:02:42 +02:00
|
|
|
}
|
2010-06-23 14:25:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-24 21:02:42 +02:00
|
|
|
*year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(_tree.GetSelection())));
|
2010-06-23 14:25:00 +02:00
|
|
|
|
|
|
|
// Error
|
|
|
|
if (year == 0)
|
2010-06-24 21:02:42 +02:00
|
|
|
{
|
|
|
|
*month = -1;
|
|
|
|
*year = -1;
|
2010-06-23 14:25:00 +02:00
|
|
|
return;
|
2010-06-24 21:02:42 +02:00
|
|
|
}
|
2010-06-23 14:25:00 +02:00
|
|
|
}
|
2010-06-24 21:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccountPanel::OnMenuGenerate(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int month, year;
|
|
|
|
|
|
|
|
GetTreeSelection(&month, &year);
|
2010-06-23 14:25:00 +02:00
|
|
|
|
|
|
|
GenerateDialog g(_kiss, _wxUI, month, year);
|
|
|
|
g.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccountPanel::OnMenuDelete(wxCommandEvent& event)
|
|
|
|
{
|
2010-06-24 21:02:42 +02:00
|
|
|
int month, year;
|
|
|
|
wxString message;
|
|
|
|
wxTreeItemId curNode, node ;
|
|
|
|
std::map<int, std::vector<int> > ops ;
|
|
|
|
|
|
|
|
GetTreeSelection(&month, &year);
|
|
|
|
|
2010-06-27 21:39:49 +02:00
|
|
|
ops = _kiss->GetAllOperations();
|
|
|
|
|
|
|
|
if (ops.size() == 1 && ops[year].size() == 1)
|
|
|
|
{
|
|
|
|
wxMessageBox(_("It must be at least one month"), _("Error"), wxICON_ERROR | wxOK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
message = _("Are you sure want to delete ");
|
|
|
|
if (month != -1)
|
|
|
|
message += months[month] + _(" ");
|
|
|
|
message += wxString::Format(_("%d"), year);
|
|
|
|
|
|
|
|
message += _(" operations ?");
|
2010-06-23 14:25:00 +02:00
|
|
|
|
2010-06-24 21:02:42 +02:00
|
|
|
wxMessageDialog dialog(_wxUI, message, _("KissCount"), wxYES_NO);
|
|
|
|
if (dialog.ShowModal() == wxID_NO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
curNode = _tree.GetSelection();
|
|
|
|
|
|
|
|
if (ops[year].size() == 1 && month != -1)
|
|
|
|
curNode = _tree.GetItemParent(curNode);
|
|
|
|
|
|
|
|
_kiss->DeleteOperations(month, year);
|
|
|
|
|
|
|
|
node = _tree.GetNextSibling(curNode);
|
|
|
|
|
|
|
|
if (!node.IsOk())
|
|
|
|
node = _tree.GetPrevSibling(curNode);
|
|
|
|
|
|
|
|
_tree.Delete(curNode);
|
|
|
|
|
|
|
|
if (!node.IsOk())
|
|
|
|
ChangeUser();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_tree.SelectItem(node);
|
|
|
|
GetTreeSelection(&month, &year);
|
|
|
|
if (month == -1)
|
|
|
|
month = ops[year][0];
|
|
|
|
ShowMonth(month, year);
|
|
|
|
}
|
2010-06-23 14:25:00 +02:00
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
|
|
|
|
void AccountPanel::GenerateMonth(int month, int year)
|
|
|
|
{
|
|
|
|
wxTreeItemId root, years, node ;
|
|
|
|
wxTreeItemIdValue cookie;
|
|
|
|
wxString monthString, yearString;
|
|
|
|
std::map<unsigned int, std::vector<operation> >::iterator it;
|
|
|
|
int i;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
|
|
|
|
root = _tree.GetRootItem();
|
|
|
|
yearString = wxString::Format(wxT("%d"), year);
|
|
|
|
monthString = months[month];
|
|
|
|
|
|
|
|
if (_tree.GetChildrenCount(root, true) < 1)
|
|
|
|
{
|
|
|
|
node = _tree.AppendItem(root, yearString);
|
|
|
|
node = _tree.AppendItem(node, monthString);
|
|
|
|
|
|
|
|
_tree.SelectItem(node, true);
|
|
|
|
ShowMonth(month, year);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
years = _tree.GetFirstChild(root, cookie);
|
|
|
|
while (years.IsOk())
|
|
|
|
{
|
|
|
|
if (_tree.GetItemText(years) == yearString)
|
|
|
|
break;
|
|
|
|
if (wxAtoi(_tree.GetItemText(years)) > year)
|
|
|
|
{
|
|
|
|
years = _tree.GetPrevSibling(years);
|
|
|
|
if (!years.IsOk())
|
|
|
|
years = _tree.PrependItem(root, yearString);
|
|
|
|
else
|
|
|
|
years = _tree.InsertItem(root, years, yearString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
years = _tree.GetNextSibling(years);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!years.IsOk())
|
2010-06-24 21:02:42 +02:00
|
|
|
{
|
|
|
|
years = _tree.GetFirstChild(root, cookie);
|
|
|
|
if (wxAtoi(_tree.GetItemText(years)) > year)
|
|
|
|
years = _tree.PrependItem(root, yearString);
|
|
|
|
else
|
|
|
|
years = _tree.AppendItem(root, yearString);
|
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
|
|
|
|
if (!_tree.GetChildrenCount(years, true))
|
|
|
|
node = _tree.AppendItem(years, monthString);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0, it = user->_operations[year]->begin();
|
|
|
|
it != user->_operations[year]->end();
|
|
|
|
it++, i++)
|
|
|
|
{
|
2010-06-23 20:30:42 +02:00
|
|
|
if ((int)it->first > month)
|
2010-06-23 19:32:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
years = _tree.InsertItem(years, i, monthString);
|
|
|
|
}
|
|
|
|
|
|
|
|
_tree.SelectItem(node, true);
|
|
|
|
ShowMonth(month, year);
|
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
|
|
|
void AccountPanel::OnShow(wxShowEvent& event)
|
|
|
|
{
|
|
|
|
if (_curMonth != -1)
|
|
|
|
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + months[_curMonth] + _(" ") + wxString::Format(wxT("%d"), _curYear));
|
|
|
|
else
|
|
|
|
_wxUI->SetTitle(_kiss->GetUser()->_name);
|
|
|
|
}
|