KissCount/view/AccountPanel.cpp

604 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()];
for (i=0,
2010-05-27 21:09:02 +02:00
accountIt = user->_accounts.begin();
accountIt != user->_accounts.end();
accountIt++, i++)
_accounts[i] = user->_accounts[accountIt->first].name;
_categories = new wxString[user->GetCategoriesNumber()] ;
for(i=0, it = user->_preferences._categories.begin(); it != user->_preferences._categories.end(); it++, i++)
2010-05-27 21:09:02 +02:00
{
_categories[i] = it->second ;
_categoriesIndexes[it->second] = i;
}
_dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber());
2010-05-27 21:09:02 +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
_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-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()+6, 2);
2010-05-27 22:32:35 +02:00
_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(); i++)
2010-06-02 22:14:11 +02:00
_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;
2010-06-10 19:15:25 +02:00
//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-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);
_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-05 14:33:19 +02:00
void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix)
{
_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));
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->_accounts.size(), _accounts, false);
2010-06-10 19:15:25 +02:00
_grid->SetCellEditor(line, ACCOUNT, accountEditor);
// Remove Fix category
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++;
SET_ROW_COLOR(line, OWN_YELLOW);
_grid->SetCellValue(line, CATEGORY, _("Fixe"));
_grid->SetReadOnly(line, CATEGORY);
2010-06-05 14:33:19 +02:00
}
else
{
2010-06-10 19:15:25 +02:00
SET_ROW_COLOR(line, OWN_GREEN);
2010-06-05 14:33:19 +02:00
}
if (op)
{
2010-06-10 19:15:25 +02:00
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
_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));
if (!fix)
_grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
2010-06-05 14:33:19 +02:00
}
2010-06-10 19:15:25 +02:00
else
{
_grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear));
}
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)
{
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(); 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;
2010-06-10 19:15:25 +02:00
int op_complete = 5, 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 ;
// 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-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] ;
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);
_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;
for(i=0; i<NUMBER_COLS_OPS; i++)
{
if (i == CATEGORY) continue;
_grid->SetCellValue(event.GetRow(), i, _(""));
}
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;
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-10 19:15:25 +02:00
for(i=0; i<NUMBER_COLS_OPS; i++)
{
_grid->SetCellValue(event.GetRow(), i, _(""));
}
}
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
}