Add Real mode

This commit is contained in:
Grégory Soutadé 2011-02-19 13:41:59 +01:00
parent 4cb57641d8
commit 8792ac2a8e
5 changed files with 136 additions and 46 deletions

View File

@ -1,4 +1,4 @@
v0.2_dev (15/02/2011)
v0.2_dev (19/02/2011)
** User **
Better use of sizers (so better interface!)
@ -11,6 +11,7 @@ v0.2_dev (15/02/2011)
Add virtual accounts
Searchs aren't case sensitive enough
Default categories in native language (even if switching language at runtime)
Add Real mode
** Dev **
Use a factory to create panels (prepare for plug-in)

2
TODO
View File

@ -6,6 +6,8 @@ Using tabulation to navigate throw interface (Search Panel)
Can type a letter with a comboboxes
Windows version
Need packaging (.deb)
Real mode
Choosing accounts & categories position
Cool for 0.2:
Database auto saving at startup

View File

@ -21,7 +21,9 @@
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};
enum {CALENDAR_TREE_ID=1, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID, CHECK_MODE_ID, GROUP_ID, UNGROUP_ID};
enum {CALENDAR_TREE_ID=1, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID, DISPLAY_MODE_ID, GROUP_ID, UNGROUP_ID};
enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE};
BEGIN_EVENT_TABLE(AccountPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified)
@ -33,7 +35,7 @@ EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
EVT_SHOW(AccountPanel::OnShow)
EVT_CALENDAR_SEL_CHANGED(CALENDAR_ID, AccountPanel::OnCalendarChange)
EVT_CHECKBOX(CHECK_MODE_ID, AccountPanel::OnCheckMode)
EVT_RADIOBOX(DISPLAY_MODE_ID, AccountPanel::OnModeChange)
EVT_BUTTON(GROUP_ID, AccountPanel::OnGroup)
EVT_BUTTON(UNGROUP_ID, AccountPanel::OnUnGroup)
END_EVENT_TABLE()
@ -119,7 +121,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
chart->SetMinSize(// chart->GetSize()
wxSize(200,250));
_checkCheckMode = new wxCheckBox(this, CHECK_MODE_ID, _("Check mode"));
wxString modes[3] = {_("Virtual"), _("Real"), _("Check")};
_radioMode = new wxRadioBox(this, DISPLAY_MODE_ID, _("Mode"), wxDefaultPosition, wxDefaultSize,
3, modes);
_tree.SetIndent(5);
@ -138,7 +142,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
hbox->Add(vbox2, 0, wxGROW|wxALL, 2);
vbox->Add(_statsGrid, 0, wxGROW);
vbox->Add(chart, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 10);
vbox->Add(_checkCheckMode, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 10);
vbox->Add(_radioMode, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 10);
hbox->Add(vbox, 0, wxGROW|wxALL, 2);
ChangeUser();
@ -432,20 +436,22 @@ void AccountPanel::UpdateStats()
std::map<wxString, int>::iterator intIt;
std::vector<Account>::iterator accountIt;
unsigned int day;
bool checkMode = _checkCheckMode->IsChecked();
int mode;
std::map<wxString, double>* notChecked = NULL;
std::map<wxString, double>* virtuals = NULL;
Account account;
Operation op;
bool blocked_account ;
mode = _radioMode->GetSelection();
curCredit = curDebit = totalCredit = totalDebit = percents = 0.0;
if (checkMode)
{
if (mode == CHECK_MODE)
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
}
if (mode == REAL_MODE || mode == CHECK_MODE)
virtuals = _kiss->GetVirtualAmount(_curMonth, _curYear);
day = _calendar->GetDate().GetDay()-1;
@ -457,7 +463,7 @@ void AccountPanel::UpdateStats()
curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first];
if (virtuals)
if (mode == REAL_MODE || mode == CHECK_MODE)
{
curAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
finalAccountAmount[doubleIt->first] += -(*virtuals)[doubleIt->first];
@ -484,41 +490,119 @@ void AccountPanel::UpdateStats()
}
}
if (op.amount >= 0)
switch(mode)
{
if (!op.transfert.Length() || (op._virtual && checkMode))
totalCredit += op.amount;
if (day >= op.day)
case VIRTUAL_MODE:
if (op.amount >= 0)
{
if (!op.transfert.Length() || (op._virtual && checkMode))
curCredit += op.amount;
if ((!checkMode || (checkMode && op.checked)) && !op._virtual)
curAccountAmount[op.account] += op.amount;
if (!op.transfert.Length())
totalCredit += op.amount;
if (day >= op.day)
{
if (!op.transfert.Length())
curCredit += op.amount;
curAccountAmount[op.account] += op.amount;
}
finalAccountAmount[op.account] += op.amount;
}
if ((!checkMode || (checkMode && op.checked)) && !op._virtual)
finalAccountAmount[op.account] += op.amount;
}
else
{
if (!op.transfert.Length())
_categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ;
if (!op.transfert.Length() || op._virtual)
totalDebit += -op.amount;
if (blocked_account)
op.amount = -op.amount;
if (day >= op.day)
else
{
if (!op.transfert.Length() || op._virtual)
curDebit += -op.amount;
if (!checkMode || (checkMode && op.checked && !op._virtual))
curAccountAmount[op.account] += op.amount;
if (!op.transfert.Length())
_categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ;
if (!op.transfert.Length() || op._virtual)
totalDebit += -op.amount;
if (blocked_account)
op.amount = -op.amount;
if (day >= op.day)
{
if (!op.transfert.Length() || op._virtual)
curDebit += -op.amount;
curAccountAmount[op.account] += op.amount;
}
finalAccountAmount[op.account] += op.amount;
}
if (!checkMode || (checkMode && op.checked && !op._virtual))
finalAccountAmount[op.account] += op.amount;
break;
case REAL_MODE:
if (op.amount >= 0)
{
if (!op.transfert.Length())
totalCredit += op.amount;
if (day >= op.day)
{
if (!op.transfert.Length())
curCredit += op.amount;
if (!op._virtual)
curAccountAmount[op.account] += op.amount;
}
if (!op._virtual)
finalAccountAmount[op.account] += op.amount;
}
else
{
if (!op.transfert.Length())
_categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ;
if (!op.transfert.Length() && !op._virtual)
totalDebit += -op.amount;
if (blocked_account)
op.amount = -op.amount;
if (day >= op.day)
{
if (!op.transfert.Length() && !op._virtual)
curDebit += -op.amount;
if (!op._virtual)
curAccountAmount[op.account] += op.amount;
}
if (!op._virtual)
finalAccountAmount[op.account] += op.amount;
}
break;
case CHECK_MODE:
if (op.amount >= 0)
{
if (!op.transfert.Length() && !op._virtual)
totalCredit += op.amount;
if (day >= op.day)
{
if (!op.transfert.Length() && !op._virtual)
curCredit += op.amount;
if (op.checked && !op._virtual)
curAccountAmount[op.account] += op.amount;
}
if (op.checked && !op._virtual)
finalAccountAmount[op.account] += op.amount;
}
else
{
if (!op.transfert.Length())
_categoriesValues[_categoriesIndexes[user->GetCategoryName(op.category)]] += -op.amount ;
if (!op.transfert.Length() && !op._virtual)
totalDebit += -op.amount;
if (blocked_account)
op.amount = -op.amount;
if (day >= op.day)
{
if (!op.transfert.Length() && !op._virtual)
curDebit += -op.amount;
if (op.checked && !op._virtual)
curAccountAmount[op.account] += op.amount;
}
if (op.checked && !op._virtual)
finalAccountAmount[op.account] += op.amount;
}
break;
}
}
@ -542,9 +626,11 @@ void AccountPanel::UpdateStats()
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
{
if (!checkMode || !notChecked)
if (mode != CHECK_MODE)
{
value = _accountsInitValues[accountIt->id];
if (mode == REAL_MODE)
value -= (*virtuals)[accountIt->id];
_accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
value = curAccountAmount[accountIt->id];
_accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value));
@ -882,7 +968,7 @@ void AccountPanel::OnCalendarChange(wxCalendarEvent& event)
UpdateStats();
}
void AccountPanel::OnCheckMode(wxCommandEvent& event)
void AccountPanel::OnModeChange(wxCommandEvent& event)
{
UpdateStats();
}

