@extends('layouts.app') @php use App\Services\CapaLifecycleService; /** * Defensive date formatter (accepts Carbon, string, or null). */ $fmtDate = function ($value, string $format = 'M j, Y H:i') { if (empty($value)) return '—'; try { return \Illuminate\Support\Carbon::parse($value)->format($format); } catch (\Throwable $e) { return (string) $value; } }; $pendingInstance = $capa->latestApprovalInstance(); $hasPending = $pendingInstance && in_array($pendingInstance->status, ['PENDING', 'IN_PROGRESS'], true); @endphp @section('title', $capa->capa_number . ' — ' . $capa->title) @section('content')
{{-- ═══════════════════════════════════════════════════════════ FLASH MESSAGES ═══════════════════════════════════════════════════════════ --}} @if(session('success'))
{{ session('success') }}
@endif @if(session('warning'))
{{ session('warning') }}
@endif @if(session('error'))
{{ session('error') }} @if(session('missing') && count(session('missing')))
Missing prerequisites: @endif
@endif @include('record-links._tab', ['record' => $capa]) {{-- ═══════════════════════════════════════════════════════════ PENDING APPROVAL BANNER ═══════════════════════════════════════════════════════════ --}} @if($hasPending)
Awaiting Approval — Workflow #{{ $pendingInstance->instance_id }} is pending at step {{ $pendingInstance->current_step }}. @if($pendingInstance->workflow) {{ $pendingInstance->workflow->workflow_name }} @endif
View Workflow
@endif {{-- ═══════════════════════════════════════════════════════════ HEADER ═══════════════════════════════════════════════════════════ --}}

{{ $capa->capa_type }} {{ $capa->capa_number }}

{{ $capa->title }}
Status: {{ str_replace('_', ' ', $capa->status) }}
Priority: {{ $capa->priority }}
Owner: {{ $capa->owner?->name ?? '—' }}
Target: {{ $fmtDate($capa->target_completion_date, 'M j, Y') }} @if($capa->isOverdue()) Overdue @endif
{{ $progress }}%
{{-- ═══════════════════════════════════════════════════════════ STATUS TRANSITIONS (approval-aware) ═══════════════════════════════════════════════════════════ --}} @if(!empty($allowedStatuses))
Status Transitions
{{-- Guidance based on priority --}} @if($capa->priority === 'CRITICAL')
This is a CRITICAL CAPA. It requires Department Head sign-off at Initiation and both QA Manager + Department Head at Approval.
@elseif($capa->priority === 'HIGH')
This is a HIGH priority CAPA. It requires Department Head sign-off at Initiation and both QA Manager + Department Head at Approval.
@endif @if($hasPending)
You cannot transition this CAPA while an approval is pending. Complete or cancel the current workflow first.
@endif {{-- Buttons --}} @foreach($allowedStatuses as $status) @php $needsApproval = CapaLifecycleService::requiresApproval( $capa, $capa->status, $status ); $docType = CapaLifecycleService::workflowTypeFor($capa->status, $status); $approvers = $docType ? CapaLifecycleService::approverRolesFor($docType) : []; $approverLabel = empty($approvers) ? '—' : implode(' + ', array_map(function ($role) { return match($role) { 'qa_manager' => 'QA Manager', 'department_head' => 'Department Head', 'qualified_person' => 'Qualified Person', 'sme' => 'SME', 'production_supervisor' => 'Production Supervisor', default => ucwords(str_replace('_', ' ', $role)), }; }, $approvers)); @endphp @endforeach
@endif {{-- ═══════════════════════════════════════════════════════════ TABS ═══════════════════════════════════════════════════════════ --}}
{{-- ═════════ OVERVIEW ═════════ --}}
Problem Statement

{{ $capa->problem_statement }}

{{-- Root Cause --}}
Root Cause
@if($capa->root_cause_summary)

{{ $capa->root_cause_summary }}

@if($capa->root_cause_method) Method / Source: {{ str_replace('_', ' ', $capa->root_cause_method) }} @endif @else
No root cause summary on file. To proceed to Action Planning, you can either:
  1. Fill in a Root Cause Summary here (for CAPAs where the cause is already known — audit findings, regulatory notices, supplier NCRs, customer complaints with identified cause).
  2. Add a full Investigation from the Investigation tab.
@endif
{{-- ═════════ INVESTIGATION ═════════ --}}
Investigations Optional
Investigations are optional. If the root cause is already known (e.g. from an audit finding or supplier NCR), use the Root Cause card on the Overview tab instead.
@forelse($capa->investigations as $inv)
{{ str_replace('_', ' ', $inv->methodology) }} {{ $inv->status }}

{{ Str::limit($inv->investigation_scope, 250) }}

@empty

No investigations recorded.

@endforelse
{{-- ═════════ ACTIONS ═════════ --}}
Action Plan
@forelse($capa->actions as $a) @empty @endforelse
Type Description Responsible Due Status Actions
{{ $a->action_type }} {{ Str::limit($a->action_description, 60) }} {{ $a->responsible?->name ?? '—' }} {{ $fmtDate($a->due_date, 'M j, Y') }} @if($a->isOverdue()) Overdue @endif {{ $a->status }}
@csrf @method('DELETE')
No actions recorded.
{{-- ═════════ EFFECTIVENESS ═════════ --}}
Effectiveness Checks
@forelse($capa->effectiveness as $eff)
{{ $eff->conclusion }} Monitoring: {{ $eff->monitoring_period }}

{{ Str::limit($eff->results, 250) }}

@empty

No effectiveness checks recorded.

@endforelse
{{-- ═════════ DOCUMENTS ═════════ --}}
Documents
@forelse($capa->documents as $doc)
{{ $doc->file_name }} {{ $doc->document_type }}
@csrf @method('DELETE')
@empty

No documents uploaded.

@endforelse
{{-- ═════════ EXTENSIONS ═════════ --}}
Extensions
@forelse($capa->extensions as $ext)
{{ $fmtDate($ext->original_due_date, 'M j, Y') }} {{ $fmtDate($ext->new_due_date, 'M j, Y') }} {{ $ext->approval_status }}
@if($ext->approval_status === 'Pending')
@csrf
@csrf
@endif
@empty

No extensions requested.

@endforelse
{{-- ═════════ AUDIT ═════════ --}}
@forelse($capa->auditTrails as $t) @empty @endforelse
Date User Action Description
{{ $fmtDate($t->changed_at, 'M j, Y H:i') }} {{ $t->user?->name ?? 'System' }} {{ $t->action_type }} {{ $t->action_description }}
No audit entries.
{{-- ═══════════════════════════════════════════════════════════ EDIT ACTION MODALS (one per row) ═══════════════════════════════════════════════════════════ --}} @foreach($capa->actions as $action) @endforeach {{-- ═══════════════════════════════════════════════════════════ ROOT CAUSE MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ TRANSITION MODAL (approval-aware) ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ INVESTIGATION MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ CREATE ACTION MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ EFFECTIVENESS MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ DOCUMENT MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ EXTENSION MODAL ═══════════════════════════════════════════════════════════ --}} {{-- ═══════════════════════════════════════════════════════════ CLOSURE MODAL ═══════════════════════════════════════════════════════════ --}} @if(in_array('CLOSED', $allowedStatuses)) @endif {{-- ═══════════════════════════════════════════════════════════ INLINE JS ═══════════════════════════════════════════════════════════ --}} @push('scripts') @endpush @endsection