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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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', ], ];