New view and what-not for feature.

This commit is contained in:
Sander Dorigo
2014-10-12 08:19:18 +02:00
parent 287c2e7af8
commit 5f4db7874c
6 changed files with 101 additions and 5 deletions

View File

@@ -32,6 +32,48 @@ class EloquentRecurringTrigger
{
}
public function rescan(\RecurringTransaction $recurring, \TransactionJournal $journal)
{
/*
* Match words.
*/
$wordMatch = false;
$matches = explode(' ', $recurring->match);
$description = strtolower($journal->description);
$count = 0;
foreach ($matches as $word) {
if (!(strpos($description, $word) === false)) {
$count++;
}
}
if ($count > 0) {
$wordMatch = true;
}
/*
* Match amount.
*/
$transactions = $journal->transactions()->get();
$amountMatch = false;
if (count($transactions) > 1) {
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
$min = floatval($recurring->amount_min);
$max = floatval($recurring->amount_max);
if ($amount >= $min && $amount <= $max) {
$amountMatch = true;
}
}
/*
* If both, update!
*/
if ($wordMatch && $amountMatch) {
$journal->recurringTransaction()->associate($recurring);
$journal->save();
}
}
/**
* Trigger!
*
@@ -39,6 +81,8 @@ class EloquentRecurringTrigger
*/
public function subscribe(Dispatcher $events)
{
//Event::fire('recurring.rematch', [$recurringTransaction, $journal]);
$events->listen('recurring.rescan', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@rescan');
// $events->listen('recurring.destroy', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@destroy');
// $events->listen('recurring.store', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@store');
// $events->listen('recurring.update', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@update');