mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Moved findByAccountNumber
This commit is contained in:
parent
8ef7c5ac33
commit
d1b56c2afa
@ -51,34 +51,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $iban
|
* @param string $iban
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@ -25,14 +25,6 @@ use Illuminate\Support\Collection;
|
|||||||
interface AccountCrudInterface
|
interface AccountCrudInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $number
|
|
||||||
* @param array $types
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function findByAccountNumber(string $number, array $types): Account;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $iban
|
* @param string $iban
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@ -59,7 +59,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $crud->findByAccountNumber($value, [AccountType::ASSET]);
|
$account = $repository->findByAccountNumber($value, [AccountType::ASSET]);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
Log::debug('Found account by name', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
|
@ -62,7 +62,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $crud->findByAccountNumber($value, []);
|
$account = $repository->findByAccountNumber($value, []);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by number', ['id' => $account->id]);
|
Log::debug('Found account by number', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
|
@ -92,6 +92,33 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return $account;
|
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.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
@ -50,6 +50,14 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function find(int $accountId): Account;
|
public function find(int $accountId): Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $number
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
public function findByAccountNumber(string $number, array $types): Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the date of the very first transaction in this account.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user