@extends('layouts.app') @section('title', 'Approval — ' . ($instance->record_title ?: '#' . $instance->instance_id)) @php /** * Defensive date formatter. * Accepts Carbon, string, or null; returns a formatted string or '—'. */ $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; } }; @endphp @section('content')
{{-- Flash messages --}} @if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif {{-- Header --}}

{{ $instance->record_title ?: 'Approval Request' }}

{{ $instance->record_number ?: '#' . $instance->record_id }} {{ $instance->record_type }}

{{ $instance->status }}
{{-- Navigation --}}
Back @if(in_array($instance->status, ['PENDING', 'IN_PROGRESS'], true)) Take Action @endif
{{-- Two-column layout --}}
{{-- LEFT: Record preview + Timeline --}}
{{-- Record preview --}} @if($record)
Record Preview
@if(view()->exists("workflows.approvals.previews.{$instance->record_type}")) @include("workflows.approvals.previews.{$instance->record_type}", [ 'record' => $record, 'instance' => $instance, ]) @else @foreach($record->getAttributes() as $key => $value) @endforeach
{{ Str::headline($key) }} @if(is_array($value) || is_object($value)) {{ json_encode($value) }} @else {{ Str::limit((string) $value, 200) }} @endif
@endif
@endif {{-- Approval Timeline --}}
Approval Timeline
@forelse($steps as $step) @php $stepAction = $stepActions[$step->step_id] ?? null; $isCurrent = $step->step_order == $instance->current_step && in_array($instance->status, ['PENDING', 'IN_PROGRESS'], true); $isPast = $step->step_order < $instance->current_step || $stepAction; // Defensive — action_date may be a string $actionDateFormatted = $stepAction ? $fmtDate($stepAction->action_date) : null; @endphp
Step {{ $step->step_order }}: {{ $step->step_name }} @if($stepAction) {{ $stepAction->action }} @endif
@if($step->approver_user_id) Assigned to user #{{ $step->approver_user_id }} @elseif($step->required_role) Required Role: {{ $step->required_role }} @endif
@if($stepAction)
{{ $stepAction->approver?->name ?? 'Unknown' }} — {{ $actionDateFormatted ?? '—' }}
@if($stepAction->comment)
{{ $stepAction->comment }}
@endif @if($stepAction->signature)
Signed: {{ $stepAction->signature }}
@endif
@endif
@empty

No workflow steps defined for this workflow.

@endforelse
{{-- RIGHT: Instance Details + All Actions --}}
{{-- Instance Details --}}
Instance Details
@if(!empty($instance->completed_at)) @endif
Workflow {{ $instance->workflow?->workflow_name ?? '—' }}
Code {{ $instance->workflow?->workflow_code ?? '—' }}
Module {{ $instance->record_type }}
Initiator {{ $instance->initiator?->name ?? '—' }}
Initiated {{ $fmtDate($instance->initiated_at) }}
Current Step Step {{ $instance->current_step }}
Completed {{ $fmtDate($instance->completed_at) }}
Decision By {{ $instance->finalDecisionBy?->name ?? '—' }}
{{-- All Actions --}}
All Actions
@forelse($actions as $action)
{{ $action->approver?->name ?? 'Unknown' }} {{ $action->action }}
{{ $action->step?->step_name ?? '—' }} — {{ $fmtDate($action->action_date) }} @if($action->comment)
{{ $action->comment }}
@endif
@empty
No actions yet.
@endforelse
@endsection