Fix GetAllOperations bug and new user (GenerateMonth) bug

This commit is contained in:
Grégory Soutadé 2010-07-03 12:22:46 +02:00
parent 496ef95ce0
commit 3e53e67859
5 changed files with 86 additions and 58 deletions

View File

@ -102,10 +102,12 @@ void KissCount::SetAccountAmount(int month, int year, wxString accountId, double
_db->SetAccountAmount(month, year, accountId, amount);
}
void KissCount::AddAccount(Account ac)
wxString KissCount::AddAccount(Account ac)
{
ac.id = _db->AddAccount(_user, ac);
_user->_accounts.push_back(ac);
return ac.id;
}
void KissCount::UpdateAccount(Account ac)
@ -230,7 +232,6 @@ void KissCount::NewUser(wxString name)
curDate.SetToCurrent();
AddAccount(ac);
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
}

View File

@ -33,7 +33,7 @@ class KissCount
double GetAccountAmount(wxString id, int month, int year);
void SetAccountAmount(int month, int year, wxString accountId, double value);
void AddAccount(Account ac);
wxString AddAccount(Account ac);
void UpdateAccount(Account ac);
void DeleteAccount(Account ac);

View File

@ -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", "Exceptionnel", "#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
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 ("1", "0", "0", "2009", "4", "0", "1234", "Opé May 1", "1", "1", "0");
-- May 2010
INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "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 ("3", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
-- June 2010
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 ("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 ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
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 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", "Fixe", "#FFFF99", "");
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Courses", "#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", "");
-- -- 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
-- 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 ("1", "0", "0", "2009", "4", "0", "1234", "Opé May 1", "1", "1", "0");
-- -- May 2010
-- INSERT INTO account_amount("id", "account", "year", "month", "amount") VALUES("2", "0", "2010", "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 ("3", "0", "0", "2010", "4", "1", "-56", "Opé May 2", "2", "0", "0");
-- -- June 2010
-- 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 ("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 ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
-- 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 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", "Fixe", "#FFFF99", "");
-- INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Courses", "#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", "");

View File

@ -606,7 +606,7 @@ void Database::DeleteCategory(User* user, Category category)
std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
{
wxString req;
wxString req, req2, reqUnion;
wxSQLite3ResultSet set, set2;
std::vector<Account>::iterator it;
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())
{
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++;
for (;it != user->_accounts.end(); it++)
{
req += wxT("', '") + it->id ;
}
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())
{
year = set.GetInt(wxT("year"));
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++;
for (;it != user->_accounts.end(); it++)
{
req += wxT("', '") + it->id ;
}
req += wxT("')");
req += wxT(" OR user='") + user->_id + 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())
{

View File

@ -208,34 +208,37 @@ void AccountPanel::InitStatsGrid(User* user)
void AccountPanel::ChangeUser()
{
User* user = _kiss->GetUser();
int curYear = -1;
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
wxDateTime curDate;
wxTreeItemId rootNode, curNode;
InitStatsGrid(user);
User* user = _kiss->GetUser();
int curYear = -1;
wxDateTime curDate;
wxTreeItemId rootNode, curNode;
std::map<int, std::vector<int> > ops;
std::map<int, std::vector<int> >::iterator it;
_tree.DeleteAllItems();
rootNode = _tree.AddRoot(wxT(""));
ops = _kiss->GetAllOperations();
curDate.SetToCurrent();
for(it = user->_operations.begin(); it != user->_operations.end(); it++)
InitStatsGrid(user);
_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));
}
else
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
}
Fit();
if (curYear != -1)
{
_tree.SelectItem(curNode, true);
LoadYear(curYear);
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);
}
}
void AccountPanel::LoadYear(int year, bool showMonth)