@extends('layouts.app') @php use App\Services\ChangeControlService; 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; } }; $pendingInstance = $change->latestApprovalInstance(); $hasPending = $pendingInstance && in_array($pendingInstance->status, ['PENDING', 'IN_PROGRESS']); @endphp @section('title', $change->change_number . ' — ' . $change->title) @section('content')
{{-- Flash --}} @foreach(['success' => 'check-circle', 'warning' => 'exclamation-triangle', 'error' => 'exclamation-circle'] as $key => $icon) @if(session($key))
{{ session($key) }} @if($key === 'error' && session('missing'))
Missing prerequisites: @endif
@endif @endforeach {{-- Pending approval banner --}} @if($hasPending)
Awaiting Approval — Workflow #{{ $pendingInstance->instance_id }} is pending at step {{ $pendingInstance->current_step }}.
View Workflow
@endif {{-- Header --}}

{{ $change->change_type->label() }} {{ $change->change_number }}

{{ $change->title }}
Status: {{ $change->current_status->label() }}
Phase: {{ $change->current_phase->label() }}
Category: {{ $change->change_category->label() }}
Priority: {{ $change->priority }}
Owner: {{ $change->owner?->name ?? '—' }}
Department: {{ $change->department?->department_name ?? '—' }}
Initiated: {{ $fmtDate($change->initiated_date, 'M j, Y') }}
Target: {{ $fmtDate($change->target_implementation_date, 'M j, Y') }} @if($change->isOverdue()) Overdue @endif
@include('record-links._tab', ['record' => $change]) {{-- Status Transitions --}} @if(!empty($allowedStatuses))
Status Transitions
@if($change->change_category->requiresQualifiedPerson())
This is a CRITICAL change — Qualified Person approval is required.
@endif @if($hasPending)
You cannot transition while an approval is pending.
@endif @foreach($allowedStatuses as $status) @php $needsApproval = ChangeControlService::requiresApproval($change->current_status->value, $status); $docType = ChangeControlService::workflowTypeFor($change->current_status->value, $status); // Compute the approver list based on which workflow will actually run $approvers = []; if ($docType === 'APPROVAL' && $needsApproval) { if ($change->change_category->value === 'CRITICAL') { $approvers = [ RoleNames::QA_MANAGER, RoleNames::DEPARTMENT_HEAD, RoleNames::QUALIFIED_PERSON, ]; } else { $approvers = [ RoleNames::QA_MANAGER, RoleNames::DEPARTMENT_HEAD, ]; } } elseif ($docType && $needsApproval) { $approvers = ChangeControlService::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', default => ucwords(str_replace('_', ' ', $role)), }; }, $approvers)); @endphp @endforeach
@endif {{-- Tabs --}}
{{-- Overview --}}
Description

{!! nl2br(e($change->description)) !!}

Justification

{!! nl2br(e($change->justification)) !!}

@if($change->expected_benefits)
Expected Benefits

{!! nl2br(e($change->expected_benefits)) !!}

@endif @if($change->risks_if_not_implemented)
Risks if Not Implemented

{!! nl2br(e($change->risks_if_not_implemented)) !!}

@endif
{{-- Impact --}}
Impact Assessment
@if($change->impactAssessment) @php $ia = $change->impactAssessment; @endphp
Risk Level
{{ $ia->risk_level }}
RPN
{{ $ia->rpn ?? '—' }}
Assessed By
{{ $ia->assessor?->name ?? '—' }}
Approval Status
{{ $ia->approval_status }}
Summary

{!! nl2br(e($ia->summary)) !!}

Impact Data
@foreach(($ia->impact_data ?? []) as $key => $value) @endforeach
{{ Str::headline($key) }} @if(is_bool($value)) {{ $value ? 'Yes' : 'No' }} @elseif(is_array($value)) {{ implode(', ', $value) }} @else {{ $value ?: '—' }} @endif
@if($ia->mitigation_plan)
Mitigation Plan

{!! nl2br(e($ia->mitigation_plan)) !!}

@endif @else
No impact assessment recorded. This is required before the change can be approved.
@endif
{{-- Implementation Plan --}}
Implementation Plan
@if($change->implementationPlan->isEmpty())
No implementation steps defined. Add at least one before requesting implementation approval.
@else
@foreach($change->implementationPlan as $step) @endforeach
# Step Responsible Due Completed Status Actions
{{ $step->step_order }} {{ $step->step_title }} @if($step->step_description)
{{ Str::limit($step->step_description, 120) }} @endif
{{ $step->responsible?->name ?? '—' }} {{ $fmtDate($step->due_date, 'M j, Y') }} {{ $fmtDate($step->completed_date, 'M j, Y') }} {{ $step->status }} {{-- Quick status dropdown --}}
@csrf @method('PUT')
{{-- Full edit button --}} {{-- Delete button --}}
@csrf @method('DELETE')
@endif
{{-- Effectiveness --}}
Effectiveness Checks
@forelse($change->effectivenessChecks as $check)
{{ $check->conclusion }} Methodology: {{ Str::limit($check->methodology, 120) }} @if($check->results)

{!! nl2br(e($check->results)) !!}

@endif
@empty
No effectiveness check recorded. Required before the change can be closed.
@endforelse
{{-- Links --}} {{-- Audit --}}
@forelse($change->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 --}} {{-- Impact Assessment --}} {{-- Add Plan Step --}} {{-- ═══════════════════════════════════════════════════════════ EDIT IMPLEMENTATION STEP MODALS (one per row) ═══════════════════════════════════════════════════════════ --}} @foreach($change->implementationPlan as $step) @endforeach {{-- Effectiveness --}} {{-- Link --}} @endsection @push('scripts') @endpush