Add multi month operation support : Normal operation with description "... (XX/YY)" will be automatically forwarded to next month

This commit is contained in:
Grégory Soutadé 2018-07-06 20:23:31 +02:00
parent fe6bb52c52
commit 38770639be
3 changed files with 114 additions and 16 deletions

View File

@ -1,3 +1,16 @@
v0.8 (06/08/2018)
** User **
Add multi month operation support : Normal operation with description "... (XX/YY)" will be forwarded to next month
** Dev **
** Bugs **
v0.7.1 (07/05/2018)
** User **
** Dev **
** Bugs **
web: start and end date only compared to current date and not selected one
v0.7 (25/03/2018)
** User **
Set background calendar color to red or yellow when one account is negative or less than 200€ (configurable)

View File

@ -24,7 +24,9 @@
#include "KissCount.hpp"
#include <view/view.hpp>
#include <QRegularExpression>
std::vector<ImportEngine*> * KissCount::_importEngines;
std::vector<ExportEngine*> * KissCount::_exportEngines;
@ -285,12 +287,62 @@ std::map<int, std::vector<int> > KissCount::GetAllOperations()
return _db->GetAllOperations(_user);
}
int KissCount::CopyGeneratedOperation(int monthTo, int yearTo, Operation& opOrig, Operation& opDest,
std::map<int, int> &meta, QRegularExpression *regexp=0)
{
opDest = opOrig;
opDest.month = monthTo;
opDest.year = yearTo;
opDest.checked = false;
opDest.id = AddOperation(opDest);
opDest.childs.clear();
if (opOrig.meta)
meta[opOrig.id] = opDest.id;
if (regexp)
{
QRegularExpressionMatch match;
int first, second;
match = regexp->match(opOrig.description);
if (match.hasMatch())
{
first = match.captured(1).toInt();
second = match.captured(2).toInt();
if (first < second)
{
first++;
opDest.description = opOrig.description.left(match.capturedStart(1));
opDest.description += QString::number(first) + QString("/") + QString::number(second);
opDest.description += opOrig.description.right(opOrig.description.length()-match.capturedEnd(2));
}
}
}
if (!QDate::isValid(opDest.year, opDest.month+1, opDest.day+1))
{
QDate d(opDest.year, opDest.month+1, 1);
opDest.day = d.daysInMonth()-1;
return 1;
}
return 0;
}
int KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo)
{
std::vector<Operation>::iterator it, it2;
std::vector<int>::iterator childIt, copyIt;
std::map<int, int> meta;
Operation op;
int nb_update_days = 0;
Operation op, op2, parentOp, childOp;
std::vector<int> toCopy;
int nb_update_days = 0, first, second;
QRegularExpressionMatch match;
bool hasmatch;
/* Try to find something like XXX(1/5)XXX */
QRegularExpression regexp(".+\\((\\d+)/(\\d+)\\).*");
QString newDescription;
_db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo);
@ -305,26 +357,56 @@ int KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearT
it != (*_user->_operations[yearFrom])[monthFrom].end();
it++)
{
if (!it->fix_cost) continue;
op = *it;
op.month = monthTo;
op.year = yearTo;
op.checked = false;
op.id = AddOperation(op);
op.childs.clear();
if (op.meta)
meta[it->id] = op.id;
hasmatch = false;
if (!QDate::isValid(op.year, op.month+1, op.day+1))
if (!it->fix_cost)
{
QDate d(op.year, op.month+1, 1);
op.day = d.daysInMonth()-1;
nb_update_days++;
match = regexp.match(it->description);
if (!match.hasMatch())
continue;
hasmatch = true;
}
if (hasmatch)
{
first = match.captured(1).toInt();
second = match.captured(2).toInt();
if (first >= second)
continue;
if (!std::count(toCopy.begin(), toCopy.end(), it->id))
{
/* Copy only parent if has */
if (it->parent)
{
if (std::count(toCopy.begin(), toCopy.end(), it->parent))
continue;
toCopy.push_back(it->parent);
}
else
toCopy.push_back(it->id);
}
}
else
nb_update_days += CopyGeneratedOperation(monthTo, yearTo, *it, op, meta);
(*_user->_operations[yearTo])[monthTo].push_back(op);
}
/* Restart search and filter by copy */
for(it = (*_user->_operations[yearFrom])[monthFrom].begin();
it != (*_user->_operations[yearFrom])[monthFrom].end();
it++)
{
if (std::count(toCopy.begin(), toCopy.end(), it->id) ||
(it->parent && std::count(toCopy.begin(), toCopy.end(), it->parent)))
{
nb_update_days += CopyGeneratedOperation(monthTo, yearTo, *it, childOp, meta, &regexp);
(*_user->_operations[yearTo])[monthTo].push_back(childOp);
}
}
// Re Generate parents
for(it = (*_user->_operations[yearTo])[monthTo].begin();
it != (*_user->_operations[yearTo])[monthTo].end();

View File

@ -165,6 +165,9 @@ private:
static std::vector<ImportEngine*> *_importEngines;
static std::vector<ExportEngine*> *_exportEngines;
int CopyGeneratedOperation(int monthTo, int yearTo, Operation& opOrig, Operation& opDest,
std::map<int, int> &meta, QRegularExpression *regexp);
};
#endif