52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Pelaksana;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Permohonan;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SemakanController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$permohonan = Permohonan::with(['user', 'jabatan', 'vot'])
|
|
->where('jabatan_id', auth()->user()->jabatan_id)
|
|
->whereIn('status', ['Submitted', 'Under Review', 'Accepted', 'Rejected'])
|
|
->latest()->paginate(10);
|
|
|
|
return view('pelaksana.index', compact('permohonan'));
|
|
}
|
|
|
|
public function show(Permohonan $permohonan)
|
|
{
|
|
abort_unless($permohonan->jabatan_id === auth()->user()->jabatan_id || auth()->user()->hasRole('Admin'), 403);
|
|
return view('pelaksana.show', ['permohonan' => $permohonan->load(['items', 'user', 'jabatan', 'vot'])]);
|
|
}
|
|
|
|
public function update(Request $request, Permohonan $permohonan)
|
|
{
|
|
$validated = $request->validate([
|
|
'items' => ['required', 'array'],
|
|
'items.*.status_item' => ['required', 'in:Pending,Accepted,Rejected,Partial Accept'],
|
|
'items.*.catatan_pelaksana' => ['nullable'],
|
|
'catatan_semakan' => ['nullable'],
|
|
]);
|
|
|
|
foreach ($validated['items'] as $id => $row) {
|
|
$permohonan->items()->whereKey($id)->update($row);
|
|
}
|
|
|
|
$hasReject = $permohonan->items()->where('status_item', 'Rejected')->exists();
|
|
$permohonan->update([
|
|
'status' => $hasReject ? 'Rejected' : 'Accepted',
|
|
'status_semakan' => 'Selesai',
|
|
'catatan_semakan' => $validated['catatan_semakan'] ?? null,
|
|
'reviewed_by' => auth()->id(),
|
|
'reviewed_at' => now(),
|
|
]);
|
|
|
|
return redirect()->route('semakan.index')->with('success', 'Semakan berjaya dihantar kepada Admin.');
|
|
}
|
|
}
|