<?php namespace App\Http\Controllers; use App\Models\{AttendanceMonthLock,AttendanceRecord,AttendanceRegularization,RemoteWorkRequest}; use App\Services\ApprovalService; use Illuminate\Http\Request; class AttendanceAdminController extends Controller {public function index(){return view('attendance.admin',['records'=>AttendanceRecord::with('user')->latest('work_date')->paginate(30),'regularizations'=>AttendanceRegularization::with('user')->latest()->limit(30)->get(),'remote'=>RemoteWorkRequest::with('user')->latest()->limit(30)->get(),'locks'=>AttendanceMonthLock::latest()->limit(12)->get()]);}public function lock(Request $r){$d=$r->validate(['period'=>'required|date_format:Y-m','notes'=>'nullable|string|max:1000']);AttendanceMonthLock::firstOrCreate(['period'=>$d['period']],['locked_by'=>$r->user()->id,'locked_at'=>now(),'notes'=>$d['notes']??null]);AttendanceRecord::whereBetween('work_date',[$d['period'].'-01',date('Y-m-t',strtotime($d['period'].'-01'))])->update(['is_locked'=>true]);return back()->with('success','Attendance month locked.');}public function requestRemote(Request $r,ApprovalService $a){$d=$r->validate(['work_date'=>'required|date','reason'=>'required|string|max:2000']);$m=RemoteWorkRequest::updateOrCreate(['user_id'=>$r->user()->id,'work_date'=>$d['work_date']],['reason'=>$d['reason'],'status'=>'pending']);$a->start($m,['team_lead','hr']);return back()->with('success','Remote-work request submitted.');}}