From 6568acbae7ca339bd1498a0d8edbfd986a98a8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 25 Oct 2010 21:33:09 +0200 Subject: [PATCH] Meta specifications where not reported into search --- src/model/Database.cpp | 19 +++++++++++++++---- src/model/User.cpp | 19 ++++++++++++++----- src/model/User.h | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 5b505fb..fd6e0f4 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1229,7 +1229,8 @@ std::vector* Database::Search(User* user, wxString* description, wxDa std::vector::iterator it; std::vector::iterator accountIt; std::vector* res = new std::vector; - + int i; + wxString dayFrom, monthFrom, yearFrom; wxString dayTo, monthTo, yearTo; wxString desc; @@ -1311,19 +1312,20 @@ std::vector* Database::Search(User* user, wxString* description, wxDa if (accounts.size()) { - req += wxT("account IN ('"); + req += wxT("(account IN ('"); it = accounts.begin(); req += *it; it++; - for (; it != categories.end(); it++) + for (; it != accounts.end(); it++) req += wxT("', '") + *it ; req += wxT("')"); + req += wxT(" OR user ='") + user->_id + wxT("')"); } else { - req += wxT("account IN ('"); + req += wxT("(account IN ('"); accountIt = user->_accounts.begin(); req += accountIt->id; accountIt++; @@ -1332,6 +1334,7 @@ std::vector* Database::Search(User* user, wxString* description, wxDa req += wxT("', '") + accountIt->id ; } req += wxT("')"); + req += wxT(" OR user ='") + user->_id + wxT("')"); } req += wxT(" ORDER BY year ") ; @@ -1347,6 +1350,7 @@ std::vector* Database::Search(User* user, wxString* description, wxDa { Operation op; op.id = set.GetAsString(wxT("id")); + op.parent = set.GetAsString(wxT("parent")); op.account = set.GetAsString(wxT("account")); op.day = set.GetInt(wxT("day")); op.month = set.GetInt(wxT("month")); @@ -1356,9 +1360,16 @@ std::vector* Database::Search(User* user, wxString* description, wxDa op.category = set.GetAsString(wxT("category")); op.fix_cost = set.GetBool(wxT("fix_cost")); op.checked = set.GetBool(wxT("checked")); + op.transfert = set.GetAsString(wxT("transfert")); + op.formula = set.GetAsString(wxT("formula")); + op.meta = set.GetBool(wxT("meta")); res->push_back(op); } + for(i=0; i < (int)res->size(); i++) + if ((*res)[i].parent.Length()) + user->Group(res, (*res)[i]); + return res; } diff --git a/src/model/User.cpp b/src/model/User.cpp index 911e8b7..df40721 100644 --- a/src/model/User.cpp +++ b/src/model/User.cpp @@ -181,12 +181,12 @@ void User::LinkOrUnlinkOperation(Operation& op) } } -void User::Group(const Operation& op) +bool User::Group(std::vector* ops, const Operation& op) { std::vector::iterator it; std::vector::iterator it2; - for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++) + for (it = ops->begin(); it != ops->end(); it++) { if (it->id == op.parent) { @@ -194,13 +194,22 @@ void User::Group(const Operation& op) if (*it2 == op.id) break; // Already into childs - if (it2 != it->childs.end()) return; + if (it2 != it->childs.end()) return true; it->childs.push_back(op.id); - return; + return true; } } - if (_db->LoadOperation(this, op.parent)) + return false ; +} + +void User::Group(const Operation& op) +{ + std::vector::iterator it; + std::vector::iterator it2; + + if (!Group(&(*_operations[op.year])[op.month], op) + && _db->LoadOperation(this, op.parent)) { (*_operations[op.year])[op.month][(*_operations[op.year])[op.month].size()-1].childs.push_back(op.id); } diff --git a/src/model/User.h b/src/model/User.h index a7c13e5..257cb7a 100644 --- a/src/model/User.h +++ b/src/model/User.h @@ -59,6 +59,7 @@ public: wxLanguage GetLanguage(); void LinkOrUnlinkOperation(Operation& op); void Group(const Operation& op); + bool Group(std::vector* ops, const Operation& op); void UnGroup(const Operation& op); void ResolveGroups(int year);