From 1151daf8613bf464cf340306bf9d1056e8d31306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 29 Jan 2011 20:53:44 +0100 Subject: [PATCH] Show stats for current month even if next month has not been generated Bug : Update all panels after generating/deleting month --- ChangeLog | 2 ++ src/controller/KissCount.cpp | 5 +++++ src/controller/KissCount.h | 2 ++ src/model/Database.cpp | 32 ++++++++++++++++++++++++++++++++ src/model/Database.h | 1 + src/view/AccountPanel.cpp | 2 ++ src/view/StatsPanel.cpp | 29 ++++++++++++++++++++++++----- 7 files changed, 68 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe146fa..aaeb6b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ v0.2_dev (29/01/2011) Better use of sizers (so better interface!) No further problems with scrollbar in AccountPanel/SearchPanel/PreferencesPanel when there is a lot of operations Better fit of interface when displaying grouped operations + Show stats for current month even if next month has not been generated ** Dev ** Use a factory to create panels (prepare for plug-in) @@ -21,3 +22,4 @@ v0.2_dev (29/01/2011) Grouped operations have bad month/year in SearchPanel Categories fonts not updated for new category --> crash New category had read only fields in PreferencesPanel + Update all panels after generating/deleting month diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 7cf3545..47df870 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -93,6 +93,11 @@ double KissCount::GetAccountAmount(const wxString& id, int month, int year) return _db->GetAccountAmount(id, month, year); } +double KissCount::CalcAccountAmount(const wxString& id, int month, int year, bool* had_values) +{ + return _db->CalcAccountAmount(id, month, year, had_values); +} + void KissCount::UpdateOperation(Operation& op) { // Unlink diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index 137a5d9..9f60ee6 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -60,6 +60,8 @@ public: double GetAccountAmount(const wxString& id, int month, int year); void SetAccountAmount(int month, int year, const wxString& accountId, double value); + double CalcAccountAmount(const wxString& id, int month, int year, bool* had_values); + wxString AddAccount(Account& ac); void UpdateAccount(Account& ac); void DeleteAccount(Account& ac); diff --git a/src/model/Database.cpp b/src/model/Database.cpp index ea9b9d0..1a81dac 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -429,6 +429,38 @@ double Database::GetAccountAmount(const wxString& id, int month, int year) return res; } +double Database::CalcAccountAmount(const wxString& id, int month, int year, bool* had_values) +{ + wxSQLite3ResultSet set; + wxString req; + double res; + + req = wxT("SELECT SUM(id) AS id, SUM(amount) AS amount FROM operation WHERE account='") + id ; + req += wxT("' AND month='") + wxString::Format(wxT("%d"), month); + req += wxT("' AND year='") + wxString::Format(wxT("%d"), year); + req += wxT("'"); + req += wxT(" AND meta='0'"); + + EXECUTE_SQL_QUERY(req , set, 0.0); + + if (set.NextRow()) + { + res = set.GetDouble(wxT("amount")); + if (had_values) + *had_values = set.GetInt(wxT("id")) > 0 ; + } + else + { + res=0.0; + if (had_values) + *had_values = false; + } + + set.Finalize(); + + return res; +} + bool Database::GetOperation(const wxString& id, Operation* op) { wxSQLite3ResultSet set; diff --git a/src/model/Database.h b/src/model/Database.h index aa23d3f..bced1e4 100644 --- a/src/model/Database.h +++ b/src/model/Database.h @@ -62,6 +62,7 @@ public: double GetAccountAmount(const wxString& id, int month, int year); void SetAccountAmount(int month, int year, const wxString& accountId, double amount); + double CalcAccountAmount(const wxString& id, int month, int year, bool* had_values); wxString AddAccount(User* user, Account& ac); void UpdateAccount(Account& ac); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 5963e7f..9edd09c 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -784,6 +784,7 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event) month = ops[year][0]; ShowMonth(month, year); } + _wxUI->NeedReload(); } void AccountPanel::GenerateMonth(int month, int year) @@ -856,6 +857,7 @@ void AccountPanel::GenerateMonth(int month, int year) _tree.SelectItem(node, true); ShowMonth(month, year); + _wxUI->NeedReload(); } void AccountPanel::OnShow(wxShowEvent& event) diff --git a/src/view/StatsPanel.cpp b/src/view/StatsPanel.cpp index 0a5a650..e9c32e2 100644 --- a/src/view/StatsPanel.cpp +++ b/src/view/StatsPanel.cpp @@ -174,6 +174,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT wxString value; User* user = _kiss->GetUser(); wxDateTime date; + bool failed; if (_chart) { @@ -256,18 +257,36 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT } size = accountAmounts[accountIt->id].size(); - amounts = new double[size*12*2]; + amounts = new double[size*13*2]; size = 0; for(a = 0, accountYearIt = accountAmounts[accountIt->id].begin(); accountYearIt != accountAmounts[accountIt->id].end(); accountYearIt++, a++) { - for(b = 0; b<12; b++) + for(b = 0; b<=12; b++) { - if (!accountAmounts[accountIt->id][accountYearIt->first].count(b)) - continue; amounts[size*2+0] = a*12+b; - amounts[size*2+1] = accountAmounts[accountIt->id][accountYearIt->first][b]; + if (!accountAmounts[accountIt->id][accountYearIt->first].count(b)) + { + /* + If previously afiled, continue to avoid to set + account to 0 (only for display) + */ + if (!b || failed) continue; + /* + Compute cur month value (if there are operations) + as next month value + */ + amounts[size*2+1] = + accountAmounts[accountIt->id][accountYearIt->first][b-1] + + _kiss->CalcAccountAmount(accountIt->id, b-1, accountYearIt->first, NULL); + failed = true; + } + else + { + amounts[size*2+1] = accountAmounts[accountIt->id][accountYearIt->first][b]; + failed = false; + } size++; } }