<?php namespace App\Http\Controllers; use App\Models\{Expense,ExpenseCategory}; use App\Services\ApprovalService; use Illuminate\Http\Request; class ExpenseController extends Controller {public function index(){return view('expenses.index',['expenses'=>Expense::latest('expense_date')->paginate(25)]);}public function store(Request $r,ApprovalService $a){$d=$r->validate(['expense_category_id'=>'required|exists:expense_categories,id','type'=>'required|string|max:50','expense_date'=>'required|date','amount'=>'required|numeric|min:0.01','description'=>'required|string|max:2000','project_id'=>'nullable|exists:projects,id','department_id'=>'nullable|exists:departments,id']);$d['claimant_user_id']=$r->user()->id;$d['status']='submitted';$e=Expense::create($d);$cat=ExpenseCategory::find($d['expense_category_id']);$roles=['team_lead','finance'];if($cat?->requires_founder_approval)$roles[]='founder';$a->start($e,$roles);return back()->with('success','Expense submitted for multi-step approval.');}}