|
|
|
|
@@ -271,6 +271,7 @@ User* Database::LoadUser(const wxString& name)
|
|
|
|
|
account.name = set.GetAsString(wxT("name"));
|
|
|
|
|
account.number = set.GetAsString(wxT("number"));
|
|
|
|
|
account.shared = set.GetBool(wxT("shared"));
|
|
|
|
|
account.blocked = set.GetBool(wxT("blocked"));
|
|
|
|
|
account._default = set.GetBool(wxT("default_account"));
|
|
|
|
|
account.is_owner = true;
|
|
|
|
|
user->_accounts.push_back(account);
|
|
|
|
|
@@ -287,6 +288,7 @@ User* Database::LoadUser(const wxString& name)
|
|
|
|
|
account.name = set.GetAsString(wxT("name"));
|
|
|
|
|
account.number = set.GetAsString(wxT("number"));
|
|
|
|
|
account.shared = set.GetBool(wxT("shared"));
|
|
|
|
|
account.blocked = set.GetBool(wxT("blocked"));
|
|
|
|
|
account._default = set.GetBool(wxT("default_account"));
|
|
|
|
|
account.is_owner = false;
|
|
|
|
|
user->_accounts.push_back(account);
|
|
|
|
|
@@ -754,7 +756,7 @@ wxString Database::AddAccount(User* user, Account& ac)
|
|
|
|
|
{
|
|
|
|
|
wxString req;
|
|
|
|
|
|
|
|
|
|
req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'default_account') VALUES ('") ;
|
|
|
|
|
req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account') VALUES ('") ;
|
|
|
|
|
req += user->_id + wxT("'");
|
|
|
|
|
req += wxT(", '") + ac.name + wxT("'");
|
|
|
|
|
req += wxT(", '") + ac.number + wxT("'");
|
|
|
|
|
@@ -762,6 +764,10 @@ wxString Database::AddAccount(User* user, Account& ac)
|
|
|
|
|
req += wxT(", '1'") ;
|
|
|
|
|
else
|
|
|
|
|
req += wxT(", '0'") ;
|
|
|
|
|
if (ac.blocked)
|
|
|
|
|
req += wxT(", '1'") ;
|
|
|
|
|
else
|
|
|
|
|
req += wxT(", '0'") ;
|
|
|
|
|
if (ac._default)
|
|
|
|
|
req += wxT(", '1'") ;
|
|
|
|
|
else
|
|
|
|
|
@@ -783,6 +789,10 @@ void Database::UpdateAccount(Account& ac)
|
|
|
|
|
req += wxT(", shared='1'");
|
|
|
|
|
else
|
|
|
|
|
req += wxT(", shared='0'");
|
|
|
|
|
if (ac.blocked)
|
|
|
|
|
req += wxT(", blocked='1'");
|
|
|
|
|
else
|
|
|
|
|
req += wxT(", blocked='0'");
|
|
|
|
|
if (ac._default)
|
|
|
|
|
req += wxT(", default_account='1'");
|
|
|
|
|
else
|
|
|
|
|
@@ -1389,7 +1399,7 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
|
|
|
|
|
std::map<wxString, double>* categories)
|
|
|
|
|
{
|
|
|
|
|
wxSQLite3ResultSet set;
|
|
|
|
|
wxString req;
|
|
|
|
|
wxString req, req2;
|
|
|
|
|
std::vector<Account>::iterator accountIt;
|
|
|
|
|
std::vector<Category>::iterator categoryIt;
|
|
|
|
|
|
|
|
|
|
@@ -1412,7 +1422,7 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
|
|
|
|
|
|
|
|
|
|
for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
|
|
|
|
{
|
|
|
|
|
req = wxT("SELECT SUM(amount) as amount FROM operation WHERE category='") + categoryIt->id + wxT("'");
|
|
|
|
|
req = wxT("SELECT SUM(amount) as amount FROM operation AS o1 WHERE category='") + categoryIt->id + wxT("'");
|
|
|
|
|
accountIt = user->_accounts.begin();
|
|
|
|
|
req += wxT(" AND (account IN('") + accountIt->id;
|
|
|
|
|
accountIt++;
|
|
|
|
|
@@ -1425,17 +1435,31 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
|
|
|
|
|
|
|
|
|
|
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 (transfert='' OR transfert IS NULL)");
|
|
|
|
|
req += wxT(" AND amount < 0");
|
|
|
|
|
req += wxT(" AND meta='0'");
|
|
|
|
|
|
|
|
|
|
EXECUTE_SQL_QUERY(req, set, );
|
|
|
|
|
req2 = req + wxT(" AND (transfert='' OR transfert IS NULL)");
|
|
|
|
|
req2 += wxT(" AND amount < 0");
|
|
|
|
|
|
|
|
|
|
EXECUTE_SQL_QUERY(req2, set, );
|
|
|
|
|
|
|
|
|
|
if (set.NextRow())
|
|
|
|
|
{
|
|
|
|
|
(*categories)[categoryIt->id] = -set.GetDouble(wxT("amount"));
|
|
|
|
|
}
|
|
|
|
|
set.Finalize();
|
|
|
|
|
|
|
|
|
|
// Transfert on blocked accounts must be computed
|
|
|
|
|
req2 = req + wxT(" AND transfert != ''");
|
|
|
|
|
req2 = req + wxT(" AND (SELECT blocked FROM account WHERE id=o1.account)");
|
|
|
|
|
req2 += wxT(" AND amount > 0");
|
|
|
|
|
|
|
|
|
|
EXECUTE_SQL_QUERY(req2, set, );
|
|
|
|
|
|
|
|
|
|
if (set.NextRow())
|
|
|
|
|
{
|
|
|
|
|
(*categories)[categoryIt->id] += set.GetDouble(wxT("amount"));
|
|
|
|
|
}
|
|
|
|
|
set.Finalize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|