first
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Management;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\Management\StoreReturnTransactionRequest;
|
||||
use App\Http\Requests\Admin\Management\StoreTakenTransactionRequest;
|
||||
use App\Http\Requests\Admin\Management\UpsertWheelchairAllocationRequest;
|
||||
use App\Models\Election;
|
||||
use App\Models\PusatMengundi;
|
||||
use App\Models\WheelchairAllocation;
|
||||
use App\Services\Admin\Management\WheelchairManagementService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class WheelchairController extends Controller
|
||||
{
|
||||
public function index(WheelchairManagementService $service): View
|
||||
{
|
||||
$allocations = WheelchairAllocation::query()
|
||||
->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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user