Move getActiveAccountsByType

This commit is contained in:
James Cole
2016-10-10 07:53:12 +02:00
parent f8935c92ea
commit 1dc17dd59d
5 changed files with 48 additions and 70 deletions

View File

@@ -225,6 +225,33 @@ class AccountRepository implements AccountRepositoryInterface
return $result;
}
/**
* @param array $types
*
* @return Collection
*/
public function getActiveAccountsByType(array $types): Collection
{
/** @var Collection $result */
$query = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
);
if (count($types) > 0) {
$query->accountTypeIn($types);
}
$query->where('active', 1);
$result = $query->get(['accounts.*']);
$result = $result->sortBy(
function (Account $account) {
return strtolower($account->name);
}
);
return $result;
}
/**
* Returns the date of the very first transaction in this account.
*

View File

@@ -89,6 +89,13 @@ interface AccountRepositoryInterface
*/
public function getAccountsByType(array $types): Collection;
/**
* @param array $types
*
* @return Collection
*/
public function getActiveAccountsByType(array $types): Collection;
/**
* Returns the date of the very first transaction in this account.
*