Make sure the user can create liabilities in the "credit" direction with the right transactions.

This commit is contained in:
James Cole
2021-04-10 17:26:36 +02:00
parent 5d7ca1ef9a
commit 0426fa63d0
9 changed files with 636 additions and 149 deletions

View File

@@ -125,7 +125,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (0!==count($types)) {
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@@ -747,4 +747,21 @@ class AccountRepository implements AccountRepositoryInterface
return $service->update($account, $data);
}
/**
* @inheritDoc
*/
public function getCreditTransactionGroup(Account $account): ?TransactionGroup
{
$journal = TransactionJournal
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*']);
if (null === $journal) {
return null;
}
return $journal->transactionGroup;
}
}

View File

@@ -198,6 +198,13 @@ interface AccountRepositoryInterface
*/
public function getOpeningBalanceDate(Account $account): ?string;
/**
* @param Account $account
*
* @return TransactionGroup|null
*/
public function getCreditTransactionGroup(Account $account): ?TransactionGroup;
/**
* @param Account $account
*