Fix GetAllOperations bug and new user (GenerateMonth) bug
This commit is contained in:
parent
496ef95ce0
commit
3e53e67859
|
@ -102,10 +102,12 @@ void KissCount::SetAccountAmount(int month, int year, wxString accountId, double
|
||||||
_db->SetAccountAmount(month, year, accountId, amount);
|
_db->SetAccountAmount(month, year, accountId, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KissCount::AddAccount(Account ac)
|
wxString KissCount::AddAccount(Account ac)
|
||||||
{
|
{
|
||||||
ac.id = _db->AddAccount(_user, ac);
|
ac.id = _db->AddAccount(_user, ac);
|
||||||
_user->_accounts.push_back(ac);
|
_user->_accounts.push_back(ac);
|
||||||
|
|
||||||
|
return ac.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KissCount::UpdateAccount(Account ac)
|
void KissCount::UpdateAccount(Account ac)
|
||||||
|
@ -230,7 +232,6 @@ void KissCount::NewUser(wxString name)
|
||||||
curDate.SetToCurrent();
|
curDate.SetToCurrent();
|
||||||
|
|
||||||
AddAccount(ac);
|
AddAccount(ac);
|
||||||
|
|
||||||
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
|
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class KissCount
|
||||||
|
|
||||||
double GetAccountAmount(wxString id, int month, int year);
|
double GetAccountAmount(wxString id, int month, int year);
|
||||||
void SetAccountAmount(int month, int year, wxString accountId, double value);
|
void SetAccountAmount(int month, int year, wxString accountId, double value);
|
||||||
void AddAccount(Account ac);
|
wxString AddAccount(Account ac);
|
||||||
void UpdateAccount(Account ac);
|
void UpdateAccount(Account ac);
|
||||||
void DeleteAccount(Account ac);
|
void DeleteAccount(Account ac);
|
||||||
|
|
||||||
|
|
47
init.sql
47
init.sql
|
@ -14,25 +14,28 @@ INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "L
|
||||||
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Frais de fonctionnement", "#3DEB3D", "");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Frais de fonctionnement", "#3DEB3D", "");
|
||||||
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Exceptionnel", "#3DEB3D", "");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Exceptionnel", "#3DEB3D", "");
|
||||||
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Autre", "#3DEB3D", "");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Autre", "#3DEB3D", "");
|
||||||
-- No password
|
|
||||||
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
|
||||||
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
|
|
||||||
-- May 2009
|
-- -- No password
|
||||||
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("1", "0", "2009", "4", "500");
|
-- INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("1", "0", "0", "2009", "4", "0", "1234", "Opé May 1", "1", "1", "0");
|
-- INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
|
||||||
-- May 2010
|
-- -- May 2009
|
||||||
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "4", "500");
|
-- INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("1", "0", "2009", "4", "500");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("2", "0", "0", "2010", "4", "0", "1234", "Opé May 1", "1", "1", "0");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("1", "0", "0", "2009", "4", "0", "1234", "Opé May 1", "1", "1", "0");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("3", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
|
-- -- May 2010
|
||||||
-- June 2010
|
-- INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "4", "500");
|
||||||
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("3", "0", "2010", "5", "1000");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("2", "0", "0", "2010", "4", "0", "1234", "Opé May 1", "1", "1", "0");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("4", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1", "0");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("3", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
|
-- -- June 2010
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
|
-- INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("3", "0", "2010", "5", "1000");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("7", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("4", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1", "0");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Fixe", "#FFFF99", "");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Courses", "#3DEB3D", "");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Loisirs", "#3DEB3D", "");
|
-- INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("7", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Frais de fonctionnement", "#3DEB3D", "");
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Fixe", "#FFFF99", "");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Exceptionnel", "#3DEB3D", "");
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Courses", "#3DEB3D", "");
|
||||||
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Autre", "#3DEB3D", "");
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Loisirs", "#3DEB3D", "");
|
||||||
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Frais de fonctionnement", "#3DEB3D", "");
|
||||||
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Exceptionnel", "#3DEB3D", "");
|
||||||
|
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Autre", "#3DEB3D", "");
|
||||||
|
|
|
@ -606,7 +606,7 @@ void Database::DeleteCategory(User* user, Category category)
|
||||||
|
|
||||||
std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||||
{
|
{
|
||||||
wxString req;
|
wxString req, req2, reqUnion;
|
||||||
wxSQLite3ResultSet set, set2;
|
wxSQLite3ResultSet set, set2;
|
||||||
std::vector<Account>::iterator it;
|
std::vector<Account>::iterator it;
|
||||||
std::map<int, std::vector<int> > res;
|
std::map<int, std::vector<int> > res;
|
||||||
|
@ -615,35 +615,56 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
||||||
if (!user->_accounts.empty())
|
if (!user->_accounts.empty())
|
||||||
{
|
{
|
||||||
it = user->_accounts.begin();
|
it = user->_accounts.begin();
|
||||||
req = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id;
|
req = wxT("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id;
|
||||||
it++;
|
it++;
|
||||||
for (;it != user->_accounts.end(); it++)
|
for (;it != user->_accounts.end(); it++)
|
||||||
{
|
{
|
||||||
req += wxT("', '") + it->id ;
|
req += wxT("', '") + it->id ;
|
||||||
}
|
}
|
||||||
req += wxT("')");
|
req += wxT("')");
|
||||||
req += wxT(" OR user='") + user->_id + wxT("'");
|
|
||||||
req += wxT(" ORDER BY year ASC");
|
|
||||||
|
|
||||||
EXECUTE_SQL_QUERY(req, set, res);
|
it = user->_accounts.begin();
|
||||||
|
req2 = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id;
|
||||||
|
it++;
|
||||||
|
for (;it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
req2 += wxT("', '") + it->id ;
|
||||||
|
}
|
||||||
|
req2 += wxT("')");
|
||||||
|
req2 += wxT(" OR user='") + user->_id + wxT("'");
|
||||||
|
req2 += wxT(" ORDER BY year ASC");
|
||||||
|
|
||||||
|
reqUnion = req + wxT(" UNION ") + req2;
|
||||||
|
EXECUTE_SQL_QUERY(reqUnion, set, res);
|
||||||
|
|
||||||
while (set.NextRow())
|
while (set.NextRow())
|
||||||
{
|
{
|
||||||
year = set.GetInt(wxT("year"));
|
year = set.GetInt(wxT("year"));
|
||||||
|
|
||||||
it = user->_accounts.begin();
|
it = user->_accounts.begin();
|
||||||
req = wxT("SELECT DISTINCT month FROM operation WHERE (account IN('") + it->id;
|
req = wxT("SELECT DISTINCT month FROM account_amount WHERE account IN('") + it->id;
|
||||||
it++;
|
it++;
|
||||||
for (;it != user->_accounts.end(); it++)
|
for (;it != user->_accounts.end(); it++)
|
||||||
{
|
{
|
||||||
req += wxT("', '") + it->id ;
|
req += wxT("', '") + it->id ;
|
||||||
}
|
}
|
||||||
req += wxT("')");
|
req += wxT("')");
|
||||||
req += wxT(" OR user='") + user->_id + wxT("')");
|
|
||||||
req += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'");
|
req += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'");
|
||||||
req += wxT(" ORDER BY month ASC");
|
|
||||||
|
|
||||||
EXECUTE_SQL_QUERY(req, set2, res);
|
it = user->_accounts.begin();
|
||||||
|
req2 = wxT("SELECT DISTINCT month FROM operation WHERE (account IN('") + it->id;
|
||||||
|
it++;
|
||||||
|
for (;it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
req2 += wxT("', '") + it->id ;
|
||||||
|
}
|
||||||
|
req2 += wxT("')");
|
||||||
|
req2 += wxT(" OR user='") + user->_id + wxT("')");
|
||||||
|
req2 += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'");
|
||||||
|
req2 += wxT(" ORDER BY month ASC");
|
||||||
|
|
||||||
|
reqUnion = req + wxT(" UNION ") + req2;
|
||||||
|
EXECUTE_SQL_QUERY(reqUnion, set2, res);
|
||||||
|
|
||||||
while (set2.NextRow())
|
while (set2.NextRow())
|
||||||
{
|
{
|
||||||
|
|
|
@ -208,34 +208,37 @@ void AccountPanel::InitStatsGrid(User* user)
|
||||||
|
|
||||||
void AccountPanel::ChangeUser()
|
void AccountPanel::ChangeUser()
|
||||||
{
|
{
|
||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
int curYear = -1;
|
int curYear = -1;
|
||||||
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
|
wxDateTime curDate;
|
||||||
wxDateTime curDate;
|
wxTreeItemId rootNode, curNode;
|
||||||
wxTreeItemId rootNode, curNode;
|
std::map<int, std::vector<int> > ops;
|
||||||
|
std::map<int, std::vector<int> >::iterator it;
|
||||||
InitStatsGrid(user);
|
|
||||||
|
|
||||||
_tree.DeleteAllItems();
|
ops = _kiss->GetAllOperations();
|
||||||
rootNode = _tree.AddRoot(wxT(""));
|
|
||||||
|
|
||||||
curDate.SetToCurrent();
|
InitStatsGrid(user);
|
||||||
for(it = user->_operations.begin(); it != user->_operations.end(); it++)
|
|
||||||
|
_tree.DeleteAllItems();
|
||||||
|
rootNode = _tree.AddRoot(wxT(""));
|
||||||
|
|
||||||
|
curDate.SetToCurrent();
|
||||||
|
for(it = ops.begin(); it != ops.end(); it++)
|
||||||
|
{
|
||||||
|
if ((int)it->first <= curDate.GetYear())
|
||||||
{
|
{
|
||||||
if ((int)it->first <= curDate.GetYear())
|
curYear = it->first;
|
||||||
{
|
curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||||
curYear = it->first;
|
|
||||||
curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
|
||||||
}
|
|
||||||
Fit();
|
|
||||||
if (curYear != -1)
|
|
||||||
{
|
|
||||||
_tree.SelectItem(curNode, true);
|
|
||||||
LoadYear(curYear);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||||
|
}
|
||||||
|
Fit();
|
||||||
|
if (curYear != -1)
|
||||||
|
{
|
||||||
|
_tree.SelectItem(curNode, true);
|
||||||
|
LoadYear(curYear);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::LoadYear(int year, bool showMonth)
|
void AccountPanel::LoadYear(int year, bool showMonth)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user