Moved findByAccountNumber

This commit is contained in:
James Cole
2016-10-10 07:14:01 +02:00
parent 8ef7c5ac33
commit d1b56c2afa
6 changed files with 37 additions and 38 deletions

View File

@@ -92,6 +92,33 @@ class AccountRepository implements AccountRepositoryInterface
return $account;
}
/**
* @param string $number
* @param array $types
*
* @return Account
*/
public function findByAccountNumber(string $number, array $types): Account
{
$query = $this->user->accounts()
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
->where('account_meta.name', 'accountNumber')
->where('account_meta.data', json_encode($number));
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Collection $accounts */
$accounts = $query->get(['accounts.*']);
if ($accounts->count() > 0) {
return $accounts->first();
}
return new Account;
}
/**
* Returns the date of the very first transaction in this account.
*