86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Supervisor;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Supervisor\Concerns\ScopesSupervisorResources;
|
|
use App\Models\Booking;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class BookingPageController extends Controller
|
|
{
|
|
use ScopesSupervisorResources;
|
|
|
|
public function index(Request $request): Response
|
|
{
|
|
$query = Booking::query()
|
|
->with(['user:id,first_name,last_name,email', 'machine:id,uuid,name,establishment_id', 'machine.establishment:id,name']);
|
|
|
|
$this->scopeMachineRelationQuery($query);
|
|
|
|
if ($request->filled('status')) {
|
|
$query->where('status', $request->string('status'));
|
|
}
|
|
|
|
if ($request->filled('date')) {
|
|
$query->whereDate('slot_start', $request->string('date'));
|
|
}
|
|
|
|
$bookings = $query
|
|
->orderByDesc('slot_start')
|
|
->paginate(20)
|
|
->withQueryString()
|
|
->through(fn (Booking $booking) => [
|
|
'uuid' => $booking->uuid,
|
|
'status' => $booking->status,
|
|
'status_label' => $this->statusLabel($booking->status),
|
|
'slot_start' => $booking->slot_start?->toIso8601String(),
|
|
'slot_end' => $booking->slot_end?->toIso8601String(),
|
|
'booking_fee' => (float) $booking->booking_fee,
|
|
'reserved_amount' => (float) $booking->reserved_amount,
|
|
'penalty_amount' => (float) $booking->penalty_amount,
|
|
'user' => $booking->user ? [
|
|
'name' => trim($booking->user->first_name.' '.$booking->user->last_name),
|
|
'email' => $booking->user->email,
|
|
] : null,
|
|
'machine' => $booking->machine ? [
|
|
'uuid' => $booking->machine->uuid,
|
|
'name' => $booking->machine->name,
|
|
'establishment_name' => $booking->machine->establishment?->name,
|
|
] : null,
|
|
]);
|
|
|
|
return Inertia::render('Supervisor/Bookings/Index', [
|
|
'bookings' => $bookings,
|
|
'filters' => [
|
|
'status' => $request->string('status')->toString() ?: null,
|
|
'date' => $request->string('date')->toString() ?: null,
|
|
],
|
|
'statusOptions' => $this->statusOptions(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
private function statusOptions(): array
|
|
{
|
|
return [
|
|
'pending' => 'En attente',
|
|
'confirmed' => 'Confirmée',
|
|
'cancelled' => 'Annulée',
|
|
'expired' => 'Expirée',
|
|
'active' => 'Active',
|
|
'completed' => 'Terminée',
|
|
'no_show' => 'Absent',
|
|
];
|
|
}
|
|
|
|
private function statusLabel(string $status): string
|
|
{
|
|
return $this->statusOptions()[$status] ?? $status;
|
|
}
|
|
}
|