mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #608
This commit is contained in:
parent
209a907c61
commit
f0dab5bdb9
61
app/Rules/Triggers/HasAttachment.php
Normal file
61
app/Rules/Triggers/HasAttachment.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* HasAttachment.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules\Triggers;
|
||||
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
class HasAttachment extends AbstractTrigger implements TriggerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* A trigger is said to "match anything", or match any given transaction,
|
||||
* when the trigger value is very vague or has no restrictions. Easy examples
|
||||
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
||||
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
||||
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
||||
*
|
||||
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
||||
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
||||
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
||||
* false.
|
||||
*
|
||||
* @param null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function willMatchEverything($value = null)
|
||||
{
|
||||
$value = intval($value);
|
||||
if ($value < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$minimum = intval($this->triggerValue);
|
||||
$attachments = $journal->attachments()->count();
|
||||
if ($attachments >= $minimum) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -176,6 +176,7 @@ return [
|
||||
'category_is' => 'FireflyIII\Rules\Triggers\CategoryIs',
|
||||
'budget_is' => 'FireflyIII\Rules\Triggers\BudgetIs',
|
||||
'tag_is' => 'FireflyIII\Rules\Triggers\TagIs',
|
||||
'has_attachments' => 'FireflyIII\Rules\Triggers\HasAttachment',
|
||||
],
|
||||
'rule-actions' => [
|
||||
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',
|
||||
|
@ -287,6 +287,8 @@ return [
|
||||
'rule_trigger_category_is_choice' => 'Category is..',
|
||||
'rule_trigger_budget_is_choice' => 'Budget is..',
|
||||
'rule_trigger_tag_is_choice' => '(A) tag is..',
|
||||
'rule_trigger_has_attachments_choice' => 'Has at least this many attachments',
|
||||
'rule_trigger_has_attachments' => 'Has at least :trigger_value attachment(s)',
|
||||
'rule_trigger_store_journal' => 'When a transaction is created',
|
||||
'rule_trigger_update_journal' => 'When a transaction is updated',
|
||||
'rule_action_set_category' => 'Set category to ":action_value"',
|
||||
|
Loading…
Reference in New Issue
Block a user