@php
 $businessId=auth()->user()->business_id;$users=\App\Models\User::where('business_id',$businessId)->orderBy('name')->get(['id','name']);
 $query=\DB::table('project_risks_issues')->join('projects','projects.id','=','project_risks_issues.project_id')->leftJoin('users','users.id','=','project_risks_issues.owner_id')->where('project_risks_issues.business_id',$businessId)->select('project_risks_issues.*','projects.name as project_name','users.name as owner_name');
 if(request('risk_owner'))$query->where('project_risks_issues.owner_id',request('risk_owner'));if(request('risk_severity'))$query->where('project_risks_issues.severity',request('risk_severity'));if(request('risk_status'))$query->where('project_risks_issues.status',request('risk_status'));if(request('risk_due_from'))$query->whereDate('project_risks_issues.due_date','>=',request('risk_due_from'));if(request('risk_due_to'))$query->whereDate('project_risks_issues.due_date','<=',request('risk_due_to'));
 $items=$query->latest('project_risks_issues.created_at')->get();$open=$items->whereNotIn('status',['resolved','closed']);$high=$open->where('severity','high')->count();$critical=$open->where('severity','critical')->count();
@endphp
<div class="card mt-4"><div class="card-header"><h5 class="mb-0">Project risks &amp; issues</h5></div><div class="card-body"><form method="GET" class="row g-2 mb-3"><div class="col-md-2"><select class="form-select" name="risk_owner"><option value="">All owners</option>@foreach($users as $user)<option value="{{ $user->id }}" @selected(request('risk_owner')==$user->id)>{{ $user->name }}</option>@endforeach</select></div><div class="col-md-2"><select class="form-select" name="risk_severity"><option value="">All severities</option>@foreach(['low','medium','high','critical'] as $value)<option value="{{ $value }}" @selected(request('risk_severity')===$value)>{{ ucfirst($value) }}</option>@endforeach</select></div><div class="col-md-2"><select class="form-select" name="risk_status"><option value="">All statuses</option>@foreach(['open','mitigating','resolved','closed'] as $value)<option value="{{ $value }}" @selected(request('risk_status')===$value)>{{ ucfirst($value) }}</option>@endforeach</select></div><div class="col-md-2"><input class="form-control" type="date" name="risk_due_from" value="{{ request('risk_due_from') }}"></div><div class="col-md-2"><input class="form-control" type="date" name="risk_due_to" value="{{ request('risk_due_to') }}"></div><div class="col-auto"><button class="btn btn-outline-primary">Filter</button></div></form><div class="row g-2 mb-3"><div class="col-md-4"><div class="border rounded p-2">Open <strong class="float-end">{{ $open->count() }}</strong></div></div><div class="col-md-4"><div class="border rounded p-2">High <strong class="float-end">{{ $high }}</strong></div></div><div class="col-md-4"><div class="border rounded p-2">Critical <strong class="float-end">{{ $critical }}</strong></div></div></div><table class="table table-sm"><thead><tr><th>Project</th><th>Type</th><th>Title</th><th>Owner</th><th>Severity</th><th>Due</th><th>Status</th></tr></thead><tbody>@forelse($items as $item)<tr><td><a href="{{ route('projects-view',['id'=>$item->project_id]) }}">{{ $item->project_name }}</a></td><td>{{ ucfirst($item->type) }}</td><td>{{ $item->title }}</td><td>{{ $item->owner_name }}</td><td>{{ ucfirst($item->severity) }}</td><td>{{ $item->due_date }}</td><td>{{ ucfirst($item->status) }}</td></tr>@empty<tr><td colspan="7" class="text-muted">No matching project risks or issues.</td></tr>@endforelse</tbody></table></div></div>
