Move findByIban

This commit is contained in:
James Cole
2016-10-10 07:16:05 +02:00
parent d1b56c2afa
commit 0ae9afd325
7 changed files with 45 additions and 38 deletions

View File

@@ -19,6 +19,7 @@ use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -119,6 +120,32 @@ class AccountRepository implements AccountRepositoryInterface
return new Account;
}
/**
* @param string $iban
* @param array $types
*
* @return Account
*/
public function findByIban(string $iban, array $types): Account
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->iban === $iban) {
return $account;
}
}
return new Account;
}
/**
* Returns the date of the very first transaction in this account.
*