mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Fixed #3048
This commit is contained in:
@@ -71,6 +71,7 @@ class SetSourceAccount implements ActionInterface
|
||||
$this->repository->setUser($journal->user);
|
||||
// journal type:
|
||||
$type = $journal->transactionType->type;
|
||||
|
||||
// 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:
|
||||
if ((TransactionType::WITHDRAWAL === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
|
||||
Log::error(
|
||||
@@ -110,18 +111,22 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function findAssetAccount(): bool
|
||||
private function findAssetAccount(string $type): bool
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
||||
// switch on type:
|
||||
$allowed = config(sprintf('firefly.expected_source_types.source.%s', $type));
|
||||
$account = $this->repository->findByName($this->action->action_value, $allowed);
|
||||
|
||||
if (null === $account) {
|
||||
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
||||
Log::debug(sprintf('There is NO valid source account called "%s".', $this->action->action_value));
|
||||
|
||||
return false;
|
||||
}
|
||||
Log::debug(sprintf('There exists an asset account called "%s". ID is #%d', $this->action->action_value, $account->id));
|
||||
Log::debug(sprintf('There exists a valid source account called "%s". ID is #%d', $this->action->action_value, $account->id));
|
||||
$this->newSourceAccount = $account;
|
||||
|
||||
return true;
|
||||
@@ -132,7 +137,8 @@ class SetSourceAccount implements ActionInterface
|
||||
*/
|
||||
private function findRevenueAccount(): void
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
|
||||
$allowed = config('firefly.expected_source_types.source.Deposit');
|
||||
$account = $this->repository->findByName($this->action->action_value, $allowed);
|
||||
if (null === $account) {
|
||||
// create new revenue account with this name:
|
||||
$data = [
|
||||
|
Reference in New Issue
Block a user