<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\PayrollBatch; use App\Services\PayrollService; class PayrollController extends Controller {public function index(){return view('payroll.index',['batches'=>PayrollBatch::withCount('items')->latest()->paginate(20)]);}public function calculate(Request $r,PayrollService $s){$d=$r->validate(['period'=>'required|date_format:Y-m']);try{$s->calculate($d['period']);return back()->with('success','Payroll calculated with attendance, leave, overtime, tax and approved adjustments.');}catch(\RuntimeException $e){return back()->withErrors(['payroll'=>$e->getMessage()]);}}public function approve(PayrollBatch $batch,Request $r,PayrollService $s){try{$s->approve($batch,$r->user()->id);return back()->with('success','Payroll approved and locked.');}catch(\RuntimeException $e){return back()->withErrors(['payroll'=>$e->getMessage()]);}}public function paid(PayrollBatch $batch,PayrollService $s){try{$s->markPaid($batch);return back()->with('success','Payroll marked paid.');}catch(\RuntimeException $e){return back()->withErrors(['payroll'=>$e->getMessage()]);}}}