Expand account index overview.

This commit is contained in:
James Cole
2024-04-28 09:54:28 +02:00
parent 56c9026299
commit c1c0afa40b
22 changed files with 502 additions and 189 deletions

View File

@@ -240,7 +240,7 @@ class AccountRepository implements AccountRepositoryInterface
}
}
public function getAccountsByType(array $types, ?array $sort = []): Collection
public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection
{
$sortable = ['name', 'active']; // TODO yes this is a duplicate array.
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
@@ -249,6 +249,19 @@ class AccountRepository implements AccountRepositoryInterface
$query->accountTypeIn($types);
}
// process filters
// TODO this should be repeatable, it feels like a hack when you do it here.
foreach($filters as $column => $value) {
// filter on NULL values
if(null === $value) {
continue;
}
if ('active' === $column) {
$query->where('accounts.active', $value);
}
}
// add sort parameters. At this point they're filtered to allowed fields to sort by:
$hasActiveColumn = array_key_exists('active', $sort);
if (count($sort) > 0) {

View File

@@ -55,7 +55,7 @@ interface AccountRepositoryInterface
public function getAccountsById(array $accountIds): Collection;
public function getAccountsByType(array $types, ?array $sort = []): Collection;
public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection;
/**
* Used in the infinite accounts list.