From 271b3ef1e713c3c76b3bc1f1b8eaefa6d1fae14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 23 Jun 2010 20:30:42 +0200 Subject: [PATCH] Month generation OK --- controller/KissCount.cpp | 3 ++- model/Database.cpp | 6 +++--- view/AccountPanel.cpp | 17 +++++++++-------- view/GenerateDialog.cpp | 11 +++++++---- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/controller/KissCount.cpp b/controller/KissCount.cpp index d757df9..87fccc8 100644 --- a/controller/KissCount.cpp +++ b/controller/KissCount.cpp @@ -161,7 +161,8 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year op = *it; op.month = monthTo; op.year = yearTo; - AddOperation(op); + op.id = AddOperation(op); + (*_user->_operations[yearTo])[monthTo].push_back(op); } } _wxUI->GenerateMonth(monthTo, yearTo); diff --git a/model/Database.cpp b/model/Database.cpp index 1b17fcb..b4cd5fb 100644 --- a/model/Database.cpp +++ b/model/Database.cpp @@ -632,15 +632,15 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) { amount = 0.0; - req = _("SELECT SUM(amount) FROM operation WHERE") ; + req = _("SELECT amount FROM operation WHERE") ; req += _(" account='") + it->id + _("'"); req += _(" AND year='") + wxString::Format(_("%d"), yearFrom) + _("'"); req += _(" AND month='") + wxString::Format(_("%d"), monthFrom) + _("'"); EXECUTE_SQL_QUERY(req, set, ); - if (set.NextRow()) - amount = set.GetDouble(_("amount")); + while (set.NextRow()) + amount += set.GetDouble(_("amount")); req = _("SELECT amount FROM account_amount WHERE") ; req += _(" account='") + it->id + _("'"); diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index e9e50a4..61f3f20 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -223,10 +223,10 @@ void AccountPanel::LoadYear(int year, bool showMonth) { User* user = _kiss->GetUser(); int curMonth = -1; - std::map >::iterator it; wxDateTime curDate; wxTreeItemId parentNode, curMonthNode; - //std::map > Database::GetAllOperations(User* user) + std::map > ops ; + std::vector::iterator it; if (user->_operations[year]) { @@ -237,19 +237,20 @@ void AccountPanel::LoadYear(int year, bool showMonth) _curYear = year ; _kiss->LoadYear(year); + ops = _kiss->GetAllOperations(); curDate.SetToCurrent(); parentNode = _tree.GetSelection(); - for (it = user->_operations[year]->begin(); it != user->_operations[year]->end(); it++) + for (it = ops[year].begin(); it != ops[year].end(); it++) { - if (curMonth == -1 || (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth())) + if (curMonth == -1 || (year == curDate.GetYear() && *it <= curDate.GetMonth())) { - curMonth = it->first; - curMonthNode = _tree.AppendItem(parentNode, months[it->first]); + curMonth = *it; + curMonthNode = _tree.AppendItem(parentNode, months[*it]); } else - _tree.AppendItem(parentNode, months[it->first]); + _tree.AppendItem(parentNode, months[*it]); } _tree.Expand(parentNode); @@ -945,7 +946,7 @@ void AccountPanel::GenerateMonth(int month, int year) it != user->_operations[year]->end(); it++, i++) { - if ((int)it->first >= month) + if ((int)it->first > month) break; } years = _tree.InsertItem(years, i, monthString); diff --git a/view/GenerateDialog.cpp b/view/GenerateDialog.cpp index 328d3dd..a10f8d2 100644 --- a/view/GenerateDialog.cpp +++ b/view/GenerateDialog.cpp @@ -65,15 +65,18 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea { if (_monthFrom->GetString(i) == months[month]) { - toSelect = i+1; + toSelect = i; break; } } } _monthFrom->Select(toSelect); } - - OnYearFromChange(event); + else + { + _yearFrom->Select(0); + OnYearFromChange(event); + } for(i=2000; i<=2050; i++) _yearTo->Append(wxString::Format(_("%d"), i)); @@ -171,7 +174,7 @@ void GenerateDialog::OnOK(wxCommandEvent& event) { int monthFrom, yearFrom, monthTo, yearTo, i; - if (_yearFrom->GetString(_yearTo->GetCurrentSelection()) == _("")) + if (_yearFrom->GetString(_yearFrom->GetCurrentSelection()) == _("")) { monthFrom = -1; yearFrom = -1;