@php($milestones=\DB::table('project_milestones')->join('projects','projects.id','=','project_milestones.project_id')->where('projects.business_id',auth()->user()->business_id)->whereNull('project_milestones.deleted_at')->whereNotIn('project_milestones.status',['completed','cancelled'])->select('project_milestones.*','projects.name as project_name')->get())
@php($blocked=$milestones->filter(fn($milestone)=>$milestone->depends_on_milestone_id&&\DB::table('project_milestones')->where('id',$milestone->depends_on_milestone_id)->where('status','!=','completed')->exists()))
@php($overdue=$milestones->filter(fn($milestone)=>$milestone->due_date&&\Carbon\Carbon::parse($milestone->due_date)->isPast()))
<div class="card mt-4"><div class="card-header">Milestone delivery exceptions</div><div class="card-body"><div class="row"><div class="col-md-6"><strong>Overdue: {{ $overdue->count() }}</strong></div><div class="col-md-6"><strong>Blocked: {{ $blocked->count() }}</strong></div></div><table class="table table-sm mt-3"><thead><tr><th>Project</th><th>Milestone</th><th>Planned</th><th>Reason</th></tr></thead><tbody>@forelse($overdue->merge($blocked)->unique('id') as $milestone)<tr><td>{{ $milestone->project_name }}</td><td>{{ $milestone->name }}</td><td>{{ $milestone->due_date }}</td><td>{{ $milestone->blocking_reason ?: ($blocked->contains('id',$milestone->id)?'Dependency incomplete':'Overdue') }}</td></tr>@empty<tr><td colspan="4" class="text-muted">No blocked or overdue milestones.</td></tr>@endforelse</tbody></table></div></div>
