Auto fill operation amount if it was the same for the last 3 operations

This commit is contained in:
Grégory Soutadé 2018-10-03 09:05:21 +02:00
parent 10c534857d
commit 951793567a
3 changed files with 50 additions and 14 deletions

View File

@ -1,9 +1,12 @@
v0.8 (26/08/2018) v0.8 (03/10/2018)
** User ** ** User **
Add multi month operation support : Normal operation with description "... (XX/YY)" will be forwarded to next month 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 ** ** Dev **
** Bugs ** ** Bugs **
Current account value is badly computed if operations are not in date order 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) v0.7.1 (07/05/2018)

View File

@ -30,6 +30,9 @@
std::vector<ImportEngine*> * KissCount::_importEngines; std::vector<ImportEngine*> * KissCount::_importEngines;
std::vector<ExportEngine*> * KissCount::_exportEngines; 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) KissCount::KissCount(int& argc, char** argv) : QApplication(argc, argv), _user(0)
{ {
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
@ -562,15 +565,11 @@ bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month
//wxDateSpan threeMonths(0, 3); Not working :( //wxDateSpan threeMonths(0, 3); Not working :(
std::vector<int> v; std::vector<int> v;
int i; int i;
bool ret = false;
int same_amount = SAME_AMOUNT_THRESHOLD-1, same_amount_value = 0;
month -= 3; QDate date = QDate(year, month+1, 1);
if (month < 0) date = date.addMonths(-3);
{
year -= 1;
month += 12;
}
QDate date = QDate(year, month, 0);
if (limitToType) 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); 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--) 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)
{
index--;
continue;
}
if (!ret)
{
// First time found
*res = (*operations)[i]; *res = (*operations)[i];
delete operations; res->amount = 0;
return true; 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; delete operations;
return false; return ret;
} }
void KissCount::GetHistory(int month, int year, QStringList& list) void KissCount::GetHistory(int month, int year, QStringList& list)

View File

@ -1050,6 +1050,12 @@ void GridAccount::OnOperationModified(int row, int col)
new_op.fix_cost = (new_op.category == user->GetCategoryId("Fix")); new_op.fix_cost = (new_op.category == user->GetCategoryId("Fix"));
if (op_tmp.transfert != 0) if (op_tmp.transfert != 0)
transfertCompleted = true; 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)));
} }
} }