KissCount

KissCount Commit Details

Date:2018-07-06 20:23:31 (1 year 3 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:38770639bedc2ef9f8f9a91b5f40d77642d87f73
Parents: fe6bb52c52c2d115b006dc3f251ece5bbeb4e6be
Message:Add multi month operation support : Normal operation with description "... (XX/YY)" will be automatically forwarded to next month

Changes:
MChangeLog (1 diff)
Msrc/controller/KissCount.cpp (3 diffs)
Msrc/controller/KissCount.hpp (1 diff)

File differences

ChangeLog
1
2
3
4
5
6
7
8
9
10
11
12
13
114
215
316
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)
src/controller/KissCount.cpp
2424
2525
2626
27
27
28
29
2830
2931
3032
......
285287
286288
287289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
288333
289334
290335
336
291337
292
293
338
339
340
341
342
343
344
345
294346
295347
296348
......
305357
306358
307359
308
309
310
311
312
313
314
315
316
317
318
360
361
362
319363
320
321
322
364
365
366
367
323368
324369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
325394
326395
327396
397
398
399
400
401
402
403
404
405
406
407
408
409
328410
329411
330412
#include "KissCount.hpp"
#include <view/view.hpp>
#include <QRegularExpression>
std::vector<ImportEngine*> * KissCount::_importEngines;
std::vector<ExportEngine*> * KissCount::_exportEngines;
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);
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;
if (!QDate::isValid(op.year, op.month+1, op.day+1))
hasmatch = false;
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();
src/controller/KissCount.hpp
165165
166166
167167
168
169
170
168171
169172
170173
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

Archive Download the corresponding diff file