This commit is contained in:
James Cole
2020-03-22 17:28:25 +01:00
parent 5ee1f322d0
commit cdebde5a2b

View File

@@ -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 = [