{{-- ============================================================ PHASE 4 — IMPACT ASSESSMENT + CAPA + ACTIONS ============================================================ --}} @php $impact = $deviation->impact; $activeLinks = $deviation->capaLinkages->where('is_active', true); @endphp
{{-- ──────────────────────────────────────────────────────── Impact Assessment ──────────────────────────────────────────────────────── --}}
Impact Assessment
@if($impact)
Impact Type {{ $impact->impact_type }}
Severity {{ $impact->severity_level }}
Mitigation {!! $impact->mitigation_required ? 'Required' : 'Not Required' !!}
Version v{{ $impact->assessment_version }} @if($impact->approved_at) Approved @endif
Description:
{!! nl2br(e($impact->impact_description)) !!}
{{-- Impact Items --}}
Detailed Impact Items
@if($impact->items->isEmpty())
No detailed impact items. Required for Gate 4.
@else
@foreach($impact->items as $item) @endforeach
Type Description Severity Mitigation Proposed Target Status
{{ $item->impact_type ?? '—' }} {{ Str::limit($item->impact_description, 60) }} {{ $item->severity }} {!! $item->requires_mitigation ? 'YES' : 'NO' !!} {{ Str::limit($item->proposed_mitigation, 40) ?? '—' }} {{ $item->target_date?->format('M j, Y') ?? '—' }} {{ $item->mitigation_status }}
@csrf @method('DELETE')
@endif @else
Impact assessment required for Gate 4. Click Add Impact above to begin.
@endif
{{-- ═══════════════════════════════════════════════════════════ CAPA LINKAGE ═══════════════════════════════════════════════════════════ --}} @php $activeLinks = $deviation->capaLinkages->where('is_active', true); $pendingLinks = $deviation->capaLinkages->filter(fn ($l) => $l->isAwaitingApproval()); $canCreateCapa = auth()->user()->can('capa.create') || (method_exists(auth()->user(), 'isSuperAdmin') && auth()->user()->isSuperAdmin()); @endphp
Corrective & Preventive Actions (CAPA)
@if($canCreateCapa) @endif @if(($availableCapas ?? collect())->isNotEmpty()) @else @endif
{{-- ─── Pending approval banner ────────────────────── --}} @if($pendingLinks->isNotEmpty())
Approval pending — the following CAPA linkages are awaiting sign-off:
    @foreach($pendingLinks as $pending)
  • CAPA #{{ $pending->capa_id }} {{ $pending->linkage_type }} @if($pending->approvalInstance) — Workflow #{{ $pending->approvalInstance->instance_id }} at step {{ $pending->approvalInstance->current_step }} @endif
  • @endforeach

The linkage becomes active automatically once approved.

@endif {{-- ─── Active linkages table ──────────────────────── --}} @if($activeLinks->isEmpty() && $pendingLinks->isEmpty())
No CAPA linked. Required for Gate 4. Use the Create New CAPA button above to add one.
@else
@foreach($activeLinks as $link) @endforeach {{-- Pending linkages shown in the same table with a "Pending" badge --}} @foreach($pendingLinks as $pending) @endforeach
CAPA Number Title Type Priority Status Linkage Linked Actions
{{ $link->capa?->capa_number ?? 'CAPA #' . $link->capa_id }} {{ Str::limit($link->capa?->title ?? '—', 60) }} {{ $link->capa?->capa_type ?? '—' }} {{ $link->capa?->priority ?? '—' }} {{ $link->capa?->status ?? '—' }} {{ $link->linkage_type }} @if($link->approval_instance_id)
WF #{{ $link->approval_instance_id }} @endif
{{ $link->linked_date?->format('M j, Y') ?? '—' }}
@csrf @method('DELETE')
{{ $pending->capa?->capa_number ?? 'CAPA #' . $pending->capa_id }} {{ Str::limit($pending->capa?->title ?? '—', 60) }} {{ $pending->capa?->capa_type ?? '—' }} {{ $pending->capa?->priority ?? '—' }} Awaiting approval Pending @if($pending->approval_instance_id)
WF #{{ $pending->approval_instance_id }} @endif
{{ $pending->linked_date?->format('M j, Y') ?? '—' }}
@csrf @method('DELETE')
@endif
{{-- Modals unchanged — the store endpoint handles the approval branching --}} @include('deviations.partials.modals.capa-linkage-modals', [ 'deviation' => $deviation, 'availableCapas' => $availableCapas ?? collect(), ]) {{-- ──────────────────────────────────────────────────────── Action Plan ──────────────────────────────────────────────────────── --}}
Action Plan
@if($deviation->actions->isEmpty())
No actions assigned.
@else
@foreach($deviation->actions as $action) @endforeach
Type Description Assigned Due Status Actions
{{ str_replace('_', ' ', $action->action_type) }} {{ Str::limit($action->action_description, 60) }} {{ $action->assignee?->name ?? '—' }} {{ $action->due_date?->format('M j, Y') }} @if($action->isOverdue()) Overdue @endif {{ $action->status }} @if($action->status === 'COMPLETED')
@csrf
@endif
@csrf @method('DELETE')
@endif
{{-- ============================================================ MODALS ============================================================ --}} {{-- Impact Modal --}} {{-- Impact Item Modal --}} @if($impact) @endif {{-- Link Existing CAPA Modal --}} @if(($availableCapas ?? collect())->isNotEmpty()) @endif {{-- Create New CAPA Modal --}} {{-- Add Action Modal --}}