Skip to content

Commit

Permalink
filtro utenti in pannello ricevute; ottimizzazione in elenco movimenti
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Aug 4, 2024
1 parent b62d7e7 commit a553311
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/app/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getSlugID()

public function getUserAttribute()
{
$first = $this->bookings()->first();
$first = $this->bookings->first();
if ($first)
return $first->user;
else
Expand Down
8 changes: 7 additions & 1 deletion code/app/Services/MovementsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Database\Eloquent\Relations\MorphTo;

use App\Models\Concerns\CreditableTrait;
use App\Booking;
use App\Movement;
use App\User;
use App\Balance;
Expand Down Expand Up @@ -146,7 +148,11 @@ public function list($request)
$query->where('amount', '<=', $request['amountend']);
}

return $query->with(['currency'])->get();
return $query->with(['sender', 'currency', 'target' => function(MorphTo $morphTo) {
$morphTo->morphWith([
Booking::class => ['order'],
]);
}])->get();
}

public function show($id)
Expand Down
2 changes: 1 addition & 1 deletion code/app/Services/ReceiptsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function list($start, $end, $supplier_id, $user_id = 0)
}
}

$query = Receipt::where('date', '>=', $start)->where('date', '<=', $end)->orderBy('date', 'desc');
$query = Receipt::where('date', '>=', $start)->where('date', '<=', $end)->with(['bookings', 'bookings.user'])->orderBy('date', 'desc');

if ($supplier_id != '0' || $user_id != 0) {
$query->whereHas('bookings', function($query) use ($supplier_id, $user_id) {
Expand Down
2 changes: 1 addition & 1 deletion code/app/Services/UsersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function list($term = '', $all = false)
$user = $this->ensureAuth(['users.admin' => 'gas', 'users.movements' => 'gas', 'users.view' => 'gas', 'supplier.shippings' => null]);

$gas_id = $user->gas['id'];
$query = User::with('roles')->where('parent_id', null)->where('gas_id', '=', $gas_id);
$query = User::with('roles')->topLevel()->where('gas_id', '=', $gas_id);

if (!empty($term)) {
$query->where(function ($query) use ($term) {
Expand Down
5 changes: 5 additions & 0 deletions code/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function scopeFilterEnabled($query)
return $query;
}

public function scopeTopLevel($query)
{
return $query->whereNull('parent_id');
}

public function scopeSorted($query)
{
return $query->orderBy('lastname', 'asc')->orderBy('firstname', 'asc');
Expand Down
7 changes: 6 additions & 1 deletion code/resources/views/receipt/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
<div class="col-12 col-md-6">
<x-filler :data-action="route('receipts.search')" data-fill-target="#receipts-in-range" :actionButtons="$actions" :downloadButtons="$downloads">
@include('commons.genericdaterange', ['start_date' => strtotime('-1 months')])
<x-larastrap::hidden name="user_id" :value="$user_id" />
<x-larastrap::selectobj name="supplier_id" :label="_i('Fornitore')" :options="$currentgas->suppliers" :extraitem="_i('Nessuno')" />

@if($user_id == '0')
<x-larastrap::selectobj name="user_id" :label="_i('Utente')" :options="$currentgas->users()->topLevel()->sorted()->get()" :extraitem="_i('Nessuno')" />
@else
<x-larastrap::hidden name="user_id" :value="$user_id" />
@endif
</x-filler>
</div>
</div>
Expand Down

0 comments on commit a553311

Please sign in to comment.