Add update next months feature
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| v0.2 (26/04/2011) | ||||
| v0.2 (30/04/2011) | ||||
|  | ||||
| ** User ** | ||||
| 	Better use of sizers (so better interface!) | ||||
| @@ -15,6 +15,7 @@ v0.2 (26/04/2011) | ||||
| 	Database is now at ~/.kisscount/kc.bdd | ||||
| 	Add Debian's packages !! | ||||
| 	Add Import Panel, OFX and Grisbi imports | ||||
| 	Add update next months | ||||
|  | ||||
| ** Dev ** | ||||
| 	Use a factory to create panels (prepare for plug-in) | ||||
|   | ||||
| @@ -21,7 +21,7 @@ | ||||
|  | ||||
| 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, DISPLAY_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, UPDATE_NEXT_MONTHS_ID}; | ||||
|  | ||||
| enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE}; | ||||
|  | ||||
| @@ -38,6 +38,7 @@ EVT_CALENDAR_SEL_CHANGED(CALENDAR_ID, AccountPanel::OnCalendarChange) | ||||
| EVT_RADIOBOX(DISPLAY_MODE_ID, AccountPanel::OnModeChange) | ||||
| EVT_BUTTON(GROUP_ID, AccountPanel::OnGroup) | ||||
| EVT_BUTTON(UNGROUP_ID, AccountPanel::OnUnGroup) | ||||
| EVT_BUTTON(UPDATE_NEXT_MONTHS_ID, AccountPanel::OnUpdateNextMonths) | ||||
| END_EVENT_TABLE() | ||||
|  | ||||
| AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _curMonth(-1), _curYear(-1), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT) | ||||
| @@ -132,8 +133,10 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare | ||||
|  | ||||
|     wxButton* buttonGroup = new wxButton(this, GROUP_ID, _("Group")); | ||||
|     wxButton* buttonUnGroup = new wxButton(this, UNGROUP_ID, _("UnGroup")); | ||||
|     wxButton* buttonUpdateNextMonths = new wxButton(this, UPDATE_NEXT_MONTHS_ID, _("Update next months")); | ||||
|      | ||||
|     vbox3->Add(&_tree, 0, wxGROW|wxALL, 2); | ||||
|     vbox3->Add(buttonUpdateNextMonths, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10); | ||||
|     vbox3->Add(buttonGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10); | ||||
|     vbox3->Add(buttonUnGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10); | ||||
|  | ||||
| @@ -985,3 +988,110 @@ void AccountPanel::OnUnGroup(wxCommandEvent& event) | ||||
| { | ||||
|     _grid->UnGroup(); | ||||
| } | ||||
|  | ||||
| void AccountPanel::OnUpdateNextMonths(wxCommandEvent& event) | ||||
| { | ||||
|     double* deltas, *cur_amounts, amount; | ||||
|     int i, a; | ||||
|     User* user = _kiss->GetUser(); | ||||
|     bool had_values, accounts_updated = false; | ||||
|     int last_month = 0, last_year = 0, account_updated = 0; | ||||
|     std::map<int, std::vector<int> > operations; | ||||
|  | ||||
|     deltas = new double[user->_accounts.size()] ; | ||||
|     cur_amounts = new double[user->_accounts.size()] ; | ||||
|  | ||||
|     operations = _kiss->GetAllOperations(); | ||||
|  | ||||
|     if (_curMonth == 11) | ||||
|     { | ||||
| 	last_month = 0; | ||||
| 	last_year = _curYear+1; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| 	last_month = _curMonth+1; | ||||
| 	last_year = _curYear; | ||||
|     } | ||||
|  | ||||
|     for (i=0; i<(int)user->_accounts.size(); i++) | ||||
|     { | ||||
| 	deltas[i] = _kiss->GetAccountAmount(user->_accounts[i].id, _curMonth, _curYear); | ||||
| 	cur_amounts[i] = deltas[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, _curMonth, _curYear, &had_values); | ||||
|  | ||||
| 	for (a=0; a<(int)operations[last_year].size(); a++) | ||||
| 	    if (operations[last_year][a] == last_month) break; | ||||
|  | ||||
| 	if (a == (int)operations[last_year].size()) | ||||
| 	{ | ||||
| 	    deltas[i] = 0; | ||||
| 	    continue; | ||||
| 	} | ||||
| 	 | ||||
| 	amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year); | ||||
|  | ||||
| 	deltas[i] -=  amount; | ||||
| 	     | ||||
| 	account_updated++; | ||||
|     } | ||||
|  | ||||
|     if (!account_updated) | ||||
| 	goto end; | ||||
|  | ||||
|     last_month = _curMonth; | ||||
|     last_year = _curYear; | ||||
|  | ||||
|     while (1) | ||||
|     { | ||||
| 	account_updated = 0; | ||||
|  | ||||
| 	if (last_month == 11) | ||||
| 	{ | ||||
| 	    last_month = 0; | ||||
| 	    last_year = last_year+1; | ||||
| 	} | ||||
| 	else | ||||
| 	    last_month++; | ||||
|  | ||||
| 	for (i=0; i<(int)user->_accounts.size(); i++) | ||||
| 	{ | ||||
| 	    if (deltas[i] == 0.0) continue; | ||||
|  | ||||
| 	    amount = _kiss->GetAccountAmount(user->_accounts[i].id, last_month, last_year); | ||||
| 	    if ((cur_amounts[i] - amount) != deltas[i]) continue; | ||||
|  | ||||
| 	    cur_amounts[i] = amount + deltas[i]; | ||||
| 	    _kiss->SetAccountAmount(last_month, last_year, user->_accounts[i].id, cur_amounts[i]); | ||||
| 	    cur_amounts[i] += _kiss->CalcAccountAmount(user->_accounts[i].id, last_month, last_year, &had_values); | ||||
|  | ||||
| 	    account_updated++; | ||||
| 	} | ||||
| 	 | ||||
| 	if (!account_updated) break; | ||||
|  | ||||
| 	accounts_updated = true; | ||||
|     } | ||||
|  | ||||
|     if (last_month == 0) | ||||
|     { | ||||
| 	last_month = 11; | ||||
| 	last_year--; | ||||
|     } | ||||
|     else | ||||
| 	last_month--; | ||||
|  | ||||
| end: | ||||
|     if (accounts_updated) | ||||
|     { | ||||
| 	wxString message = _("Accounts updated until ") + months[last_month]; | ||||
|  | ||||
| 	message += wxT(" ") + wxString::Format(wxT("%d"), last_year); | ||||
|  | ||||
|         wxMessageBox(message, wxT("KissCount"), wxICON_INFORMATION | wxOK); | ||||
|     } | ||||
|     else | ||||
|         wxMessageBox(_("Any account updated !"), wxT("KissCount"), wxICON_INFORMATION | wxOK); | ||||
|  | ||||
|     delete[] deltas; | ||||
|     delete[] cur_amounts; | ||||
| } | ||||
|   | ||||
| @@ -62,6 +62,7 @@ public: | ||||
|     void OnModeChange(wxCommandEvent& event); | ||||
|     void OnGroup(wxCommandEvent& event); | ||||
|     void OnUnGroup(wxCommandEvent& event); | ||||
|     void OnUpdateNextMonths(wxCommandEvent& event); | ||||
|  | ||||
|     int _curMonth, _curYear; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user