mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
New view and what-not for feature.
This commit is contained in:
@@ -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');
|
||||
|
Reference in New Issue
Block a user