Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
More valid triggers.
James Cole1270e5d15ca3
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.phpnew file mode 100644index 0000000000..908ad31a6f--- /dev/null+++ b/app/Rules/Triggers/AmountExactly.php@@ -0,0 +1,64 @@+<?php+/**+ * AmountExactly.php+ * Copyright (C) 2016 Sander Dorigo+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++namespace FireflyIII\Rules\Triggers;+++use FireflyIII\Models\RuleTrigger;+use FireflyIII\Models\TransactionJournal;+use Log;++/**+ * Class AmountExactly+ *+ * @package FireflyIII\Rules\Triggers+ */+class AmountExactly implements TriggerInterface+{+ /** @var RuleTrigger */+ protected $trigger;++ /** @var TransactionJournal */+ protected $journal;+++ /**+ * TriggerInterface constructor.+ *+ * @param RuleTrigger $trigger+ * @param TransactionJournal $journal+ */+ public function __construct(RuleTrigger $trigger, TransactionJournal $journal)+ {+ $this->trigger = $trigger;+ $this->journal = $journal;+ }++ /**+ * @return bool+ */+ public function triggered()+ {+ $amount = $this->journal->amount_positive;+ $compare = $this->trigger->trigger_value;+ $result = bccomp($amount, $compare, 4);+ if ($result === 0) {+ // found something+ Log::debug($amount . ' is exactly ' . $compare . '. Return true.');++ return true;+ }++ // found nothing.+ Log::debug($amount . ' is not exactly ' . $compare . '. Return false.');++ return false;++ }+}\ No newline at end of filediff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.phpnew file mode 100644index 0000000000..4c659db944--- /dev/null+++ b/app/Rules/Triggers/AmountLess.php@@ -0,0 +1,64 @@+<?php+/**+ * AmountLess.php+ * Copyright (C) 2016 Sander Dorigo+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++namespace FireflyIII\Rules\Triggers;+++use FireflyIII\Models\RuleTrigger;+use FireflyIII\Models\TransactionJournal;+use Log;++/**+ * Class AmountLess+ *+ * @package FireflyIII\Rules\Triggers+ */+class AmountLess implements TriggerInterface+{+ /** @var RuleTrigger */+ protected $trigger;++ /** @var TransactionJournal */+ protected $journal;+++ /**+ * TriggerInterface constructor.+ *+ * @param RuleTrigger $trigger+ * @param TransactionJournal $journal+ */+ public function __construct(RuleTrigger $trigger, TransactionJournal $journal)+ {+ $this->trigger = $trigger;+ $this->journal = $journal;+ }++ /**+ * @return bool+ */+ public function triggered()+ {+ $amount = $this->journal->amount_positive;+ $compare = $this->trigger->trigger_value;+ $result = bccomp($amount, $compare, 4);+ if ($result === -1) {+ // found something+ Log::debug($amount . ' is less than ' . $compare . '. Return true.');++ return true;+ }++ // found nothing.+ Log::debug($amount . ' is not less than ' . $compare . '. Return false.');++ return false;++ }+}\ No newline at end of filediff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.phpnew file mode 100644index 0000000000..a3470ffd13--- /dev/null+++ b/app/Rules/Triggers/AmountMore.php@@ -0,0 +1,64 @@+<?php+/**+ * AmountMore.php+ * Copyright (C) 2016 Sander Dorigo+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++namespace FireflyIII\Rules\Triggers;+++use FireflyIII\Models\RuleTrigger;+use FireflyIII\Models\TransactionJournal;+use Log;++/**+ * Class AmountMore+ *+ * @package FireflyIII\Rules\Triggers+ */+class AmountMore implements TriggerInterface+{+ /** @var RuleTrigger */+ protected $trigger;++ /** @var TransactionJournal */+ protected $journal;+++ /**+ * TriggerInterface constructor.+ *+ * @param RuleTrigger $trigger+ * @param TransactionJournal $journal+ */+ public function __construct(RuleTrigger $trigger, TransactionJournal $journal)+ {+ $this->trigger = $trigger;+ $this->journal = $journal;+ }++ /**+ * @return bool+ */+ public function triggered()+ {+ $amount = $this->journal->amount_positive;+ $compare = $this->trigger->trigger_value;+ $result = bccomp($amount, $compare, 4);+ if ($result === 1) {+ // found something+ Log::debug($amount . ' is more than ' . $compare . '. Return true.');++ return true;+ }++ // found nothing.+ Log::debug($amount . ' is not more than ' . $compare . '. Return false.');++ return false;++ }+}\ No newline at end of filediff --git a/app/Rules/Triggers/DescriptionEnds.php b/app/Rules/Triggers/DescriptionEnds.phpnew file mode 100644index 0000000000..4d7c0a10a4--- /dev/null+++ b/app/Rules/Triggers/DescriptionEnds.php@@ -0,0 +1,74 @@+<?php+/**+ * DescriptionEnds.php+ * Copyright (C) 2016 Sander Dorigo+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++namespace FireflyIII\Rules\Triggers;++use FireflyIII\Models\RuleTrigger;+use FireflyIII\Models\TransactionJournal;+use Log;++/**+ * Class DescriptionEnds+ *+ * @package FireflyIII\Rules\Triggers+ */+class DescriptionEnds implements TriggerInterface+{+ /** @var RuleTrigger */+ protected $trigger;++ /** @var TransactionJournal */+ protected $journal;+++ /**+ * TriggerInterface constructor.+ *+ * @param RuleTrigger $trigger+ * @param TransactionJournal $journal+ */+ public function __construct(RuleTrigger $trigger, TransactionJournal $journal)+ {+ $this->trigger = $trigger;+ $this->journal = $journal;+ }++ /**+ * @return bool+ */+ public function triggered()+ {+ $description = strtolower($this->journal->description);+ $descriptionLength = strlen($description);+ $search = strtolower($this->trigger->trigger_value);+ $searchLength = strlen($search);++ // if the string to search for is longer than the account name,+ // shorten the search string.+ if ($searchLength > $descriptionLength) {+ Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $description . '" (' . $descriptionLength . '). ');+ $search = substr($search, ($descriptionLength * -1));+ $searchLength = strlen($search);+ Log::debug('Search string is now "' . $search . '" (' . $searchLength . ') instead.');+ }+++ $part = substr($description, $searchLength * -1);++ if ($part == $search) {+ Log::debug('"' . $description . '" ends with "' . $search . '". Return true.');++ return true;+ }+ Log::debug('"' . $description . '" does not end with "' . $search . '". Return false.');++ return false;++ }+}\ No newline at end of filediff --git a/app/Rules/Triggers/DescriptionStarts.php b/app/Rules/Triggers/DescriptionStarts.phpnew file mode 100644index 0000000000..8475f99fda--- /dev/null+++ b/app/Rules/Triggers/DescriptionStarts.php@@ -0,0 +1,62 @@+<?php+/**+ * DescriptionStarts.php+ * Copyright (C) 2016 Sander Dorigo+ *+ * This software may be modified and distributed under the terms+ * of the MIT license. See the LICENSE file for details.+ */++namespace FireflyIII\Rules\Triggers;++use FireflyIII\Models\RuleTrigger;+use FireflyIII\Models\TransactionJournal;+use Log;++/**+ * Class DescriptionStarts+ *+ * @package FireflyIII\Rules\Triggers+ */+class DescriptionStarts implements TriggerInterface+{+ /** @var RuleTrigger */+ protected $trigger;++ /** @var TransactionJournal */+ protected $journal;+++ /**+ * TriggerInterface constructor.+ *+ * @param RuleTrigger $trigger+ * @param TransactionJournal $journal+ */+ public function __construct(RuleTrigger $trigger, TransactionJournal $journal)+ {+ $this->trigger = $trigger;+ $this->journal = $journal;+ }++ /**+ * @return bool+ */+ public function triggered()+ {+ $description = strtolower($this->journal->description);+ $search = strtolower($this->trigger->trigger_value);++ $part = substr($description, 0, strlen($search));++ if ($part == $search) {+ Log::debug('"' . $description . '" starts with "' . $search . '". Return true.');++ return true;+ }+ Log::debug('"' . $description . '" does not start with "' . $search . '". Return false.');++ return false;++ }+}\ No newline at end of filediff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.phpindex 67bb9750f1..7c1984ea2a 100644--- a/app/Rules/Triggers/ToAccountEnds.php+++ b/app/Rules/Triggers/ToAccountEnds.php@@ -18,7 +18,7 @@ use Log;** @package FireflyIII\Rules\Triggers*/-class Ends implements TriggerInterface+class ToAccountEnds implements TriggerInterface{/** @var RuleTrigger */protected $trigger;diff --git a/config/firefly.php b/config/firefly.phpindex eb78cf5102..4acb99dfd8 100644--- a/config/firefly.php+++ b/config/firefly.php@@ -179,11 +179,10 @@ return ['to_account_is' => 'FireflyIII\Rules\Triggers\ToAccountIs','to_account_contains' => 'FireflyIII\Rules\Triggers\ToAccountContains','transaction_type' => 'FireflyIII\Rules\Triggers\TransactionType',- 'amount_less' => 'FireflyIII\Rules\Triggers',- 'amount_exactly' => 'FireflyIII\Rules\Triggers',- 'amount_exactly_not' => 'FireflyIII\Rules\Triggers',- 'amount_more' => 'FireflyIII\Rules\Triggers',- 'description_starts' => 'FireflyIII\Rules\Triggers',+ 'amount_less' => 'FireflyIII\Rules\Triggers\AmountLess',+ 'amount_exactly' => 'FireflyIII\Rules\Triggers\AmountExactly',+ 'amount_more' => 'FireflyIII\Rules\Triggers\AmountMore',+ 'description_starts' => 'FireflyIII\Rules\Triggers\DescriptionStarts','description_ends' => 'FireflyIII\Rules\Triggers','description_contains' => 'FireflyIII\Rules\Triggers\DescriptionContains','description_is' => 'FireflyIII\Rules\Triggers',