Remove various sort routines.

This commit is contained in:
James Cole
2019-05-04 20:58:43 +02:00
parent d5c5fa4fad
commit 8676764513
19 changed files with 261 additions and 151 deletions

View File

@@ -94,7 +94,7 @@ class BillRepository implements BillRepositoryInterface
*
* @return Bill|null
*/
public function findBill( ?int $billId, ?string $billName): ?Bill
public function findBill(?int $billId, ?string $billName): ?Bill
{
if (null !== $billId) {
$searchResult = $this->find((int)$billId);
@@ -146,8 +146,8 @@ class BillRepository implements BillRepositoryInterface
/** @var Collection $set */
$set = $this->user->bills()
->where('active', 1)
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),])
->sortBy('name');
->orderBy('bills.name', 'ASC')
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
return $set;
}
@@ -170,15 +170,7 @@ class BillRepository implements BillRepositoryInterface
public function getBills(): Collection
{
/** @var Collection $set */
$set = $this->user->bills()->orderBy('name', 'ASC')->get();
$set = $set->sortBy(
function (Bill $bill) {
$int = $bill->active ? 0 : 1;
return $int . strtolower($bill->name);
}
);
$set = $this->user->bills()->orderBy('active', 'DESC')->orderBy('name', 'ASC')->get();
return $set;
}
@@ -210,17 +202,11 @@ class BillRepository implements BillRepositoryInterface
)
->whereIn('transactions.account_id', $ids)
->whereNull('transaction_journals.deleted_at')
->orderBy('bills.active', 'DESC')
->orderBy('bills.name', 'ASC')
->groupBy($fields)
->get($fields);
$set = $set->sortBy(
function (Bill $bill) {
$int = $bill->active ? 0 : 1;
return $int . strtolower($bill->name);
}
);
return $set;
}