First version of statistics (very ugly code)
This commit is contained in:
@@ -365,7 +365,7 @@ void Database::UpdateOperation(Operation& op)
|
||||
req += wxT(", checked='1'");
|
||||
else
|
||||
req += wxT(", checked='0'");
|
||||
req += wxT(", forumla='") + op.formula + wxT("'");
|
||||
req += wxT(", formula='") + op.formula + wxT("'");
|
||||
req += wxT(" WHERE id='") + op.id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
@@ -1056,3 +1056,56 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
|
||||
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
||||
std::map<wxString, double>* categories)
|
||||
{
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
|
||||
if (!user->_accounts.empty())
|
||||
{
|
||||
for (accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
|
||||
{
|
||||
req = wxT("SELECT month, year, amount FROM account_amount WHERE account ='") + accountIt->id + wxT("'");
|
||||
|
||||
EXECUTE_SQL_QUERY(req, set, );
|
||||
|
||||
while (set.NextRow())
|
||||
{
|
||||
(*accountAmounts)[accountIt->id][set.GetInt(wxT("year"))][set.GetInt(wxT("month"))] = set.GetInt(wxT("amount"));
|
||||
}
|
||||
set.Finalize();
|
||||
}
|
||||
|
||||
for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
||||
{
|
||||
req = wxT("SELECT SUM(amount) as amount FROM operation WHERE category='") + categoryIt->id + wxT("'");
|
||||
accountIt = user->_accounts.begin();
|
||||
req += wxT(" AND (account IN('") + accountIt->id;
|
||||
accountIt++;
|
||||
for (;accountIt != user->_accounts.end(); accountIt++)
|
||||
{
|
||||
req += wxT("', '") + accountIt->id ;
|
||||
}
|
||||
req += wxT("')");
|
||||
req += wxT(" OR user='") + user->_id + wxT("')");
|
||||
|
||||
req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))");
|
||||
|
||||
req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))");
|
||||
req += wxT(" AND amount < 0");
|
||||
|
||||
EXECUTE_SQL_QUERY(req, set, );
|
||||
|
||||
if (set.NextRow())
|
||||
{
|
||||
(*categories)[categoryIt->id] = -set.GetDouble(wxT("amount"));
|
||||
}
|
||||
set.Finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -71,6 +71,10 @@ class Database
|
||||
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
||||
wxString* amountFrom, wxString* amountTo,
|
||||
std::vector<wxString> categories, std::vector<wxString> accounts);
|
||||
|
||||
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
|
||||
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
||||
std::map<wxString, double>* categories);
|
||||
|
||||
void KillMe(User* user);
|
||||
private:
|
||||
|
@@ -70,7 +70,7 @@ wxString User::GetCategoryId(wxString& catName)
|
||||
return wxT("0") ;
|
||||
}
|
||||
|
||||
wxString User::GetAccountName(wxString& accountId)
|
||||
wxString User::GetAccountName(const wxString& accountId)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
|
@@ -45,7 +45,7 @@ class User
|
||||
Category GetCategory(wxString& catId);
|
||||
wxString GetCategoryName(wxString& catId);
|
||||
wxString GetCategoryId(wxString& catName);
|
||||
wxString GetAccountName(wxString& accountId);
|
||||
wxString GetAccountName(const wxString& accountId);
|
||||
wxString GetAccountId(wxString& accountName);
|
||||
int GetCategoriesNumber();
|
||||
int GetAccountsNumber();
|
||||
|
Reference in New Issue
Block a user