Replace enum

This commit is contained in:
James Cole
2025-01-03 09:05:56 +01:00
parent 44eafeeae5
commit d009ce31ca
36 changed files with 85 additions and 77 deletions

View File

@@ -99,7 +99,7 @@ class ConvertToDeposit implements ActionInterface
return $res;
}
if (TransactionType::TRANSFER === $type) {
if (TransactionTypeEnum::TRANSFER->value === $type) {
app('log')->debug('Going to transform a transfer to a deposit.');
try {
@@ -111,7 +111,7 @@ class ConvertToDeposit implements ActionInterface
return false;
}
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::TRANSFER, TransactionType::DEPOSIT));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::TRANSFER->value, TransactionType::DEPOSIT));
return $res;
}

View File

@@ -79,7 +79,7 @@ class ConvertToTransfer implements ActionInterface
$type = $object->transactionType->type;
$user = $object->user;
$journalId = $object->id;
if (TransactionType::TRANSFER === $type) {
if (TransactionTypeEnum::TRANSFER->value === $type) {
app('log')->error(
sprintf('Journal #%d is already a transfer so cannot be converted (rule #%d).', $object->id, $this->action->rule_id)
);
@@ -136,7 +136,7 @@ class ConvertToTransfer implements ActionInterface
return false;
}
if (false !== $res) {
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::WITHDRAWAL->value, TransactionType::TRANSFER));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value));
}
return $res;
@@ -154,7 +154,7 @@ class ConvertToTransfer implements ActionInterface
return false;
}
if (false !== $res) {
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionType::TRANSFER));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value));
}
return $res;
@@ -216,7 +216,7 @@ class ConvertToTransfer implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
$newType = TransactionType::whereType(TransactionTypeEnum::TRANSFER->value)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)
@@ -271,7 +271,7 @@ class ConvertToTransfer implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
$newType = TransactionType::whereType(TransactionTypeEnum::TRANSFER->value)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)

View File

@@ -80,7 +80,7 @@ class ConvertToWithdrawal implements ActionInterface
return false;
}
if (TransactionType::DEPOSIT !== $type && TransactionType::TRANSFER !== $type) {
if (TransactionType::DEPOSIT !== $type && TransactionTypeEnum::TRANSFER->value !== $type) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_withdrawal', ['type' => $type])));
return false;
@@ -113,7 +113,7 @@ class ConvertToWithdrawal implements ActionInterface
return false;
}
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::TRANSFER, TransactionTypeEnum::WITHDRAWAL->value));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::TRANSFER->value, TransactionTypeEnum::WITHDRAWAL->value));
return $res;
}

View File

@@ -72,7 +72,7 @@ class SetDestinationAccount implements ActionInterface
// if this is a transfer or a deposit, the new destination account must be an asset account or a default account, and it MUST exist:
$newAccount = $this->findAssetAccount($type, $accountName);
if ((TransactionType::DEPOSIT === $type || TransactionType::TRANSFER === $type) && null === $newAccount) {
if ((TransactionType::DEPOSIT === $type || TransactionTypeEnum::TRANSFER->value === $type) && null === $newAccount) {
app('log')->error(
sprintf(
'Cant change destination account of journal #%d because no asset account with name "%s" exists.',

View File

@@ -71,7 +71,7 @@ class SetSourceAccount implements ActionInterface
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
$newAccount = $this->findAssetAccount($type, $accountName);
if ((TransactionTypeEnum::WITHDRAWAL->value === $type || TransactionType::TRANSFER === $type) && null === $newAccount) {
if ((TransactionTypeEnum::WITHDRAWAL->value === $type || TransactionTypeEnum::TRANSFER->value === $type) && null === $newAccount) {
app('log')->error(
sprintf('Cant change source account of journal #%d because no asset account with name "%s" exists.', $object->id, $accountName)
);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog;
use FireflyIII\Models\RuleAction;
@@ -66,7 +67,7 @@ class SwitchAccounts implements ActionInterface
}
$type = $object->transactionType->type;
if (TransactionType::TRANSFER !== $type) {
if (TransactionTypeEnum::TRANSFER->value !== $type) {
app('log')->error(sprintf('Journal #%d is NOT a transfer (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_not_transfer')));