mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
All actions and triggers.
This commit is contained in:
parent
3dbb1f034d
commit
668633e764
56
app/Rules/Actions/AddTag.php
Normal file
56
app/Rules/Actions/AddTag.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
48
app/Rules/Actions/AppendDescription.php
Normal file
48
app/Rules/Actions/AppendDescription.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
51
app/Rules/Actions/ClearBudget.php
Normal file
51
app/Rules/Actions/ClearBudget.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
51
app/Rules/Actions/ClearCategory.php
Normal file
51
app/Rules/Actions/ClearCategory.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
48
app/Rules/Actions/PrependDescription.php
Normal file
48
app/Rules/Actions/PrependDescription.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
48
app/Rules/Actions/RemoveAllTags.php
Normal file
48
app/Rules/Actions/RemoveAllTags.php
Normal file
@ -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;
|
||||
|
||||
}
|
||||
}
|
61
app/Rules/Actions/RemoveTag.php
Normal file
61
app/Rules/Actions/RemoveTag.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
48
app/Rules/Actions/SetDescription.php
Normal file
48
app/Rules/Actions/SetDescription.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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',
|
||||
],
|
||||
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user