From be844b82af950c182123f8a3f36f8071ff5ab91c Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 27 Apr 2021 06:57:06 +0200 Subject: [PATCH] Add missing method. --- .../Account/AccountRepository.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 2717239829..a3f7e4c198 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -764,4 +764,30 @@ class AccountRepository implements AccountRepositoryInterface return $journal->transactionGroup; } + + /** + * @inheritDoc + */ + public function findByAccountNumber(string $number, array $types): ?Account + { + $dbQuery = $this->user + ->accounts() + ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') + ->where('accounts.active', true) + ->where( + function (EloquentBuilder $q1) use ($number) { + $json = json_encode($number); + $q1->where('account_meta.name', '=', 'account_number'); + $q1->where('account_meta.data', '=', $json); + } + ); + + if (0 !== count($types)) { + $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); + $dbQuery->whereIn('account_types.type', $types); + } + + return $dbQuery->first(['accounts.*']); + } + }