From 951793567a77d87239d991a071a067e49dc229c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 3 Oct 2018 09:05:21 +0200 Subject: [PATCH] Auto fill operation amount if it was the same for the last 3 operations --- ChangeLog | 5 +++- src/controller/KissCount.cpp | 53 ++++++++++++++++++++++++++--------- src/view/grid/GridAccount.cpp | 6 ++++ 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 48a0bab..bfdf23b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,12 @@ -v0.8 (26/08/2018) +v0.8 (03/10/2018) ** User ** Add multi month operation support : Normal operation with description "... (XX/YY)" will be forwarded to next month + Auto fill operation amount if it was the same for the last 3 operations ** Dev ** ** Bugs ** Current account value is badly computed if operations are not in date order + NULLop was set with random values which can cause misunderstanding when entering a new operation + v0.7.1 (07/05/2018) diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 853691d..5e0726b 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -30,6 +30,9 @@ std::vector * KissCount::_importEngines; std::vector * 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 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) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 4d10ad2..ef86e82 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -1050,6 +1050,12 @@ void GridAccount::OnOperationModified(int row, int col) new_op.fix_cost = (new_op.category == user->GetCategoryId("Fix")); if (op_tmp.transfert != 0) transfertCompleted = true; + + /* Non null value --> set amount */ + if (op_tmp.amount > 0) + setItem(row, CREDIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)op_tmp.amount/100))); + else if (op_tmp.amount < 0) + setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)-op_tmp.amount/100))); } }