Skip to content

Firefly III: a personal finances manager

More working triggers.

James Coleafec8480fbde
diff --git a/app/Rules/Triggers/ToAccountContains.php b/app/Rules/Triggers/ToAccountContains.php
new file mode 100644
index 0000000000..5e06383f04
--- /dev/null
+++ b/app/Rules/Triggers/ToAccountContains.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * ToAccountContains.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 ToAccountContains
+ *
+ * @package FireflyIII\Rules\Triggers
+ */
+class ToAccountContains 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()
+ {
+ $toAccountName = strtolower($this->journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+ $strpos = strpos($toAccountName, $search);
+
+ if (!($strpos === false)) {
+ // found something
+ Log::debug('"' . $toAccountName . '" contains the text "' . $search . '". Return true.');
+
+ return true;
+ }
+
+ // found nothing.
+ Log::debug('"' . $toAccountName . '" does not contain the text "' . $search . '". Return false.');
+
+ return false;
+
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Triggers/ToAccountEnds.php b/app/Rules/Triggers/ToAccountEnds.php
new file mode 100644
index 0000000000..67bb9750f1
--- /dev/null
+++ b/app/Rules/Triggers/ToAccountEnds.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * ToAccountEnds.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 ToAccountEnds
+ *
+ * @package FireflyIII\Rules\Triggers
+ */
+class Ends 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()
+ {
+ $toAccountName = strtolower($this->journal->destination_account->name);
+ $toAccountNameLength = strlen($toAccountName);
+ $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 > $toAccountNameLength) {
+ Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $toAccountName . '" (' . $toAccountNameLength . '). ');
+ $search = substr($search, ($toAccountNameLength * -1));
+ $searchLength = strlen($search);
+ Log::debug('Search string is now "' . $search . '" (' . $searchLength . ') instead.');
+ }
+
+
+ $part = substr($toAccountName, $searchLength * -1);
+
+ if ($part == $search) {
+ Log::debug('"' . $toAccountName . '" ends with "' . $search . '". Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $toAccountName . '" does not end with "' . $search . '". Return false.');
+
+ return false;
+
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Triggers/ToAccountIs.php b/app/Rules/Triggers/ToAccountIs.php
new file mode 100644
index 0000000000..09f4c66f6a
--- /dev/null
+++ b/app/Rules/Triggers/ToAccountIs.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * ToAccountIs.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 ToAccountIs
+ *
+ * @package FireflyIII\Rules\Triggers
+ */
+class ToAccountIs 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()
+ {
+ $toAccountName = strtolower($this->journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+
+ if ($toAccountName == $search) {
+ Log::debug('"' . $toAccountName . '" equals "' . $search . '" exactly. Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $toAccountName . '" does not equal "' . $search . '". Return false.');
+
+ return false;
+
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Triggers/ToAccountStarts.php b/app/Rules/Triggers/ToAccountStarts.php
new file mode 100644
index 0000000000..0af5fc4491
--- /dev/null
+++ b/app/Rules/Triggers/ToAccountStarts.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * ToAccountStarts.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 ToAccountStarts
+ *
+ * @package FireflyIII\Rules\Triggers
+ */
+class ToAccountStarts 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()
+ {
+ $toAccountName = strtolower($this->journal->destination_account->name);
+ $search = strtolower($this->trigger->trigger_value);
+
+ $part = substr($toAccountName, 0, strlen($search));
+
+ if ($part == $search) {
+ Log::debug('"' . $toAccountName . '" starts with "' . $search . '". Return true.');
+
+ return true;
+ }
+ Log::debug('"' . $toAccountName . '" does not start with "' . $search . '". Return false.');
+
+ return false;
+
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Triggers/TransactionType.php b/app/Rules/Triggers/TransactionType.php
new file mode 100644
index 0000000000..9bba776f42
--- /dev/null
+++ b/app/Rules/Triggers/TransactionType.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * TransactionType.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 TransactionType
+ *
+ * @package FireflyIII\Rules\Triggers
+ */
+class TransactionType 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()
+ {
+ $type = strtolower($this->journal->transactionType->type);
+ $search = strtolower($this->trigger->trigger_value);
+
+ if ($type == $search) {
+ Log::debug('Journal is of type "' . $type . '" which matches with "' . $search . '". Return true');
+
+ return true;
+ }
+ Log::debug('Journal is of type "' . $type . '" which does not match with "' . $search . '". Return false');
+
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Triggers/UserAction.php b/app/Rules/Triggers/UserAction.php
index 48c9932a33..bdde712e36 100644
--- a/app/Rules/Triggers/UserAction.php
+++ b/app/Rules/Triggers/UserAction.php
@@ -48,6 +48,7 @@ class UserAction implements TriggerInterface
public function triggered()
{
Log::debug('user_action always returns true.');
+
return true;
}
diff --git a/config/firefly.php b/config/firefly.php
index ef85e627f6..eb78cf5102 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -174,11 +174,11 @@ return [
'from_account_ends' => 'FireflyIII\Rules\Triggers\FromAccountEnds',
'from_account_is' => 'FireflyIII\Rules\Triggers\FromAccountIs',
'from_account_contains' => 'FireflyIII\Rules\Triggers\FromAccountContains',
- 'to_account_starts' => 'FireflyIII\Rules\Triggers',
- 'to_account_ends' => 'FireflyIII\Rules\Triggers',
- 'to_account_is' => 'FireflyIII\Rules\Triggers',
- 'to_account_contains' => 'FireflyIII\Rules\Triggers',
- 'transaction_type' => 'FireflyIII\Rules\Triggers',
+ 'to_account_starts' => 'FireflyIII\Rules\Triggers\ToAccountStarts',
+ 'to_account_ends' => 'FireflyIII\Rules\Triggers\ToAccountEnds',
+ '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',