@extends('layouts.app') @php use App\Services\AuditService; use App\Support\RoleNames; $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; } }; $hasPending = false; $openFindings = $audit->openFindingsCount(); $majorNcCount = $audit->majorNcCount(); @endphp @section('title', $audit->audit_number . ' — ' . $audit->title) @section('content')
{{-- Flash --}} @foreach(['success' => 'check-circle', 'warning' => 'exclamation-triangle', 'error' => 'exclamation-circle'] as $key => $icon) @if(session($key))
{{ session($key) }}
@endif @endforeach {{-- Header --}}

{{ $audit->audit_type->label() }} {{ $audit->audit_number }}

{{ $audit->title }}
Status: {{ $audit->current_status->label() }}
Phase: {{ $audit->current_phase->label() }}
Category: {{ $audit->audit_category->label() }}
Priority: {{ $audit->priority }}
Lead Auditor: {{ $audit->leadAuditor?->name ?? '—' }}
Auditee: {{ $audit->auditee?->name ?? $audit->auditee_organisation ?? '—' }}
Department: {{ $audit->department?->department_name ?? '—' }}
Planned: {{ $fmtDate($audit->planned_start_date, 'M j') }} – {{ $fmtDate($audit->planned_end_date, 'M j, Y') }} @if($audit->isOverdue()) Overdue @endif
Open Findings: {{ $openFindings }}
Major NCs: {{ $majorNcCount }}
Total Findings: {{ $audit->findings->count() }}
Closed: {{ $fmtDate($audit->closed_date, 'M j, Y') }}
{{-- Status Transitions --}} @if(!empty($allowedStatuses))
Status Transitions
@if($majorNcCount > 0)
This audit has {{ $majorNcCount }} major nonconformity(ies) — Qualified Person approval is required for closure.
@endif @foreach($allowedStatuses as $status) @php $needsApproval = AuditService::requiresApproval($audit->current_status->value, $status); $docType = AuditService::workflowTypeFor($audit->current_status->value, $status); $approvers = []; if ($docType && $needsApproval) { $approvers = AuditService::approverRolesFor($docType, $majorNcCount > 0); } $approverLabel = empty($approvers) ? '—' : implode(' + ', array_map(function ($role) { return match($role) { 'qa_manager' => 'QA Manager', 'department_head' => 'Department Head', 'qualified_person' => 'Qualified Person', default => ucwords(str_replace('_', ' ', $role)), }; }, $approvers)); @endphp @endforeach
@endif @include('record-links._tab', ['record' => $audit]) {{-- Tabs --}}
{{-- Plan --}}
Scope

{!! nl2br(e($audit->scope)) !!}

@if($audit->objectives)
Objectives

{!! nl2br(e($audit->objectives)) !!}

@endif @if($audit->criteria)
Audit Criteria

{!! nl2br(e($audit->criteria)) !!}

@endif
Planned: {{ $fmtDate($audit->planned_start_date, 'M j, Y') }} – {{ $fmtDate($audit->planned_end_date, 'M j, Y') }}
Actual: {{ $fmtDate($audit->actual_start_date, 'M j, Y') }} – {{ $fmtDate($audit->actual_end_date, 'M j, Y') }}
{{-- Execution --}}
@if($audit->execution_summary || $audit->closing_meeting_notes || $audit->audit_report_summary) @if($audit->execution_summary)
Execution Summary

{!! nl2br(e($audit->execution_summary)) !!}

@endif @if($audit->closing_meeting_notes)
Closing Meeting Notes

{!! nl2br(e($audit->closing_meeting_notes)) !!}

@endif @if($audit->audit_report_summary)
Audit Report Summary

{!! nl2br(e($audit->audit_report_summary)) !!}

@endif @else
Execution details will appear here once the audit begins. Update via the Edit form.
@endif
{{-- Findings --}}
Audit Findings
@if($audit->findings->isEmpty())
No findings recorded yet.
@else
@foreach($audit->findings as $f) @endforeach
# Type Title Status CAPA Response Due Actions
{{ $f->finding_number }} {{ $f->finding_type->label() }}
{{ $f->severity->label() }}
{{ $f->title }} @if($f->clause_reference)
Ref: {{ $f->clause_reference }} @endif
{{ $f->status->label() }} @if($f->capa_id) CAPA #{{ $f->capa_id }} @elseif($f->requiresCapa()) Required @else @endif {{ $fmtDate($f->response_due_date, 'M j, Y') }} @if($f->isOverdueResponse())
Overdue @endif
@if(! $f->capa_id) @endif
@csrf @method('DELETE')
@endif
{{-- Links --}} {{-- Audit --}}
@forelse($audit->auditTrails as $t) @empty @endforelse
Date User Action Description
{{ $fmtDate($t->changed_at) }} {{ $t->user?->name ?? 'System' }} {{ $t->action_type }} {{ $t->action_description }}
No audit entries.
{{-- ═══════════════════════════════════════════════════════ MODALS ═══════════════════════════════════════════════════════ --}} {{-- Transition --}} {{-- Add Finding --}} {{-- Per-finding response + CAPA link modals --}} @foreach($audit->findings as $f) @if(! $f->capa_id) @endif @endforeach {{-- Link modal --}} @endsection @push('scripts') @endpush