Skip to content

Firefly III: a personal finances manager

All actions and triggers.

James Cole668633e7642a
diff --git a/app/Rules/Actions/AddTag.php b/app/Rules/Actions/AddTag.php
new file mode 100644
index 0000000000..147d79a2df
--- /dev/null
+++ b/app/Rules/Actions/AddTag.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * AddTag.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\Actions;
+
+
+use Auth;
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\Tag;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class AddTag
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class AddTag implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ // journal has this tag maybe?
+ $tag = Tag::firstOrCreateEncrypted(['tag' => $this->action->action_value, 'user_id' => Auth::user()->id]);
+
+ $count = $this->journal->tags()->where('id', $tag->id)->count();
+ if ($count == 0) {
+ $this->journal->tags()->save($tag);
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/AppendDescription.php b/app/Rules/Actions/AppendDescription.php
new file mode 100644
index 0000000000..42254dc86b
--- /dev/null
+++ b/app/Rules/Actions/AppendDescription.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * AppendDescription.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\Actions;
+
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class AppendDescription
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class AppendDescription implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->description = $this->journal->description . $this->action->action_value;
+ $this->journal->save();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/ClearBudget.php b/app/Rules/Actions/ClearBudget.php
new file mode 100644
index 0000000000..f74b633537
--- /dev/null
+++ b/app/Rules/Actions/ClearBudget.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * ClearBudget.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\Actions;
+
+
+use Auth;
+use FireflyIII\Models\Category;
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+use Log;
+
+/**
+ * Class ClearBudget
+ *
+ * @package FireflyIII\Rules\Action
+ */
+class ClearBudget implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->budgets()->detach();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/ClearCategory.php b/app/Rules/Actions/ClearCategory.php
new file mode 100644
index 0000000000..107f2241e0
--- /dev/null
+++ b/app/Rules/Actions/ClearCategory.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * ClearCategory.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\Actions;
+
+
+use Auth;
+use FireflyIII\Models\Category;
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+use Log;
+
+/**
+ * Class ClearCategory
+ *
+ * @package FireflyIII\Rules\Action
+ */
+class ClearCategory implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->categories()->detach();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/PrependDescription.php b/app/Rules/Actions/PrependDescription.php
new file mode 100644
index 0000000000..d452125002
--- /dev/null
+++ b/app/Rules/Actions/PrependDescription.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * PrependDescription.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\Actions;
+
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class AppendDescription
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class PrependDescription implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->description = $this->action->action_value . $this->journal->description;
+ $this->journal->save();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/RemoveAllTags.php b/app/Rules/Actions/RemoveAllTags.php
new file mode 100644
index 0000000000..868acee3cd
--- /dev/null
+++ b/app/Rules/Actions/RemoveAllTags.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * RemoveAllTags.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\Actions;
+
+
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class RemoveAllTags
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class RemoveAllTags implements ActionInterface
+{
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->tags()->detach();
+
+ return true;
+
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/RemoveTag.php b/app/Rules/Actions/RemoveTag.php
new file mode 100644
index 0000000000..e6c427d0bb
--- /dev/null
+++ b/app/Rules/Actions/RemoveTag.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * RemoveTag.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\Actions;
+
+
+use Auth;
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\Tag;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class RemoveTag
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class RemoveTag implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ // if tag does not exist, no need to continue:
+ $name = $this->action->action_value;
+ /** @var Tag $tag */
+ $tag = Auth::user()->tags()->get()->filter(
+ function (Tag $tag) use ($name) {
+ return $tag->tag == $name;
+ }
+ )->first();
+
+ if (!is_null($tag)) {
+ $this->journal->tags()->detach([$tag->id]);
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/app/Rules/Actions/SetDescription.php b/app/Rules/Actions/SetDescription.php
new file mode 100644
index 0000000000..1b3ee0422f
--- /dev/null
+++ b/app/Rules/Actions/SetDescription.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * SetDescription.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\Actions;
+
+use FireflyIII\Models\RuleAction;
+use FireflyIII\Models\TransactionJournal;
+
+/**
+ * Class SetDescription
+ *
+ * @package FireflyIII\Rules\Actions
+ */
+class SetDescription implements ActionInterface
+{
+
+ private $action;
+ private $journal;
+
+ /**
+ * TriggerInterface constructor.
+ *
+ * @param RuleAction $action
+ * @param TransactionJournal $journal
+ */
+ public function __construct(RuleAction $action, TransactionJournal $journal)
+ {
+ $this->action = $action;
+ $this->journal = $journal;
+ }
+
+ /**
+ * @return bool
+ */
+ public function act()
+ {
+ $this->journal->description = $this->action->action_value;
+ $this->journal->save();
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/config/firefly.php b/config/firefly.php
index 4acb99dfd8..8a01676e8a 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -183,21 +183,21 @@ return [
'amount_exactly' => 'FireflyIII\Rules\Triggers\AmountExactly',
'amount_more' => 'FireflyIII\Rules\Triggers\AmountMore',
'description_starts' => 'FireflyIII\Rules\Triggers\DescriptionStarts',
- 'description_ends' => 'FireflyIII\Rules\Triggers',
+ 'description_ends' => 'FireflyIII\Rules\Triggers\DescriptionEnds',
'description_contains' => 'FireflyIII\Rules\Triggers\DescriptionContains',
- 'description_is' => 'FireflyIII\Rules\Triggers',
+ 'description_is' => 'FireflyIII\Rules\Triggers\DescriptionIs',
],
'rule-actions' => [
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',
- 'clear_category' => 'FireflyIII\Rules\Actions',
+ 'clear_category' => 'FireflyIII\Rules\Actions\ClearCategory',
'set_budget' => 'FireflyIII\Rules\Actions\SetBudget',
- 'clear_budget' => 'FireflyIII\Rules\Actions',
- 'add_tag' => 'FireflyIII\Rules\Actions',
- 'remove_tag' => 'FireflyIII\Rules\Actions',
- 'remove_all_tags' => 'FireflyIII\Rules\Actions',
- 'set_description' => 'FireflyIII\Rules\Actions',
- 'append_description' => 'FireflyIII\Rules\Actions',
- 'prepend_description' => 'FireflyIII\Rules\Actions',
+ 'clear_budget' => 'FireflyIII\Rules\Actions\ClearBudget',
+ 'add_tag' => 'FireflyIII\Rules\Actions\AddTag',
+ 'remove_tag' => 'FireflyIII\Rules\Actions\RemoveTag',
+ 'remove_all_tags' => 'FireflyIII\Rules\Actions\RemoveAllTags',
+ 'set_description' => 'FireflyIII\Rules\Actions\SetDescription',
+ 'append_description' => 'FireflyIII\Rules\Actions\AppendDescription',
+ 'prepend_description' => 'FireflyIII\Rules\Actions\PrependDescription',
],
];