KissCount/view/AccountPanel.cpp

567 lines
18 KiB
C++
Raw Normal View History

#include "AccountPanel.h"
2010-05-16 20:09:18 +02:00
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _("")};
2010-06-02 22:14:11 +02:00
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
END_EVENT_TABLE()
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID)
{
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);
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();
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);
2010-05-27 21:09:02 +02:00
ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors));
_pie = new PiePlot();
2010-05-27 21:09:02 +02:00
_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++)
2010-05-27 22:32:35 +02:00
_categoriesValues[i] = 0.0;
2010-05-24 20:14:15 +02:00
2010-05-27 21:09:02 +02:00
_dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber()+1);
_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-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"));
_accountsGrid->AutoSizeColumns(true);
2010-05-27 22:32:35 +02:00
_statsGrid = new wxGrid(this, -1);
_statsGrid->CreateGrid(user->GetCategoriesNumber()+1+6, 2);
_statsGrid->SetColLabelSize(0);
_statsGrid->SetRowLabelSize(0);
_statsGrid->EnableEditing(false);
2010-06-02 22:14:11 +02:00
InitStatsGrid(user);
2010-05-27 22:32:35 +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));
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-16 10:35:34 +02:00
ChangeUser();
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);
_statsGrid->SetDefaultCellFont(font);
_statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit"));
_statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit"));
_statsGrid->AutoSizeColumn(0, false);
for(i=0; i<user->GetCategoriesNumber()+1; i++)
_statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]);
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-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;
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;
2010-06-03 18:28:38 +02:00
std::map<unsigned int, std::vector<operation> >::iterator it;
2010-05-16 10:35:34 +02:00
wxDateTime curDate;
wxTreeItemId parentNode, curMonthNode;
2010-05-27 21:09:02 +02:00
_curYear = year ;
if (user->_operations[year] != NULL)
2010-05-16 10:35:34 +02:00
{
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);
2010-05-27 21:09:02 +02:00
2010-05-16 10:35:34 +02:00
ShowMonth(year, curMonth);
}
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-05-16 10:35:34 +02:00
void AccountPanel::ShowMonth(int year, int month)
{
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-05-24 20:14:15 +02:00
std::map<wxString, wxString>::iterator categoryIt;
wxGridCellChoiceEditor* categoryEditor, *accountEditor;
2010-05-16 20:09:18 +02:00
int i;
2010-05-16 10:35:34 +02:00
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
// 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-06-02 22:14:11 +02:00
//_grid->Clear();
_grid->CreateGrid(1, NUMBER_COLS_OPS);
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);
2010-06-02 22:14:11 +02:00
for(i=0; i<NUMBER_COLS_OPS; i++)
2010-05-16 20:09:18 +02:00
{
_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
2010-05-27 21:09:02 +02:00
it = _curOperations->begin();
2010-05-16 20:09:18 +02:00
/*
struct operation {
wxString id;
unsigned int day;
unsigned int month;
unsigned int year;
int amount;
wxString description;
wxString category;
bool fix_cost;
2010-06-02 22:14:11 +02:00
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS};
2010-05-16 20:09:18 +02:00
} ;
*/
2010-05-27 22:32:35 +02:00
for (;it->fix_cost && it != _curOperations->end(); it++)
2010-05-16 20:09:18 +02:00
{
curLine++;
2010-06-02 22:14:11 +02:00
_fixCosts++;
_grid->AppendRows();
2010-05-16 20:09:18 +02:00
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));
2010-06-02 22:14:11 +02:00
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
2010-05-16 20:09:18 +02:00
if (it->amount < 0)
2010-05-27 21:09:02 +02:00
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount));
2010-05-16 20:09:18 +02:00
else
2010-05-27 21:09:02 +02:00
_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));
2010-06-02 22:14:11 +02:00
_grid->SetCellValue(curLine, CATEGORY, _("Fixe"));
_grid->SetReadOnly(curLine, CATEGORY);
2010-05-27 21:09:02 +02:00
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
2010-05-24 20:14:15 +02:00
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
2010-05-16 20:09:18 +02:00
}
_grid->AppendRows();
curLine++;
SET_ROW_COLOR(curLine, OWN_YELLOW);
2010-06-02 22:14:11 +02:00
_grid->SetCellValue(curLine, CATEGORY, _("Fixe"));
_grid->SetReadOnly(curLine, CATEGORY);
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
2010-05-27 21:09:02 +02:00
_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);
2010-05-24 20:14:15 +02:00
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
2010-05-16 20:09:18 +02:00
2010-06-02 22:14:11 +02:00
_grid->_fixCosts = _fixCosts+1;
2010-05-16 20:09:18 +02:00
2010-05-27 22:32:35 +02:00
for (; it != _curOperations->end(); it++)
2010-05-16 20:09:18 +02:00
{
curLine++;
2010-06-02 22:14:11 +02:00
_grid->AppendRows();
2010-05-16 20:09:18 +02:00
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));
2010-06-02 22:14:11 +02:00
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
2010-05-16 20:09:18 +02:00
if (it->amount < 0)
2010-05-27 21:09:02 +02:00
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount));
2010-05-16 20:09:18 +02:00
else
2010-05-27 21:09:02 +02:00
_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);
2010-05-16 20:09:18 +02:00
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
2010-05-24 20:14:15 +02:00
_grid->SetCellValue(curLine, CATEGORY, user->GetCategoryName(it->category));
2010-05-27 21:09:02 +02:00
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
2010-05-24 20:14:15 +02:00
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
2010-05-16 20:09:18 +02:00
}
_grid->AppendRows();
curLine++;
SET_ROW_COLOR(curLine, OWN_GREEN);
2010-05-27 21:09:02 +02:00
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, _categories, false);
2010-05-16 20:09:18 +02:00
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
2010-06-02 22:14:11 +02:00
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
2010-05-27 21:09:02 +02:00
_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);
2010-05-24 20:14:15 +02:00
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
2010-05-16 20:09:18 +02:00
2010-05-24 20:14:15 +02:00
_grid->AutoSizeColumn(CATEGORY, false);
_grid->AutoSizeColumn(ACCOUNT, 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-02 22:14:11 +02:00
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
{
std::map<wxString, Account>::iterator it;
int curLine = 0;
Account account ;
double value;
int i, a;
DEFAULT_FONT(font);
font.SetWeight(wxFONTWEIGHT_BOLD);
for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++)
{
_accountsGrid->AppendRows();
account = user->_accounts[it->first];
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, account.number);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, account.name);
value = _kiss->GetAccountAmount(it->first, month, year);
_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);
_accountsIndexes[it->first] = i;
_accountsInitValues[it->first] = value;
}
}
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-05-27 21:09:02 +02:00
2010-05-27 22:32:35 +02:00
curDate.SetToCurrent();
curCredit = curDebit = totalCredit = totalDebit = 0.0;
for (i=0; i<user->GetCategoriesNumber()+1; 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
for (intIt=_accountsIndexes.begin(); intIt!=_accountsIndexes.end(); intIt++)
{
i = _accountsIndexes[intIt->first];
value = curAccountAmount[intIt->first];
_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));
value = finalAccountAmount[intIt->first];
_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-03 18:28:38 +02:00
struct operation new_op, cur_op;
int op_complete = 5;
wxString value ;
wxDateTime date;
bool need_insertion = false;
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
// Modify a fix operation
if (row < _fixCosts)
{
2010-06-03 18:28:38 +02:00
cur_op = (*_curOperations)[row] ;
new_op.id = cur_op.id;
if (cur_op.day != new_op.day)
{
need_insertion = true;
_grid->DeleteRows(row, 1);
_curOperations->erase(_curOperations->begin()+row);
}
else
(*_curOperations)[row] = new_op;
_kiss->UpdateOperation(new_op);
2010-06-02 22:14:11 +02:00
}
// Add a fixCost
else if (row == _fixCosts)
{
2010-06-03 18:28:38 +02:00
if (op_complete) return ;
need_insertion = true;
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;
if (cur_op.day != new_op.day)
{
need_insertion = true;
_grid->DeleteRows(row+1, 1);
_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-03 18:28:38 +02:00
if (op_complete) return ;
need_insertion = true;
2010-06-02 22:14:11 +02:00
}
2010-06-03 18:28:38 +02:00
UpdateStats();
2010-06-02 22:14:11 +02:00
}