Fix a bug on stats (when total = 0)
Fix a bug modifying account values (infinite recursive loop)
This commit is contained in:
parent
dd5f231f20
commit
4583dae912
|
@ -453,13 +453,14 @@ void AccountPanel::UpdateStats()
|
||||||
std::map<wxString, double>* notChecked = NULL;
|
std::map<wxString, double>* notChecked = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
curCredit = curDebit = totalCredit = totalDebit = percents = 0.0;
|
||||||
|
|
||||||
if (checkMode)
|
if (checkMode)
|
||||||
{
|
{
|
||||||
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
|
notChecked = _kiss->GetNotChecked(_curMonth, _curYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
day = _calendar->GetDate().GetDay()-1;
|
day = _calendar->GetDate().GetDay()-1;
|
||||||
curCredit = curDebit = totalCredit = totalDebit = 0.0;
|
|
||||||
|
|
||||||
for (i=0; i<user->GetCategoriesNumber(); i++)
|
for (i=0; i<user->GetCategoriesNumber(); i++)
|
||||||
_categoriesValues[i] = 0.0;
|
_categoriesValues[i] = 0.0;
|
||||||
|
@ -515,7 +516,10 @@ void AccountPanel::UpdateStats()
|
||||||
|
|
||||||
for(i=0; i<user->GetCategoriesNumber()+1; i++)
|
for(i=0; i<user->GetCategoriesNumber()+1; i++)
|
||||||
{
|
{
|
||||||
percents = ((double) (_categoriesValues[i]*100))/totalDebit;
|
if (totalDebit != 0)
|
||||||
|
percents = ((double) (_categoriesValues[i]*100))/totalDebit;
|
||||||
|
else
|
||||||
|
percents = 0.0;
|
||||||
_statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents));
|
_statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,12 +822,20 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
|
||||||
double amount;
|
double amount;
|
||||||
wxString id = user->GetAccountId(_accounts[row]);
|
wxString id = user->GetAccountId(_accounts[row]);
|
||||||
|
|
||||||
|
static bool inModification = false;
|
||||||
|
|
||||||
|
if (inModification) return ;
|
||||||
|
|
||||||
|
inModification = true;
|
||||||
|
|
||||||
_accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
|
_accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
|
||||||
|
|
||||||
_kiss->SetAccountAmount(_curMonth, _curYear, id, amount);
|
_kiss->SetAccountAmount(_curMonth, _curYear, id, amount);
|
||||||
_accountsInitValues[id] = amount;
|
_accountsInitValues[id] = amount;
|
||||||
|
|
||||||
UpdateStats();
|
UpdateStats();
|
||||||
|
|
||||||
|
inModification = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
||||||
|
|
|
@ -259,7 +259,10 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||||
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
|
for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++)
|
||||||
{
|
{
|
||||||
_categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second;
|
_categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second;
|
||||||
percents = ((double) (categoriesIt->second*100))/total;
|
if (total)
|
||||||
|
percents = ((double) (categoriesIt->second*100))/total;
|
||||||
|
else
|
||||||
|
percents = 0;
|
||||||
value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents);
|
value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents);
|
||||||
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
|
_statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user