View File

@ -25,6 +25,7 @@
#include <wx/treectrl.h>
#include <wx/pie/pieplot.h>
#include <wx/chartpanel.h>
#include <wx/radiobox.h>
#include "grid/CalendarEditor.h"
#include "grid/wxGridCellBitmapRenderer.h"
@ -58,7 +59,7 @@ public:
void OnMenuGenerate(wxCommandEvent& event);
void OnMenuDelete(wxCommandEvent& event);
void OnCalendarChange(wxCalendarEvent& event);
void OnCheckMode(wxCommandEvent& event);
void OnModeChange(wxCommandEvent& event);
void OnGroup(wxCommandEvent& event);
void OnUnGroup(wxCommandEvent& event);
@ -71,7 +72,7 @@ private:
wxGrid *_statsGrid, *_accountsGrid;
PiePlot* _pie;
double *_categoriesValues;
wxCheckBox *_checkCheckMode;
wxRadioBox *_radioMode;
std::map<wxString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
wxString* _categories, *_accounts;

View File

@ -774,7 +774,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
{
new_op.category = op_tmp.category;
new_op.account = op_tmp.account;
SetCellValue(row, CATEGORY, user->GetCategoryName(new_op.category));
SetCellValue(row, CATEGORY, wxGetTranslation(user->GetCategoryName(new_op.category)));
SetCellValue(row, ACCOUNT, user->GetAccountName(new_op.account));
op_complete -= 2;
}