Add blocked account (mainly for statistics)

Really fix the previous bug
This commit is contained in:
2010-11-01 11:34:39 +01:00
parent 7af9f1d9c2
commit 0832e020c4
11 changed files with 220 additions and 130 deletions

View File

@@ -30,6 +30,7 @@ public:
wxString name;
wxString number;
bool shared;
bool blocked;
bool _default;
bool is_owner;
};

View File

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

View File

@@ -102,6 +102,14 @@ const wxFont User::GetCategoryFont(wxString& catId)
return f;
}
Account User::GetAccount(const wxString& accountId)
{
std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++)
if (it->id == accountId)
return *it;
}
wxString User::GetAccountName(const wxString& accountId)
{
std::vector<Account>::iterator it;

View File

@@ -51,6 +51,7 @@ public:
wxString GetCategoryName(wxString& catId);
wxString GetCategoryId(wxString& catName);
const wxFont GetCategoryFont(wxString& catId);
Account GetAccount(const wxString& accountId);
wxString GetAccountName(const wxString& accountId);
wxString GetAccountId(wxString& accountName);
int GetCategoriesNumber();