mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 21:23:36 +00:00
🤖 Auto commit for release 'develop' on 2026-01-23
This commit is contained in:
@@ -51,13 +51,13 @@ class SetDestinationAccount implements ActionInterface
|
||||
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
$accountName = $this->action->getValue($journal);
|
||||
$accountName = $this->action->getValue($journal);
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::find($journal['user_id']);
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
@@ -66,11 +66,11 @@ class SetDestinationAccount implements ActionInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
$type = $object->transactionType->type;
|
||||
$type = $object->transactionType->type;
|
||||
$this->repository->setUser($user);
|
||||
|
||||
// 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);
|
||||
$newAccount = $this->findAssetAccount($type, $accountName);
|
||||
if ((TransactionTypeEnum::DEPOSIT->value === $type || TransactionTypeEnum::TRANSFER->value === $type) && !$newAccount instanceof Account) {
|
||||
Log::error(sprintf('Cant change destination account of journal #%d because no asset account with name "%s" exists.', $object->id, $accountName));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_asset', ['name' => $accountName])));
|
||||
@@ -80,7 +80,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
|
||||
// new destination account must be different from the current source account:
|
||||
/** @var null|Transaction $source */
|
||||
$source = $object->transactions()->where('amount', '<', 0)->first();
|
||||
$source = $object->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $source) {
|
||||
Log::error('Could not find source transaction.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction')));
|
||||
@@ -127,14 +127,15 @@ class SetDestinationAccount implements ActionInterface
|
||||
DB::table('transactions')
|
||||
->where('transaction_journal_id', '=', $object->id)
|
||||
->where('amount', '>', 0)
|
||||
->update(['account_id' => $newAccount->id]);
|
||||
->update(['account_id' => $newAccount->id])
|
||||
;
|
||||
|
||||
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function findAssetAccount(string $type, string $accountName): null|Account
|
||||
private function findAssetAccount(string $type, string $accountName): ?Account
|
||||
{
|
||||
// switch on type:
|
||||
$allowed = config(sprintf('firefly.expected_source_types.destination.%s', $type));
|
||||
@@ -155,7 +156,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
'account_type_id' => null,
|
||||
'virtual_balance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null
|
||||
'iban' => null,
|
||||
];
|
||||
$account = $this->repository->store($data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user