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!)
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

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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++;
}
}