This commit is contained in:
Grégory Soutadé 2011-01-08 12:35:04 +01:00
parent b30604fffe
commit 63ccfc7f97
2 changed files with 26 additions and 20 deletions

View File

@ -51,14 +51,19 @@ public:
wxString GetCategoryName(wxString& catId); wxString GetCategoryName(wxString& catId);
wxString GetCategoryId(wxString& catName); wxString GetCategoryId(wxString& catName);
const wxFont GetCategoryFont(wxString& catId); const wxFont GetCategoryFont(wxString& catId);
Account GetAccount(const wxString& accountId); Account GetAccount(const wxString& accountId);
wxString GetAccountName(const wxString& accountId); wxString GetAccountName(const wxString& accountId);
wxString GetAccountId(wxString& accountName); wxString GetAccountId(wxString& accountName);
int GetCategoriesNumber(); int GetCategoriesNumber();
int GetAccountsNumber(); int GetAccountsNumber();
int GetOperationsNumber(int month, int year); int GetOperationsNumber(int month, int year);
wxLanguage GetLanguage(); wxLanguage GetLanguage();
void LinkOrUnlinkOperation(Operation& op); void LinkOrUnlinkOperation(Operation& op);
void Group(const Operation& op); void Group(const Operation& op);
bool Group(std::vector<Operation>* ops, const Operation& op); bool Group(std::vector<Operation>* ops, const Operation& op);
void UnGroup(const Operation& op); void UnGroup(const Operation& op);

View File

@ -54,10 +54,12 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _ki
_yearTo->Append(wxString::Format(wxT("%d"), it->first)); _yearTo->Append(wxString::Format(wxT("%d"), it->first));
} }
_monthFrom->Select(0); if (i) i--;
_monthTo->Select(11);
_yearFrom->Select(i); _yearFrom->Select(i);
_yearTo->Select(i); _yearTo->Select(i);
_monthFrom->Select(0);
_monthTo->Select(11);
wxStaticText* label = new wxStaticText(this, wxID_ANY, _("From")); wxStaticText* label = new wxStaticText(this, wxID_ANY, _("From"));
hbox->Add(label); hbox->Add(label);
@ -152,12 +154,11 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
std::map<wxString, std::map<int, std::map<int, double> > > accountAmounts; std::map<wxString, std::map<int, std::map<int, double> > > accountAmounts;
std::map<wxString, double> categories; std::map<wxString, double> categories;
std::map<wxString, std::vector<double> > operations; std::map<wxString, std::vector<double> > operations;
std::map<wxString, std::vector<double> >::iterator accountIdIt2; std::vector<Account>::iterator accountIt;
std::map<wxString, double>::iterator categoriesIt; std::map<wxString, double>::iterator categoriesIt;
std::map<wxString, std::map<int, std::map<int, double> > >::iterator accountIdIt;
std::map<int, std::map<int, double> >::iterator accountYearIt; std::map<int, std::map<int, double> >::iterator accountYearIt;
double total; double total;
int size, i, a, b, percents, account, nbDays; int account, size, i, a, b, percents, nbDays;
double *amounts; double *amounts;
wxString value; wxString value;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
@ -193,10 +194,10 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
dataset->AddSerie((double *) amounts, nbDays); dataset->AddSerie((double *) amounts, nbDays);
delete[] amounts; delete[] amounts;
for (account = 0, i = 0, accountIdIt2 = operations.begin(); accountIdIt2 != operations.end(); for (account = 0, i = 0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end();
accountIdIt2++, i++, account++) account++, accountIt++, i++)
{ {
if (!((wxCheckListBox*)_account)->IsChecked(account)) if (!_account->IsChecked(account))
{ {
i-- ; i-- ;
continue; continue;
@ -207,11 +208,11 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
for (a=0; a<nbDays; a++) for (a=0; a<nbDays; a++)
{ {
amounts[a*2+0] = a; amounts[a*2+0] = a;
amounts[a*2+1] = operations[accountIdIt2->first][a]; amounts[a*2+1] = operations[accountIt->id][a];
} }
dataset->AddSerie((double *) amounts, nbDays); dataset->AddSerie((double *) amounts, nbDays);
// set serie names to be displayed on legend // set serie names to be displayed on legend
dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt2->first)); dataset->SetSerieName(i+1, user->GetAccountName(accountIt->id));
delete[] amounts; delete[] amounts;
} }
} }
@ -234,34 +235,34 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
dataset->AddSerie((double *) amounts, size); dataset->AddSerie((double *) amounts, size);
delete[] amounts; delete[] amounts;
for (account = 0, i = 0, accountIdIt = accountAmounts.begin(); accountIdIt != accountAmounts.end(); for (account = 0, i = 0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end();
accountIdIt++, i++, account++) account++, accountIt++, i++)
{ {
if (!((wxCheckListBox*)_account)->IsChecked(account)) if (!_account->IsChecked(account))
{ {
i-- ; i-- ;
continue; continue;
} }
size = accountAmounts[accountIdIt->first].size(); size = accountAmounts[accountIt->id].size();
amounts = new double[size*12*2]; amounts = new double[size*12*2];
size = 0; size = 0;
for(a = 0, accountYearIt = accountAmounts[accountIdIt->first].begin(); for(a = 0, accountYearIt = accountAmounts[accountIt->id].begin();
accountYearIt != accountAmounts[accountIdIt->first].end(); accountYearIt != accountAmounts[accountIt->id].end();
accountYearIt++, a++) accountYearIt++, a++)
{ {
for(b = 0; b<12; b++) for(b = 0; b<12; b++)
{ {
if (!accountAmounts[accountIdIt->first][accountYearIt->first].count(b)) if (!accountAmounts[accountIt->id][accountYearIt->first].count(b))
continue; continue;
amounts[size*2+0] = a*12+b; amounts[size*2+0] = a*12+b;
amounts[size*2+1] = accountAmounts[accountIdIt->first][accountYearIt->first][b]; amounts[size*2+1] = accountAmounts[accountIt->id][accountYearIt->first][b];
size++; size++;
} }
} }
dataset->AddSerie((double *) amounts, size); dataset->AddSerie((double *) amounts, size);
// set serie names to be displayed on legend // set serie names to be displayed on legend
dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt->first)); dataset->SetSerieName(i+1, user->GetAccountName(accountIt->id));
delete[] amounts; delete[] amounts;
} }
} }
@ -340,7 +341,7 @@ void StatsPanel::OnRangeChange(wxCommandEvent& event)
monthTo = _monthTo->GetCurrentSelection(); monthTo = _monthTo->GetCurrentSelection();
_yearTo->GetStringSelection().ToLong(&yearTo); _yearTo->GetStringSelection().ToLong(&yearTo);
if (yearTo > yearFrom || if (yearTo < yearFrom ||
(yearFrom == yearTo && monthFrom > monthTo)) (yearFrom == yearTo && monthFrom > monthTo))
{ {
wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK); wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK);