initial commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Supervisor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Supervisor\Concerns\ScopesSupervisorResources;
|
||||
use App\Models\Wash;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class WashPageController extends Controller
|
||||
{
|
||||
use ScopesSupervisorResources;
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = Wash::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('started_at', $request->string('date'));
|
||||
}
|
||||
|
||||
$washes = $query
|
||||
->orderByDesc('started_at')
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->through(fn (Wash $wash) => [
|
||||
'uuid' => $wash->uuid,
|
||||
'status' => $wash->status,
|
||||
'status_label' => $this->statusLabel($wash->status),
|
||||
'program' => $wash->program,
|
||||
'trigger_method' => $wash->trigger_method,
|
||||
'trigger_method_label' => $this->triggerMethodLabel($wash->trigger_method),
|
||||
'started_at' => $wash->started_at?->toIso8601String(),
|
||||
'ended_at' => $wash->ended_at?->toIso8601String(),
|
||||
'duration_minutes' => $wash->duration_minutes,
|
||||
'cost' => (float) $wash->cost,
|
||||
'user' => $wash->user ? [
|
||||
'name' => trim($wash->user->first_name.' '.$wash->user->last_name),
|
||||
'email' => $wash->user->email,
|
||||
] : null,
|
||||
'machine' => $wash->machine ? [
|
||||
'uuid' => $wash->machine->uuid,
|
||||
'name' => $wash->machine->name,
|
||||
'establishment_name' => $wash->machine->establishment?->name,
|
||||
] : null,
|
||||
]);
|
||||
|
||||
return Inertia::render('Supervisor/Washes/Index', [
|
||||
'washes' => $washes,
|
||||
'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_start' => 'En attente',
|
||||
'running' => 'En cours',
|
||||
'completed' => 'Terminé',
|
||||
'failed' => 'Échoué',
|
||||
'cancelled' => 'Annulé',
|
||||
];
|
||||
}
|
||||
|
||||
private function statusLabel(string $status): string
|
||||
{
|
||||
return $this->statusOptions()[$status] ?? $status;
|
||||
}
|
||||
|
||||
private function triggerMethodLabel(string $method): string
|
||||
{
|
||||
return match ($method) {
|
||||
'qr_code' => 'QR code',
|
||||
'booking' => 'Réservation',
|
||||
'supervisor' => 'Superviseur',
|
||||
'system' => 'Système',
|
||||
default => $method,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user