Fixed some bugs in the recurring transaction match.

This commit is contained in:
Sander Dorigo 2014-10-12 08:03:35 +02:00
parent 6a6d889983
commit b4ea1839a5
2 changed files with 23 additions and 9 deletions

View File

@ -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;
}

View File

@ -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);