Skip to content

Firefly III: a personal finances manager

Fixed some bugs in the recurring transaction match.

Sander Dorigob4ea1839a5c5
diff --git a/app/lib/Firefly/Helper/Toolkit/Toolkit.php b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
index 90674e381e..0266c01728 100644
--- a/app/lib/Firefly/Helper/Toolkit/Toolkit.php
+++ b/app/lib/Firefly/Helper/Toolkit/Toolkit.php
@@ -175,6 +175,9 @@ class Toolkit implements ToolkitInterface
{
$end = clone $start;
switch ($range) {
+ default:
+ throw new FireflyException('_updateEndDate cannot handle $range ' . $range);
+ break;
case '1D':
$end->endOfDay();
break;
@@ -197,9 +200,7 @@ class Toolkit implements ToolkitInterface
case '1Y':
$end->endOfYear();
break;
- default:
- throw new FireflyException('_updateEndDate cannot handle $range ' . $range);
- break;
+
}
return $end;
@@ -241,6 +242,9 @@ class Toolkit implements ToolkitInterface
protected function _previous($range, Carbon $date)
{
switch ($range) {
+ default:
+ throw new FireflyException('Cannot do _previous() on ' . $range);
+ break;
case '1D':
$date->startOfDay()->subDay();
break;
@@ -264,9 +268,7 @@ class Toolkit implements ToolkitInterface
case '1Y':
$date->startOfYear()->subYear();
break;
- default:
- throw new FireflyException('Cannot do _previous() on ' . $range);
- break;
+
}
return $date;
}
diff --git a/app/lib/Firefly/Trigger/Journals/EloquentJournalTrigger.php b/app/lib/Firefly/Trigger/Journals/EloquentJournalTrigger.php
index 38d2030a31..402b1a3326 100644
--- a/app/lib/Firefly/Trigger/Journals/EloquentJournalTrigger.php
+++ b/app/lib/Firefly/Trigger/Journals/EloquentJournalTrigger.php
@@ -23,12 +23,13 @@ class EloquentJournalTrigger
/*
* Grab all recurring events.
*/
- $set = $journal->user()->first()->recurringtransactions()->get();
+ $set = $journal->user()->first()->recurringtransactions()->get();
$result = [];
/*
* Prep vars
*/
$description = strtolower($journal->description);
+ $result = [0 => 0];
/** @var \RecurringTransaction $recurring */
foreach ($set as $recurring) {
@@ -44,7 +45,16 @@ class EloquentJournalTrigger
\Log::debug('Recurring transaction #' . $recurring->id . ': word "' . $word . '" found in "' . $description . '".');
}
}
- $result[$recurring->id] = $count;
+ /*
+ * Check the amount if match on words:
+ */
+ $amount = max(floatval($journal->transactions[0]->amount), floatval($journal->transactions[1]->amount));
+ $min = floatval($recurring->amount_min);
+ $max = floatval($recurring->amount_max);
+ if ($amount >= $min && $amount <= $max) {
+ $result[$recurring->id] = $count;
+ }
+
}
/*
* The one with the highest value is the winrar!
@@ -54,7 +64,9 @@ class EloquentJournalTrigger
/*
* Find the recurring transaction:
*/
- if (count($result[$index]) > 0) {
+
+ if ($result[$index] > 0 && $index > 0) {
+
$winner = $journal->user()->first()->recurringtransactions()->find($index);
if ($winner) {
$journal->recurringTransaction()->associate($winner);