|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Modules\HR\Http\Controllers; |
| 4 | + |
| 5 | +use App\Modules\HR\Models\SuccessionPlan; |
| 6 | +use Illuminate\Http\RedirectResponse; |
| 7 | +use Illuminate\Http\Request; |
| 8 | +use Inertia\Inertia; |
| 9 | +use Inertia\Response; |
| 10 | + |
| 11 | +class SuccessionPlanController |
| 12 | +{ |
| 13 | + public function index(): Response |
| 14 | + { |
| 15 | + $plans = SuccessionPlan::with('currentHolder') |
| 16 | + ->orderByDesc('created_at') |
| 17 | + ->paginate(20); |
| 18 | + |
| 19 | + return Inertia::render('HR/SuccessionPlans/Index', compact('plans')); |
| 20 | + } |
| 21 | + |
| 22 | + public function create(): Response |
| 23 | + { |
| 24 | + return Inertia::render('HR/SuccessionPlans/Create'); |
| 25 | + } |
| 26 | + |
| 27 | + public function store(Request $request): RedirectResponse |
| 28 | + { |
| 29 | + $data = $request->validate([ |
| 30 | + 'position_title' => 'required|string|max:255', |
| 31 | + 'department' => 'nullable|string|max:255', |
| 32 | + 'description' => 'nullable|string', |
| 33 | + 'is_critical' => 'nullable|boolean', |
| 34 | + 'current_holder_id' => 'nullable|exists:employees,id', |
| 35 | + ]); |
| 36 | + |
| 37 | + $data['tenant_id'] = app('tenant')->id; |
| 38 | + $data['created_by'] = auth()->id(); |
| 39 | + |
| 40 | + SuccessionPlan::create($data); |
| 41 | + |
| 42 | + return redirect()->route('hr.succession-plans.index'); |
| 43 | + } |
| 44 | + |
| 45 | + public function show(SuccessionPlan $successionPlan): Response |
| 46 | + { |
| 47 | + $successionPlan->load('candidates.employee', 'currentHolder'); |
| 48 | + return Inertia::render('HR/SuccessionPlans/Show', ['plan' => $successionPlan]); |
| 49 | + } |
| 50 | + |
| 51 | + public function edit(SuccessionPlan $successionPlan): Response |
| 52 | + { |
| 53 | + return Inertia::render('HR/SuccessionPlans/Edit', ['plan' => $successionPlan]); |
| 54 | + } |
| 55 | + |
| 56 | + public function update(Request $request, SuccessionPlan $successionPlan): RedirectResponse |
| 57 | + { |
| 58 | + $data = $request->validate([ |
| 59 | + 'position_title' => 'required|string|max:255', |
| 60 | + 'department' => 'nullable|string|max:255', |
| 61 | + 'description' => 'nullable|string', |
| 62 | + 'is_critical' => 'nullable|boolean', |
| 63 | + 'current_holder_id' => 'nullable|exists:employees,id', |
| 64 | + ]); |
| 65 | + |
| 66 | + $successionPlan->update($data); |
| 67 | + |
| 68 | + return redirect()->route('hr.succession-plans.index'); |
| 69 | + } |
| 70 | + |
| 71 | + public function destroy(SuccessionPlan $successionPlan): RedirectResponse |
| 72 | + { |
| 73 | + $successionPlan->delete(); |
| 74 | + return redirect()->route('hr.succession-plans.index'); |
| 75 | + } |
| 76 | + |
| 77 | + public function complete(SuccessionPlan $successionPlan): RedirectResponse |
| 78 | + { |
| 79 | + $successionPlan->complete(); |
| 80 | + return redirect()->route('hr.succession-plans.index'); |
| 81 | + } |
| 82 | + |
| 83 | + public function deactivate(SuccessionPlan $successionPlan): RedirectResponse |
| 84 | + { |
| 85 | + $successionPlan->deactivate(); |
| 86 | + return redirect()->route('hr.succession-plans.index'); |
| 87 | + } |
| 88 | +} |
0 commit comments