Show stats for current month even if next month has not been generated

Bug : Update all panels after generating/deleting month
This commit is contained in:
Grégory Soutadé 2011-01-29 20:53:44 +01:00
parent a2990ede8a
commit 1151daf861
7 changed files with 68 additions and 5 deletions

View File

@ -4,6 +4,7 @@ v0.2_dev (29/01/2011)
Better use of sizers (so better interface!) Better use of sizers (so better interface!)
No further problems with scrollbar in AccountPanel/SearchPanel/PreferencesPanel when there is a lot of operations No further problems with scrollbar in AccountPanel/SearchPanel/PreferencesPanel when there is a lot of operations
Better fit of interface when displaying grouped operations Better fit of interface when displaying grouped operations
Show stats for current month even if next month has not been generated
** Dev ** ** Dev **
Use a factory to create panels (prepare for plug-in) 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 Grouped operations have bad month/year in SearchPanel
Categories fonts not updated for new category --> crash Categories fonts not updated for new category --> crash
New category had read only fields in PreferencesPanel New category had read only fields in PreferencesPanel
Update all panels after generating/deleting month

View File

@ -93,6 +93,11 @@ double KissCount::GetAccountAmount(const wxString& id, int month, int year)
return _db->GetAccountAmount(id, month, 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) void KissCount::UpdateOperation(Operation& op)
{ {
// Unlink // Unlink

View File

@ -60,6 +60,8 @@ public:
double GetAccountAmount(const wxString& id, int month, int year); double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(int month, int year, const wxString& accountId, double value); 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); wxString AddAccount(Account& ac);
void UpdateAccount(Account& ac); void UpdateAccount(Account& ac);
void DeleteAccount(Account& ac); void DeleteAccount(Account& ac);

View File

@ -429,6 +429,38 @@ double Database::GetAccountAmount(const wxString& id, int month, int year)
return res; 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) bool Database::GetOperation(const wxString& id, Operation* op)
{ {
wxSQLite3ResultSet set; wxSQLite3ResultSet set;

View File

@ -62,6 +62,7 @@ public:
double GetAccountAmount(const wxString& id, int month, int year); double GetAccountAmount(const wxString& id, int month, int year);
void SetAccountAmount(int month, int year, const wxString& accountId, double amount); 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); wxString AddAccount(User* user, Account& ac);
void UpdateAccount(Account& ac); void UpdateAccount(Account& ac);

View File

@ -784,6 +784,7 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
month = ops[year][0]; month = ops[year][0];
ShowMonth(month, year); ShowMonth(month, year);
} }
_wxUI->NeedReload();
} }
void AccountPanel::GenerateMonth(int month, int year) void AccountPanel::GenerateMonth(int month, int year)
@ -856,6 +857,7 @@ void AccountPanel::GenerateMonth(int month, int year)
_tree.SelectItem(node, true); _tree.SelectItem(node, true);
ShowMonth(month, year); ShowMonth(month, year);
_wxUI->NeedReload();
} }
void AccountPanel::OnShow(wxShowEvent& event) void AccountPanel::OnShow(wxShowEvent& event)

View File

@ -174,6 +174,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
wxString value; wxString value;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
wxDateTime date; wxDateTime date;
bool failed;
if (_chart) if (_chart)
{ {
@ -256,18 +257,36 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
} }
size = accountAmounts[accountIt->id].size(); size = accountAmounts[accountIt->id].size();
amounts = new double[size*12*2]; amounts = new double[size*13*2];
size = 0; size = 0;
for(a = 0, accountYearIt = accountAmounts[accountIt->id].begin(); for(a = 0, accountYearIt = accountAmounts[accountIt->id].begin();
accountYearIt != accountAmounts[accountIt->id].end(); accountYearIt != accountAmounts[accountIt->id].end();
accountYearIt++, a++) 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+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++; size++;
} }
} }