wip
This commit is contained in:
@@ -605,3 +605,60 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
wxString req;
|
||||
wxSQLite3ResultSet set;
|
||||
double amount;
|
||||
|
||||
if (monthFrom == -1 || yearFrom == -1)
|
||||
{
|
||||
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
||||
{
|
||||
req = _("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ;
|
||||
req += it->id + _("'");
|
||||
req += _(" ,'") + wxString::Format(_("%d"), yearTo) + _("'");
|
||||
req += _(" ,'") + wxString::Format(_("%d"), monthTo) + _("'");
|
||||
req += _(" ,'0.0'");
|
||||
req += _(")");
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
||||
{
|
||||
amount = 0.0;
|
||||
req = _("SELECT SUM(amount) FROM operation WHERE") ;
|
||||
req += _(" account='") + it->id + _("'");
|
||||
req += _(" AND year='") + wxString::Format(_("%d"), yearFrom) + _("'");
|
||||
req += _(" AND month='") + wxString::Format(_("%d"), monthFrom) + _("'");
|
||||
|
||||
EXECUTE_SQL_QUERY(req, set, );
|
||||
|
||||
if (set.NextRow())
|
||||
amount = set.GetDouble(_("amount"));
|
||||
|
||||
req = _("SELECT amount FROM account_amount WHERE") ;
|
||||
req += _(" account='") + it->id + _("'");
|
||||
req += _(" AND year='") + wxString::Format(_("%d"), yearFrom) + _("'");
|
||||
req += _(" AND month='") + wxString::Format(_("%d"), monthFrom) + _("'");
|
||||
|
||||
EXECUTE_SQL_QUERY(req, set, );
|
||||
|
||||
if (set.NextRow())
|
||||
amount += set.GetDouble(_("amount"));
|
||||
|
||||
req = _("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ;
|
||||
req += it->id + _("'");
|
||||
req += _(" ,'") + wxString::Format(_("%d"), yearTo) + _("'");
|
||||
req += _(" ,'") + wxString::Format(_("%d"), monthTo) + _("'");
|
||||
req += _(" ,'") + wxString::Format(_("%.2lf"), amount) + _("'");
|
||||
req += _(")");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ class Database
|
||||
void DeleteCategory(User* user, struct category category);
|
||||
|
||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||
|
||||
private:
|
||||
wxSQLite3Database _db;
|
||||
|
||||
Reference in New Issue
Block a user