mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New triggers and actions for notes. #872
This commit is contained in:
parent
7a57c60891
commit
95b5793f63
55
app/TransactionRules/Actions/AppendNotes.php
Normal file
55
app/TransactionRules/Actions/AppendNotes.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* AppendNotes.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\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AppendNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
*/
|
||||
class AppendNotes implements ActionInterface
|
||||
{
|
||||
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes');
|
||||
Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $notes));
|
||||
$notes = $notes . $this->action->action_value;
|
||||
$journal->setMeta('notes', $notes);
|
||||
$journal->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
53
app/TransactionRules/Actions/ClearNotes.php
Normal file
53
app/TransactionRules/Actions/ClearNotes.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* ClearNotes.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\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ClearNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
*/
|
||||
class ClearNotes implements ActionInterface
|
||||
{
|
||||
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
Log::debug(sprintf('RuleAction ClearNotes removed all notes.'));
|
||||
$journal->deleteMeta('notes');
|
||||
$journal->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
55
app/TransactionRules/Actions/PrependNotes.php
Normal file
55
app/TransactionRules/Actions/PrependNotes.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* PrependNotes.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\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class PrependNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
*/
|
||||
class PrependNotes implements ActionInterface
|
||||
{
|
||||
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes');
|
||||
Log::debug(sprintf('RuleAction PrependNotes prepended "%s" with "%s".', $notes, $this->action->action_value));
|
||||
$notes = $this->action->action_value . $notes;
|
||||
$journal->setMeta('notes', $notes);
|
||||
$journal->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
56
app/TransactionRules/Actions/SetNotes.php
Normal file
56
app/TransactionRules/Actions/SetNotes.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* SetNotes.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\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
*/
|
||||
class SetNotes implements ActionInterface
|
||||
{
|
||||
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$oldNotes = $journal->getMeta('notes');
|
||||
|
||||
$journal->setMeta('notes', $this->action->action_value);
|
||||
$journal->save();
|
||||
|
||||
Log::debug(sprintf('RuleAction SetNotes changed the notes of journal #%d from "%s" to "%s".', $journal->id, $oldNotes, $this->action->action_value));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
67
app/TransactionRules/Triggers/NotesAny.php
Normal file
67
app/TransactionRules/Triggers/NotesAny.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesAny.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\TransactionRules\Triggers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesAny
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesAny 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes') ?? '';
|
||||
|
||||
if (strlen($notes) > 0) {
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen > 0, return true.', $journal->id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return false.', $journal->id));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
74
app/TransactionRules/Triggers/NotesAre.php
Normal file
74
app/TransactionRules/Triggers/NotesAre.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesAre.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\TransactionRules\Triggers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesAre
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesAre 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)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = strtolower($journal->getMeta('notes') ?? '');
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
if ($notes === $search) {
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is "%s", return true.', $journal->id, $notes, $search));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesAre for journal #%d: "%s" is NOT "%s", return false.', $journal->id, $notes, $search));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
82
app/TransactionRules/Triggers/NotesContain.php
Normal file
82
app/TransactionRules/Triggers/NotesContain.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesContain.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\TransactionRules\Triggers;
|
||||
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesContain
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesContain 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)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
$res = strval($value) === '';
|
||||
if ($res === true) {
|
||||
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$search = strtolower($this->triggerValue);
|
||||
$notes = strtolower($journal->getMeta('notes') ?? '');
|
||||
|
||||
$strpos = strpos($notes, $search);
|
||||
if (!($strpos === false)) {
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" contains "%s", return true.', $journal->id, $notes, $search));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesContain for journal #%d: "%s" does NOT contain "%s", return false.', $journal->id, $notes, $search));
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
67
app/TransactionRules/Triggers/NotesEmpty.php
Normal file
67
app/TransactionRules/Triggers/NotesEmpty.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesEmpty.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\TransactionRules\Triggers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesEmpty
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesEmpty 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = $journal->getMeta('notes') ?? '';
|
||||
|
||||
if (strlen($notes) === 0) {
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen is 0, return true.', $journal->id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEmpty for journal #%d: strlen > 0, return false.', $journal->id));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
90
app/TransactionRules/Triggers/NotesEnd.php
Normal file
90
app/TransactionRules/Triggers/NotesEnd.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesEnd.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\TransactionRules\Triggers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesEnd
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesEnd 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)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
$res = strval($value) === '';
|
||||
if ($res === true) {
|
||||
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = strtolower($journal->getMeta('notes') ?? '');
|
||||
$notesLength = strlen($notes);
|
||||
$search = strtolower($this->triggerValue);
|
||||
$searchLength = strlen($search);
|
||||
|
||||
// if the string to search for is longer than the description,
|
||||
// shorten the search string.
|
||||
if ($searchLength > $notesLength) {
|
||||
$search = substr($search, ($notesLength * -1));
|
||||
$searchLength = strlen($search);
|
||||
}
|
||||
|
||||
$part = substr($notes, $searchLength * -1);
|
||||
|
||||
if ($part === $search) {
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" ends with "%s", return true.', $journal->id, $notes, $search));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesEnd for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $notes, $search));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
82
app/TransactionRules/Triggers/NotesStart.php
Normal file
82
app/TransactionRules/Triggers/NotesStart.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* NotesStart.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\TransactionRules\Triggers;
|
||||
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NotesStart
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Triggers
|
||||
*/
|
||||
final class NotesStart 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)
|
||||
{
|
||||
if (!is_null($value)) {
|
||||
$res = strval($value) === '';
|
||||
if ($res === true) {
|
||||
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function triggered(TransactionJournal $journal): bool
|
||||
{
|
||||
$notes = strtolower($journal->getMeta('notes') ?? '');
|
||||
$search = strtolower($this->triggerValue);
|
||||
|
||||
$part = substr($notes, 0, strlen($search));
|
||||
|
||||
if ($part === $search) {
|
||||
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" starts with "%s", return true.', $journal->id, $notes, $search));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('RuleTrigger NotesStart for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $notes, $search));
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
@ -200,6 +200,12 @@ return [
|
||||
'has_any_budget' => 'FireflyIII\TransactionRules\Triggers\HasAnyBudget',
|
||||
'has_no_tag' => 'FireflyIII\TransactionRules\Triggers\HasNoTag',
|
||||
'has_any_tag' => 'FireflyIII\TransactionRules\Triggers\HasAnyTag',
|
||||
'notes_contain' => 'FireflyIII\TransactionRules\Triggers\NotesContain',
|
||||
'notes_start' => 'FireflyIII\TransactionRules\Triggers\NotesStart',
|
||||
'notes_end' => 'FireflyIII\TransactionRules\Triggers\NotesEnd',
|
||||
'notes_are' => 'FireflyIII\TransactionRules\Triggers\NotesAre',
|
||||
'no_notes' => 'FireflyIII\TransactionRules\Triggers\NotesEmpty',
|
||||
'any_notes' => 'FireflyIII\TransactionRules\Triggers\NotesAny',
|
||||
],
|
||||
'rule-actions' => [
|
||||
'set_category' => 'FireflyIII\TransactionRules\Actions\SetCategory',
|
||||
@ -212,9 +218,12 @@ return [
|
||||
'set_description' => 'FireflyIII\TransactionRules\Actions\SetDescription',
|
||||
'append_description' => 'FireflyIII\TransactionRules\Actions\AppendDescription',
|
||||
'prepend_description' => 'FireflyIII\TransactionRules\Actions\PrependDescription',
|
||||
|
||||
'set_source_account' => 'FireflyIII\TransactionRules\Actions\SetSourceAccount',
|
||||
'set_destination_account' => 'FireflyIII\TransactionRules\Actions\SetDestinationAccount',
|
||||
'set_notes' => 'FireflyIII\TransactionRules\Actions\SetNotes',
|
||||
'append_notes' => 'FireflyIII\TransactionRules\Actions\AppendNotes',
|
||||
'prepend_notes' => 'FireflyIII\TransactionRules\Actions\PrependNotes',
|
||||
'clear_notes' => 'FireflyIII\TransactionRules\Actions\ClearNotes',
|
||||
],
|
||||
'rule-actions-text' => [
|
||||
'set_category',
|
||||
|
3
public/js/ff/rules/create-edit.js
vendored
3
public/js/ff/rules/create-edit.js
vendored
@ -194,6 +194,7 @@ function updateActionInput(selectList) {
|
||||
break;
|
||||
case 'clear_category':
|
||||
case 'clear_budget':
|
||||
case 'clear_notes':
|
||||
case 'remove_all_tags':
|
||||
input.attr('disabled', 'disabled');
|
||||
break;
|
||||
@ -265,6 +266,8 @@ function updateTriggerInput(selectList) {
|
||||
case 'has_no_budget':
|
||||
case 'has_any_budget':
|
||||
case 'has_no_tag':
|
||||
case 'no_notes':
|
||||
case 'any_notes':
|
||||
case 'has_any_tag':
|
||||
input.prop('disabled', true);
|
||||
input.typeahead('destroy');
|
||||
|
@ -292,6 +292,18 @@ return [
|
||||
'rule_trigger_has_no_tag' => 'Transaction has no tag(s)',
|
||||
'rule_trigger_has_any_tag_choice' => 'Has one or more (any) tags',
|
||||
'rule_trigger_has_any_tag' => 'Transaction has one or more (any) tags',
|
||||
'rule_trigger_any_notes_choice' => 'Has (any) notes',
|
||||
'rule_trigger_any_notes' => 'Transaction has (any) notes',
|
||||
'rule_trigger_no_notes_choice' => 'Has no notes',
|
||||
'rule_trigger_no_notes' => 'Transaction has no notes',
|
||||
'rule_trigger_notes_are_choice' => 'Notes are..',
|
||||
'rule_trigger_notes_are' => 'Notes are ":trigger_value"',
|
||||
'rule_trigger_notes_contain_choice' => 'Notes contain..',
|
||||
'rule_trigger_notes_contain' => 'Notes contain ":trigger_value"',
|
||||
'rule_trigger_notes_start_choice' => 'Notes start with..',
|
||||
'rule_trigger_notes_start' => 'Notes start with ":trigger_value"',
|
||||
'rule_trigger_notes_end_choice' => 'Notes end with..',
|
||||
'rule_trigger_notes_end' => 'Notes end with ":trigger_value"',
|
||||
'rule_action_set_category' => 'Set category to ":action_value"',
|
||||
'rule_action_clear_category' => 'Clear category',
|
||||
'rule_action_set_budget' => 'Set budget to ":action_value"',
|
||||
@ -316,6 +328,16 @@ return [
|
||||
'rule_action_set_source_account' => 'Set source account to :action_value',
|
||||
'rule_action_set_destination_account_choice' => 'Set destination account to...',
|
||||
'rule_action_set_destination_account' => 'Set destination account to :action_value',
|
||||
'rule_action_append_notes_choice' => 'Append notes with..',
|
||||
'rule_action_append_notes' => 'Append notes with ":action_value"',
|
||||
'rule_action_prepend_notes_choice' => 'Prepend notes with..',
|
||||
'rule_action_prepend_notes' => 'Prepend notes with ":action_value"',
|
||||
'rule_action_clear_notes_choice' => 'Remove any notes',
|
||||
'rule_action_clear_notes' => 'Remove any notes',
|
||||
'rule_action_set_notes_choice' => 'Set notes to..',
|
||||
'rule_action_set_notes' => 'Set notes to ":action_value"',
|
||||
|
||||
|
||||
'rules_have_read_warning' => 'Have you read the warning?',
|
||||
'apply_rule_warning' => 'Warning: running a rule(group) on a large selection of transactions could take ages, and it could time-out. If it does, the rule(group) will only be applied to an unknown subset of your transactions. This might leave your financial administration in tatters. Please be careful.',
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user