Skip to content

Commit

Permalink
Merge branch 'master' into aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Aug 4, 2024
2 parents 7ad630c + 90c65a8 commit 0e55a0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
12 changes: 0 additions & 12 deletions code/app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ public function index(Request $request)
return $this->easyExecute(function() use ($request) {
$user = $request->user();
$users = $this->service->list('', $user->can('users.admin', $user->gas));

/*
Il grosso collo di bottiglia nell'enumerazione degli utenti è
il recupero sullo stato del saldo di ciascuno, da cui dipendono
poi icone e filtri.
Qui pre-carico il saldo corrente di ognuno, premesso che nella
funzione CreditableTrait::currentBalance() verifico che
effettivamente esista o se è necessario allocare un nuovo saldo
corrente
*/
$users->loadMissing(['balances' => fn($query) => $query->where('current', true)]);

return view('pages.users', ['users' => $users]);
});
}
Expand Down
4 changes: 2 additions & 2 deletions code/app/Models/Concerns/CreditableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public function currentBalance($currency)
{
$proxy = $this->getActualObject();

$balance = $proxy->balances->where('current', true)->where('currency_id', $currency->id)->sortByDesc('date')->first();
$balance = $proxy->balances()->where('current', true)->where('currency_id', $currency->id)->orderBy('date', 'desc')->first();
if (is_null($balance)) {
$balance = $this->balances->where('current', false)->where('currency_id', $currency->id)->sortByDesc('date')->first();
$balance = $this->balances()->where('current', false)->where('currency_id', $currency->id)->orderBy('date', 'desc')->first();
if (is_null($balance)) {
$balance = $this->fixFirstBalance($currency);
}
Expand Down

0 comments on commit 0e55a0d

Please sign in to comment.