<?php namespace App\Http\Controllers; use App\Models\{Offboarding,User,AssetAssignment}; use Illuminate\Http\Request; class OffboardingController extends Controller {public function index(){return view('offboarding.index',['items'=>Offboarding::with('user')->latest()->paginate(25)]);}public function store(Request $r){$d=$r->validate(['user_id'=>'required|exists:users,id','type'=>'required|in:resignation,termination,contract_end','notice_date'=>'nullable|date','last_working_date'=>'required|date','reason'=>'nullable|string|max:2000']);$d['processed_by']=$r->user()->id;Offboarding::create($d);return back()->with('success','Offboarding initiated.');}public function complete(Offboarding $offboarding,Request $r){$open=AssetAssignment::where('user_id',$offboarding->user_id)->whereNull('returned_at')->exists();abort_if($open,422,'Return all assigned assets before completing offboarding.');$offboarding->update(['assets_cleared'=>true,'finance_cleared'=>true,'access_revoked'=>true,'status'=>'completed','settled_at'=>now()]);$offboarding->user->update(['status'=>'inactive']);return back()->with('success','Offboarding completed and access disabled.');}}