* Goup/Ungroup initial work

* Add INSTALL file
* Adapt KissCount to new resolution
This commit is contained in:
2010-09-22 21:02:29 +02:00
parent e7a2b0c988
commit 3eea053d54
15 changed files with 203 additions and 17 deletions

View File

@@ -371,9 +371,11 @@ void Database::LoadYear(User* user, int year)
op.checked = set.GetBool(wxT("checked"));
op.transfert = set.GetAsString(wxT("transfert"));
op.formula = set.GetAsString(wxT("formula"));
op.meta = set.GetBool(wxT("meta"));
(*user->_operations[op.year])[op.month].push_back(op);
}
user->ResolveGroups(year);
set.Finalize();
}
@@ -427,6 +429,7 @@ bool Database::GetOperation(const wxString& id, Operation* op)
op->checked = set.GetBool(wxT("checked"));
op->transfert = set.GetAsString(wxT("transfert"));
op->formula = set.GetAsString(wxT("formula"));
op->meta = set.GetBool(wxT("meta"));
return true;
}
@@ -506,6 +509,10 @@ void Database::UpdateOperation(Operation& op)
else
req += wxT(", checked='0'");
req += wxT(", transfert='") + op.transfert + wxT("'");
if (op.meta)
req += wxT(", meta='1'");
else
req += wxT(", meta='0'");
req += wxT(", formula='") + op.formula + wxT("'");
req += wxT(" WHERE id='") + op.id + wxT("'");
@@ -521,7 +528,7 @@ wxString Database::AddOperation(User* user, Operation& op)
ESCAPE_CHARS(op.description);
req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert') VALUES ('") ;
req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta') VALUES ('") ;
req += user->_id + wxT("'");
req += wxT(", '") + op.parent + wxT("'");
req += wxT(", '") + op.account + wxT("'");
@@ -537,6 +544,10 @@ wxString Database::AddOperation(User* user, Operation& op)
req += wxT(", '0'") ;
req += wxT(", '") + op.formula + wxT("'");
req += wxT(", '") + op.transfert + wxT("'");
if (op.meta)
req += wxT(", '1'") ;
else
req += wxT(", '0'") ;
req += wxT(")");
EXECUTE_SQL_UPDATE(req, wxT("0"));
@@ -850,6 +861,7 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT
req += wxT(" account='") + it->id + wxT("'");
req += wxT(" AND year='") + wxString::Format(wxT("%d"), yearFrom) + wxT("'");
req += wxT(" AND month='") + wxString::Format(wxT("%d"), monthFrom) + wxT("'");
req += wxT(" AND meta='0'");
EXECUTE_SQL_QUERY(req, set, );
@@ -1194,6 +1206,7 @@ void Database::GetStats(User* user, const wxString& monthFrom, const wxString& y
req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))");
req += wxT(" AND (transfert='' OR transfert IS NULL)");
req += wxT(" AND amount < 0");
req += wxT(" AND meta='0'");
EXECUTE_SQL_QUERY(req, set, );
@@ -1217,6 +1230,7 @@ std::vector<Account>::iterator accountIt;
{
req = wxT("SELECT SUM(amount) AS amount FROM operation WHERE account='") + accountIt->id + wxT("'");
req += wxT(" AND checked='0'");
req += wxT(" AND meta='0'");
req += wxT(" AND (year < '") + wxString::Format(wxT("%d"), year) + wxT("'") ;
req += wxT(" OR (year == '") + wxString::Format(wxT("%d"), year) + wxT("'") ;
req += wxT(" AND month < '") + wxString::Format(wxT("%d"), month) + wxT("'") ;

View File

@@ -35,6 +35,8 @@ public:
bool checked;
wxString transfert;
wxString formula;
bool meta;
std::vector<Operation*> childs;
} ;
#endif

View File

@@ -160,3 +160,56 @@ void User::LinkOrUnlinkOperation(Operation& op)
op.transfert = wxT("");
}
}
void User::Group(Operation* op)
{
std::vector<Operation>::iterator it;
std::vector<Operation*>::iterator it2;
for (it = (*_operations[op->year])[op->month].begin(); it != (*_operations[op->year])[op->month].end(); it++)
{
if (it->id == op->parent)
{
for (it2 = it->childs.begin(); it2 != it->childs.end(); it2++)
if ((*it2)->id == op->id)
break;
// Already into childs
if (it2 != it->childs.end()) return;
it->childs.push_back(op);
break;
}
}
}
void User::UnGroup(Operation* op)
{
std::vector<Operation>::iterator it;
std::vector<Operation*>::iterator it2;
for (it = (*_operations[op->year])[op->month].begin(); it != (*_operations[op->year])[op->month].end(); it++)
{
if (it->id == op->parent)
{
for (it2 = it->childs.begin(); it2 != it->childs.end(); it2++)
if ((*it2)->id == op->id)
{
it->childs.erase(it2);
return;
}
break;
}
}
}
void User::ResolveGroups(int year)
{
unsigned int i;
std::map<unsigned int, std::vector<Operation> >::iterator it;
for (it = _operations[year]->begin(); it != _operations[year]->end(); it++)
{
for (i=0; i<it->second.size(); i++)
if (it->second[i].parent.Length())
Group(&((*_operations[year])[it->first])[i]);
}
}

View File

@@ -54,6 +54,9 @@ public:
int GetOperationsNumber(int month, int year);
wxLanguage GetLanguage();
void LinkOrUnlinkOperation(Operation& op);
void Group(Operation* op);
void UnGroup(Operation* op);
void ResolveGroups(int year);
};
#endif