This commit is contained in:
James Cole
2021-04-26 06:18:30 +02:00
parent 97a0110931
commit 0949a264b8
2 changed files with 10 additions and 7 deletions

View File

@@ -56,8 +56,8 @@ class SetDestinationAccount implements ActionInterface
*/ */
public function actOnArray(array $journal): bool public function actOnArray(array $journal): bool
{ {
$user = User::find($journal['user_id']); $user = User::find($journal['user_id']);
$type = $journal['transaction_type_type']; $type = $journal['transaction_type_type'];
/** @var TransactionJournal|null $object */ /** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']); $object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
@@ -108,8 +108,9 @@ class SetDestinationAccount implements ActionInterface
} }
// if this is a withdrawal, the new destination account must be a expense account and may be created: // if this is a withdrawal, the new destination account must be a expense account and may be created:
// or it is a liability, in which case it must be returned.
if (TransactionType::WITHDRAWAL === $type) { if (TransactionType::WITHDRAWAL === $type) {
$newAccount = $this->findExpenseAccount(); $newAccount = $this->findWithdrawalDestinationAccount();
} }
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name)); Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
@@ -145,9 +146,10 @@ class SetDestinationAccount implements ActionInterface
/** /**
* @return Account * @return Account
*/ */
private function findExpenseAccount(): Account private function findWithdrawalDestinationAccount(): Account
{ {
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]); $allowed = config('firefly.expected_source_types.destination.Withdrawal');
$account = $this->repository->findByName($this->action->action_value, $allowed);
if (null === $account) { if (null === $account) {
$data = [ $data = [
'name' => $this->action->action_value, 'name' => $this->action->action_value,

View File

@@ -105,8 +105,9 @@ class SetSourceAccount implements ActionInterface
} }
// if this is a deposit, the new source account must be a revenue account and may be created: // if this is a deposit, the new source account must be a revenue account and may be created:
// or its a liability
if (TransactionType::DEPOSIT === $type) { if (TransactionType::DEPOSIT === $type) {
$newAccount = $this->findRevenueAccount(); $newAccount = $this->findDepositSourceAccount();
} }
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name)); Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
@@ -140,7 +141,7 @@ class SetSourceAccount implements ActionInterface
/** /**
* @return Account * @return Account
*/ */
private function findRevenueAccount(): Account private function findDepositSourceAccount(): Account
{ {
$allowed = config('firefly.expected_source_types.source.Deposit'); $allowed = config('firefly.expected_source_types.source.Deposit');
$account = $this->repository->findByName($this->action->action_value, $allowed); $account = $this->repository->findByName($this->action->action_value, $allowed);