mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 00:20:41 -06:00
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* FireRulesForStore.php
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
*
|
|
* This software may be modified and distributed under the terms
|
|
* of the MIT license. See the LICENSE file for details.
|
|
*/
|
|
|
|
declare(strict_types = 1);
|
|
|
|
namespace FireflyIII\Handlers\Events;
|
|
|
|
|
|
use FireflyIII\Events\TransactionJournalStored;
|
|
use FireflyIII\Models\Rule;
|
|
use FireflyIII\Models\RuleGroup;
|
|
use FireflyIII\Rules\Processor;
|
|
use FireflyIII\User;
|
|
|
|
/**
|
|
* Class FireRulesForStore
|
|
*
|
|
* @package FireflyIII\Handlers\Events
|
|
*/
|
|
class FireRulesForStore
|
|
{
|
|
|
|
/**
|
|
* Connect a new transaction journal to any related piggy banks.
|
|
*
|
|
* @param TransactionJournalStored $event
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function handle(TransactionJournalStored $event): bool
|
|
{
|
|
// get all the user's rule groups, with the rules, order by 'order'.
|
|
/** @var User $user */
|
|
$user = auth()->user();
|
|
$groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get();
|
|
//
|
|
/** @var RuleGroup $group */
|
|
foreach ($groups as $group) {
|
|
$rules = $group->rules()
|
|
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
|
->where('rule_triggers.trigger_type', 'user_action')
|
|
->where('rule_triggers.trigger_value', 'store-journal')
|
|
->where('rules.active', 1)
|
|
->get(['rules.*']);
|
|
/** @var Rule $rule */
|
|
foreach ($rules as $rule) {
|
|
|
|
$processor = Processor::make($rule);
|
|
$processor->handleTransactionJournal($event->journal);
|
|
|
|
if ($rule->stop_processing) {
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|