Auto fill operation amount if it was the same for the last 3 operations
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
std::vector<ImportEngine*> * KissCount::_importEngines;
|
||||
std::vector<ExportEngine*> * KissCount::_exportEngines;
|
||||
|
||||
/* Fill amount if it was the same for the last X operations */
|
||||
#define SAME_AMOUNT_THRESHOLD 3
|
||||
|
||||
KissCount::KissCount(int& argc, char** argv) : QApplication(argc, argv), _user(0)
|
||||
{
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
|
||||
@@ -562,15 +565,11 @@ bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month
|
||||
//wxDateSpan threeMonths(0, 3); Not working :(
|
||||
std::vector<int> v;
|
||||
int i;
|
||||
bool ret = false;
|
||||
int same_amount = SAME_AMOUNT_THRESHOLD-1, same_amount_value = 0;
|
||||
|
||||
month -= 3;
|
||||
if (month < 0)
|
||||
{
|
||||
year -= 1;
|
||||
month += 12;
|
||||
}
|
||||
|
||||
QDate date = QDate(year, month, 0);
|
||||
QDate date = QDate(year, month+1, 1);
|
||||
date = date.addMonths(-3);
|
||||
|
||||
if (limitToType)
|
||||
operations = _db->Search(_user, &op.description, &date, 0, 0, 0, v, op.fix_cost ? +Database::FIX_OP : +Database::NON_FIX_OP, v, false, v);
|
||||
@@ -584,16 +583,44 @@ bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month
|
||||
}
|
||||
|
||||
for(i=operations->size()-1; i>=0; i--)
|
||||
if (!(*operations)[i].meta && index--)
|
||||
{
|
||||
if ((*operations)[i].meta)
|
||||
continue ;
|
||||
|
||||
/* If it's a transfert, take index in account */
|
||||
if ((*operations)[i].transfert && index > 0)
|
||||
{
|
||||
*res = (*operations)[i];
|
||||
delete operations;
|
||||
return true;
|
||||
index--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
// First time found
|
||||
*res = (*operations)[i];
|
||||
res->amount = 0;
|
||||
ret = true;
|
||||
same_amount_value = (*operations)[i].amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*operations)[i].amount == same_amount_value)
|
||||
{
|
||||
/* X time same amount */
|
||||
if (!same_amount--)
|
||||
{
|
||||
res->amount = same_amount_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete operations;
|
||||
|
||||
return false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void KissCount::GetHistory(int month, int year, QStringList& list)
|
||||
|
||||
Reference in New Issue
Block a user