mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Refactor old methods.
This commit is contained in:
@@ -22,20 +22,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
|
||||
/**
|
||||
* Interface ActionInterface.
|
||||
*/
|
||||
interface ActionInterface
|
||||
{
|
||||
/**
|
||||
* ActionInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action);
|
||||
|
||||
/**
|
||||
* Execute the action on an array. Returns "true" if the action was a success and the action
|
||||
* was applied. Returns false if otherwise.
|
||||
|
@@ -31,15 +31,6 @@ use Log;
|
||||
*/
|
||||
class ClearBudget implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -31,15 +31,6 @@ use Log;
|
||||
*/
|
||||
class ClearCategory implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -32,15 +32,6 @@ use Log;
|
||||
*/
|
||||
class ClearNotes implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -149,7 +149,6 @@ class ConvertToDeposit implements ActionInterface
|
||||
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE);
|
||||
|
||||
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['source_account_name']));
|
||||
unset($source);
|
||||
|
||||
// update source transaction(s) to be revenue account
|
||||
DB::table('transactions')
|
||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
|
||||
@@ -34,15 +33,6 @@ use Log;
|
||||
*/
|
||||
class DeleteTransaction implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -31,15 +30,6 @@ use Log;
|
||||
*/
|
||||
class RemoveAllTags implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
* @param RuleAction $action
|
||||
*/
|
||||
public function __construct(RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -50,4 +40,5 @@ class RemoveAllTags implements ActionInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -56,12 +56,9 @@ class SetDestinationAccount implements ActionInterface
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
/** @var AccountRepositoryInterface repository */
|
||||
/** @var Transaction $source */
|
||||
|
||||
$user = User::find($journal['user_id']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
/** @var TransactionJournal|null $object */
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
@@ -86,6 +83,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
}
|
||||
|
||||
// new destination account must be different from the current source account:
|
||||
/** @var Transaction|null $source */
|
||||
$source = $object->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $source) {
|
||||
Log::error('Could not find source transaction.');
|
||||
@@ -113,11 +111,6 @@ class SetDestinationAccount implements ActionInterface
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$newAccount = $this->findExpenseAccount();
|
||||
}
|
||||
if (null === $newAccount) {
|
||||
Log::error('New expense account is NULL');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
|
||||
@@ -150,9 +143,9 @@ class SetDestinationAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account|null
|
||||
* @return Account
|
||||
*/
|
||||
private function findExpenseAccount(): ?Account
|
||||
private function findExpenseAccount(): Account
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
|
||||
if (null === $account) {
|
||||
|
@@ -55,12 +55,9 @@ class SetSourceAccount implements ActionInterface
|
||||
*/
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
/** @var TransactionJournal $object */
|
||||
/** @var AccountRepositoryInterface repository */
|
||||
/** @var Transaction $destination */
|
||||
|
||||
$user = User::find($journal['user_id']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
/** @var TransactionJournal|null $object */
|
||||
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
@@ -83,6 +80,7 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
// new source account must be different from the current destination account:
|
||||
/** @var Transaction|null $destination */
|
||||
$destination = $object->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination) {
|
||||
Log::error('Could not find destination transaction.');
|
||||
@@ -110,11 +108,6 @@ class SetSourceAccount implements ActionInterface
|
||||
if (TransactionType::DEPOSIT === $type) {
|
||||
$newAccount = $this->findRevenueAccount();
|
||||
}
|
||||
if (null === $newAccount) {
|
||||
Log::error('New account is NULL');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
|
||||
@@ -145,9 +138,9 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account|null
|
||||
* @return Account
|
||||
*/
|
||||
private function findRevenueAccount(): ?Account
|
||||
private function findRevenueAccount(): Account
|
||||
{
|
||||
$allowed = config('firefly.expected_source_types.source.Deposit');
|
||||
$account = $this->repository->findByName($this->action->action_value, $allowed);
|
||||
|
Reference in New Issue
Block a user