A lot of good job done
This commit is contained in:
@@ -148,7 +148,7 @@ User* Database::LoadUser(wxString name)
|
||||
wxString req;
|
||||
User* user;
|
||||
struct Account account;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
req = _("SELECT * FROM user WHERE name='") + name + _("'");
|
||||
|
||||
@@ -176,18 +176,18 @@ User* Database::LoadUser(wxString name)
|
||||
account.number = set.GetAsString(_("number"));
|
||||
account.shared = set.GetBool(_("shared"));
|
||||
account._default = set.GetBool(_("default_account"));
|
||||
user->_accounts[account.id] = account;
|
||||
user->_accounts.push_back(account);
|
||||
}
|
||||
set.Finalize();
|
||||
|
||||
if (!user->_accounts.empty())
|
||||
{
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->first;
|
||||
req = _("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + it->first ;
|
||||
req += _("', '") + it->id ;
|
||||
}
|
||||
req += _("') ORDER BY year ASC");
|
||||
|
||||
@@ -223,17 +223,17 @@ void Database::LoadYear(User* user, int year)
|
||||
{
|
||||
wxSQLite3ResultSet set;
|
||||
wxString req;
|
||||
std::map<wxString, Account>::iterator it;
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
if (user->_operations[year] == NULL)
|
||||
user->_operations[year] = new std::map<unsigned int, std::vector<operation> >();
|
||||
|
||||
it = user->_accounts.begin();
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + it->first;
|
||||
req = _("SELECT * FROM operation WHERE account IN('") + it->id;
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
req += _("', '") + it->first ;
|
||||
req += _("', '") + it->id ;
|
||||
}
|
||||
req += _("') ORDER BY fix_cost DESC, year,month,day ASC");
|
||||
|
||||
@@ -306,9 +306,11 @@ void Database::UpdateOperation(struct operation op)
|
||||
|
||||
}
|
||||
|
||||
void Database::AddOperation(User* user, struct operation op)
|
||||
wxString Database::AddOperation(User* user, struct operation op)
|
||||
{
|
||||
wxString req;
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
|
||||
req = _("INSERT INTO operation ('user', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost') VALUES ('") ;
|
||||
req += user->_id + _("'");
|
||||
req += _(", '") + op.account + _("'");
|
||||
@@ -324,7 +326,33 @@ void Database::AddOperation(User* user, struct operation op)
|
||||
req += _(", '0'") ;
|
||||
req += _(")");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||
|
||||
req = _("SELECT id FROM operation WHERE ");
|
||||
req += _("user='") + user->_id + _("'");
|
||||
req += _(" AND account='") + op.account + _("'");
|
||||
req += _(" AND year='") + wxString::Format(_("%d"), op.year) + _("'");
|
||||
req += _(" AND month='") + wxString::Format(_("%d"), op.month) + _("'");
|
||||
req += _(" AND day='") + wxString::Format(_("%d"), op.day) + _("'");
|
||||
req += _(" AND amount='") + wxString::Format(_("%.2lf"), op.amount) + _("'");
|
||||
req += _(" AND description=\"") + op.description + _("\"");
|
||||
req += _(" AND category='") + op.category + _("'");
|
||||
if (op.fix_cost)
|
||||
req += _(" AND fix_cost='1'") ;
|
||||
else
|
||||
req += _(" AND fix_cost='0'") ;
|
||||
req += _("ORDER BY ID DESC") ;
|
||||
|
||||
EXECUTE_SQL_QUERY(req , set, _("0"));
|
||||
|
||||
if (set.NextRow())
|
||||
res = set.GetAsString(_("id"));
|
||||
else
|
||||
res = _("0");
|
||||
|
||||
set.Finalize();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::DeleteOperation(struct operation op)
|
||||
@@ -347,9 +375,11 @@ void Database::SetAccountAmount(int month, int year, wxString accountId, double
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
void Database::InsertAccount(User* user, struct Account ac)
|
||||
wxString Database::AddAccount(User* user, struct Account ac)
|
||||
{
|
||||
wxString req;
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
|
||||
req = _("INSERT INTO account ('user', 'name', 'number', 'shared', 'default_account') VALUES ('") ;
|
||||
req += user->_id + _("'");
|
||||
req += _(", '") + ac.name + _("'");
|
||||
@@ -364,7 +394,20 @@ void Database::InsertAccount(User* user, struct Account ac)
|
||||
req += _(", '0'") ;
|
||||
req += _(")");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||
|
||||
req = _("SELECT id FROM account WHERE name='") + ac.name + _("'") ;
|
||||
|
||||
EXECUTE_SQL_QUERY(req , set, _("0"));
|
||||
|
||||
if (set.NextRow())
|
||||
res = set.GetAsString(_("id"));
|
||||
else
|
||||
res = _("0");
|
||||
|
||||
set.Finalize();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::UpdateAccount(struct Account ac)
|
||||
|
||||
@@ -25,12 +25,12 @@ class Database
|
||||
void LoadYear(User* user, int year);
|
||||
|
||||
void UpdateOperation(struct operation op);
|
||||
void AddOperation(User* user, struct operation op);
|
||||
wxString AddOperation(User* user, struct operation op);
|
||||
void DeleteOperation(struct operation op);
|
||||
double GetAccountAmount(wxString id, int month, int year);
|
||||
void SetAccountAmount(int month, int year, wxString accountId, double amount);
|
||||
|
||||
void InsertAccount(User* user, struct Account ac);
|
||||
wxString AddAccount(User* user, struct Account ac);
|
||||
void UpdateAccount(struct Account ac);
|
||||
void DeleteAccount(struct Account ac);
|
||||
|
||||
|
||||
@@ -33,17 +33,20 @@ wxString User::GetCategoryId(wxString catName)
|
||||
|
||||
wxString User::GetAccountName(wxString accountId)
|
||||
{
|
||||
if (_accounts.find(accountId) == _accounts.end())
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->id == accountId)
|
||||
return it->name;
|
||||
|
||||
return _("Unknown") ;
|
||||
return _accounts[accountId].name;
|
||||
}
|
||||
|
||||
wxString User::GetAccountId(wxString accountName)
|
||||
{
|
||||
std::map<wxString, wxString>::iterator it;
|
||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
||||
if (it->second == accountName)
|
||||
return it->first;
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->name == accountName)
|
||||
return it->id;
|
||||
|
||||
return _("0") ;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
wxString _id;
|
||||
wxString _name;
|
||||
wxString _password;
|
||||
std::map<wxString, Account> _accounts;
|
||||
std::vector<Account> _accounts;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* > _operations;
|
||||
Preferences _preferences;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user