with(['election', 'pusatMengundi', 'transactions']) ->latest() ->paginate(15); return view('admin.management.wheelchairs.index', [ 'allocations' => $allocations, 'elections' => Election::query()->orderByDesc('id')->get(), 'pusats' => PusatMengundi::query()->orderBy('name')->get(), 'service' => $service, ]); } public function store(UpsertWheelchairAllocationRequest $request, WheelchairManagementService $service): RedirectResponse { $allocation = $service->upsertAllocation($request->user(), $request->validated()); return redirect()->route('admin.management.wheelchairs.show', $allocation) ->with('status', 'Peruntukan kerusi roda telah disimpan.'); } public function show(WheelchairAllocation $allocation, WheelchairManagementService $service): View { return view('admin.management.wheelchairs.show', [ 'allocation' => $allocation->load(['election', 'pusatMengundi', 'transactions.recordedBy']), 'elections' => Election::query()->orderByDesc('id')->get(), 'pusats' => PusatMengundi::query()->orderBy('name')->get(), 'service' => $service, ]); } public function update(UpsertWheelchairAllocationRequest $request, WheelchairAllocation $allocation, WheelchairManagementService $service): RedirectResponse { $data = [ ...$request->validated(), 'election_id' => $allocation->election_id, 'pusat_mengundi_id' => $allocation->pusat_mengundi_id, ]; $service->upsertAllocation($request->user(), $data); return redirect()->route('admin.management.wheelchairs.show', $allocation) ->with('status', 'Peruntukan kerusi roda telah dikemas kini.'); } public function recordTaken(StoreTakenTransactionRequest $request, WheelchairAllocation $allocation, WheelchairManagementService $service): RedirectResponse { $service->recordTransaction($allocation, $request->user(), [ 'transaction_type' => 'taken', ...$request->validated(), ]); return redirect()->route('admin.management.wheelchairs.show', $allocation) ->with('status', 'Rekod ambil kerusi roda telah disimpan.'); } public function recordReturn(StoreReturnTransactionRequest $request, WheelchairAllocation $allocation, WheelchairManagementService $service): RedirectResponse { $service->recordTransaction($allocation, $request->user(), [ 'transaction_type' => 'returned', ...$request->validated(), ]); return redirect()->route('admin.management.wheelchairs.show', $allocation) ->with('status', 'Rekod pulang kerusi roda telah disimpan.'); } }