From cdebde5a2b12538f617d06355f14c9a5140a6628 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 22 Mar 2020 17:28:25 +0100 Subject: [PATCH] Fixed #3048 --- .../Actions/SetSourceAccount.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/TransactionRules/Actions/SetSourceAccount.php b/app/TransactionRules/Actions/SetSourceAccount.php index d38f38edf9..5b80cad798 100644 --- a/app/TransactionRules/Actions/SetSourceAccount.php +++ b/app/TransactionRules/Actions/SetSourceAccount.php @@ -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 = [