This commit is contained in:
Grégory Soutadé 2010-06-10 19:15:25 +02:00
parent 1e79c5114e
commit 20509721cf
2 changed files with 90 additions and 88 deletions

View File

@ -224,7 +224,7 @@ void AccountPanel::ShowMonth(int year, int month)
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
DEFAULT_FONT(font); DEFAULT_FONT(font);
std::map<wxString, wxString>::iterator categoryIt; std::map<wxString, wxString>::iterator categoryIt;
wxGridCellChoiceEditor* categoryEditor, *accountEditor; //wxGridCellChoiceEditor* categoryEditor, *accountEditor;
int i; int i;
_curMonth = month; _curMonth = month;
@ -272,72 +272,15 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS
} ; } ;
*/ */
for (;it->fix_cost && it != _curOperations->end(); it++) for (;it->fix_cost && it != _curOperations->end(); it++)
{ InsertOperation(user, &(*it), ++curLine, true);
curLine++;
_fixCosts++;
_grid->AppendRows();
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));
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
if (it->amount < 0)
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount));
else
_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));
_grid->SetCellValue(curLine, CATEGORY, _("Fixe"));
_grid->SetReadOnly(curLine, CATEGORY);
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
}
_grid->AppendRows(); InsertOperation(user, NULL, ++curLine, true);
curLine++; _grid->_fixCosts = _fixCosts--;
SET_ROW_COLOR(curLine, OWN_YELLOW);
_grid->SetCellValue(curLine, CATEGORY, _("Fixe"));
_grid->SetReadOnly(curLine, CATEGORY);
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
_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+1;
for (; it != _curOperations->end(); it++) for (; it != _curOperations->end(); it++)
{ InsertOperation(user, &(*it), ++curLine, false);
curLine++;
_grid->AppendRows();
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));
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
if (it->amount < 0)
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount));
else
_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);
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor);
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account));
}
_grid->AppendRows(); InsertOperation(user, NULL, ++curLine, false);
curLine++;
SET_ROW_COLOR(curLine, OWN_GREEN);
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, _categories, false);
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year));
_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->AutoSizeColumn(CATEGORY, false); _grid->AutoSizeColumn(CATEGORY, false);
_grid->AutoSizeColumn(ACCOUNT, false); _grid->AutoSizeColumn(ACCOUNT, false);
@ -352,37 +295,43 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS
void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix) void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix)
{ {
_grid->InsertRows(line, 1); _grid->InsertRows(line, 1);
_grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); _grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); _grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2));
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false);
accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); _grid->SetCellEditor(line, ACCOUNT, accountEditor);
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()+1, _categories, false);
_grid->SetCellEditor(line, CATEGORY, categoryEditor);
if (fix) if (fix)
{ {
_fixCosts++; _fixCosts++;
SET_ROW_COLOR(curLine, OWN_YELLOW); SET_ROW_COLOR(line, OWN_YELLOW);
_grid->SetCellValue(curLine, CATEGORY, _("Fixe")); _grid->SetCellValue(line, CATEGORY, _("Fixe"));
_grid->SetReadOnly(curLine, CATEGORY); _grid->SetReadOnly(line, CATEGORY);
} }
else else
{ {
SET_ROW_COLOR(curLine, OWN_GREEN); SET_ROW_COLOR(line, OWN_GREEN);
} }
if (op) if (op)
{ {
_grid->SetCellValue(curLine, DESCRIPTION, it->description); _grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
_grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year)); _grid->SetCellValue(line, DESCRIPTION, op->description);
if (it->amount < 0) _grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount)); if (op->amount < 0)
else _grid->SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
_grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount)); else
_grid->SetCellEditor(curLine, ACCOUNT, accountEditor); _grid->SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
_grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); _grid->SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
_grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
} }
else
{
_grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear));
}
} }
void AccountPanel::InitAccountsGrid(User* user, int month, int year) void AccountPanel::InitAccountsGrid(User* user, int month, int year)
@ -495,11 +444,17 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
int row = event.GetRow()-1; int row = event.GetRow()-1;
struct operation new_op, cur_op; struct operation new_op, cur_op;
int op_complete = 5; int op_complete = 5, i;
wxString value ; wxString value ;
wxDateTime date; wxDateTime date;
bool need_insertion = false; bool need_insertion = false, fix_op=false;
static bool inModification = false ;
// Avoid recursives calls
if (inModification) return;
inModification = true ;
if (event.GetCol() == DEBIT) if (event.GetCol() == DEBIT)
_grid->SetCellValue(event.GetRow(), CREDIT, _("")); _grid->SetCellValue(event.GetRow(), CREDIT, _(""));
else if (event.GetCol() == CREDIT) else if (event.GetCol() == CREDIT)
@ -551,7 +506,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
op_complete--; op_complete--;
} }
// Penser au fix // Penser au fix implosif
// Modify a fix operation // Modify a fix operation
if (row < _fixCosts) if (row < _fixCosts)
{ {
@ -560,18 +515,29 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
if (cur_op.day != new_op.day) if (cur_op.day != new_op.day)
{ {
need_insertion = true; need_insertion = true;
_grid->DeleteRows(row, 1); _grid->DeleteRows(event.GetRow(), 1);
_curOperations->erase(_curOperations->begin()+row); _curOperations->erase(_curOperations->begin()+row);
} }
else else
(*_curOperations)[row] = new_op; (*_curOperations)[row] = new_op;
_kiss->UpdateOperation(new_op); _kiss->UpdateOperation(new_op);
fix_op = true;
} }
// Add a fixCost // Add a fixCost
else if (row == _fixCosts) else if (row == _fixCosts)
{ {
if (op_complete) return ; if (op_complete) {
inModification = false ;
return ;
}
need_insertion = true; need_insertion = true;
fix_op = true;
for(i=0; i<NUMBER_COLS_OPS; i++)
{
if (i == CATEGORY) continue;
_grid->SetCellValue(event.GetRow(), i, _(""));
}
} }
// Modify an operation // Modify an operation
else if (row <= user->GetOperationsNumber(_curMonth, _curYear)) else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
@ -582,7 +548,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
if (cur_op.day != new_op.day) if (cur_op.day != new_op.day)
{ {
need_insertion = true; need_insertion = true;
_grid->DeleteRows(row+1, 1); _grid->DeleteRows(event.GetRow(), 1);
_curOperations->erase(_curOperations->begin()+row); _curOperations->erase(_curOperations->begin()+row);
} }
else else
@ -593,10 +559,45 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
else else
{ {
row--; row--;
if (op_complete) return ; if (op_complete) {
inModification = false ;
return ;
}
need_insertion = true; need_insertion = true;
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;
} }
UpdateStats(); UpdateStats();
inModification = false ;
} }

View File

@ -60,6 +60,7 @@ private:
void InitStatsGrid(User* user); void InitStatsGrid(User* user);
void InitAccountsGrid(User* user, int month, int year); void InitAccountsGrid(User* user, int month, int year);
void UpdateStats(); void UpdateStats();
void InsertOperation(User* user, operation* op, int line, bool fix);
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
}; };