@php $canEdit = false; $canEditDeclined = false; $lastReturnRemark = $lastReturnRemark ?? null; $workflowHistory = $workflowHistory ?? []; $departmentNames = ($departmentNames ?? null) instanceof \Illuminate\Support\Collection ? $departmentNames : collect(); $allSchemes = $plan->latestVersion?->schemes ?? collect(); $declinedSchemes = ($declinedSchemes ?? null) instanceof \Illuminate\Support\Collection ? $declinedSchemes : $allSchemes->filter(fn ($s) => filled($s->rd_rejected_at ?? null))->values(); $planMeta = $planMeta ?? [ 'region_label' => plan_region_label_for_plan($plan), 'created_by_display' => $plan->creator->name ?? '—', 'consolidated_by_label' => $plan->consolidatedSourcePlanIds() !== [] ? ($plan->creator->name ?? '—') : '—', 'plan_type_label' => match ($plan->plan_type ?? '') { 'RVP' => 'Regular Visit Plan (RVP)', 'CVP' => 'Compliance Visit Plan (CVP)', 'SVP' => 'Special Visit Plan (SVP)', 'DRP' => 'Desk Review Plan (DRP)', 'ERP' => 'Evaluation Plan (ERP)', 'PMP' => 'Project Monitoring Plan (PMP)', default => $plan->plan_type ?? 'Plan', }, ]; $periodLabel = \Carbon\Carbon::create()->month((int) $plan->month)->format('F').' '.$plan->year; $accordionDomId = 'reportPlanSchemesAccordion-'.$plan->id; $schemeNameColorClassByProjectId = is_array($schemeNameColorClassByProjectId ?? null) ? $schemeNameColorClassByProjectId : []; @endphp
{{ $planMeta['plan_type_label'] }} Plan ID: #{{ $plan->id }}
Visit Report Details
{{ $periodLabel }}
Created by {{ $planMeta['created_by_display'] }}
Consolidated by {{ $planMeta['consolidated_by_label'] }}
Division {{ $planMeta['region_label'] }}
Plan type {{ $plan->plan_type ?? '—' }}
@if($plan->status === 'rejected') @php $lastDeclineEntry = collect($workflowHistory)->where('action', 'rejected')->last(); $declineReason = $lastReturnRemark ?? ($lastDeclineEntry['remarks'] ?? ''); @endphp @elseif($plan->status === 'returned') @php $lastReturnEntry = collect($workflowHistory)->where('action', 'returned')->last(); $returnReason = $lastReturnRemark ?? ($lastReturnEntry['remarks'] ?? ''); $rdSchemeFlaggedCount = $declinedSchemes->count(); @endphp @endif @if(! empty($workflowHistory))
Plan History
    @foreach($workflowHistory as $idx => $entry) @php $actionLabel = match ($entry['action']) { 'submitted' => 'Submitted', 'forwarded' => 'Forwarded', 'returned' => 'Returned', 'approved' => 'Approved', 'rejected' => 'Declined', default => ucfirst($entry['action']), }; $timestamp = $entry['action_date']->format('d M Y').' • '.$entry['action_date']->format('H:i'); $isLast = $idx === count($workflowHistory) - 1; @endphp
  • {{ $actionLabel }}
    {{ $entry['routing_line'] ?? (($entry['from_user_label'] ?? $entry['from_user_name']).' → '.($entry['to_user_label'] ?? $entry['to_user_name'])) }}
    {{ $timestamp }}
    @if(filled($entry['remarks'] ?? null))
    Note: {!! nl2br(e((string) $entry['remarks'])) !!}
    @endif
  • @endforeach
@endif @php $planSchemesOrdered = $allSchemes->values(); @endphp
Plan schemes ({{ $planSchemesOrdered->count() }})
@if($planSchemesOrdered->isEmpty())

No schemes in this plan.

@else
@foreach($planSchemesOrdered as $idx => $scheme) @php $schemeNameToneClass = trim((string) ($schemeNameColorClassByProjectId[(int) ($scheme->scheme_id ?? 0)] ?? '')); $isDeclined = filled($scheme->rd_rejected_at ?? null); $p = $projectsMap->get($scheme->scheme_id); $schemeCode = $p ? ($p->code ?? '') : ''; $schemeName = $p ? ($p->name ?? '') : ''; $deptLabel = ($p && filled($p->department_id)) ? ($departmentNames->get((int) $p->department_id) ?? '—') : '—'; $visitTeamNames = $scheme->visitingTeams->map(fn ($t) => $t->user->name ?? '')->filter()->values()->implode(', '); $additionalDates = $scheme->dates->map(fn ($d) => $d->visit_date?->format('d-m-Y'))->filter()->values(); $physical = $scheme->physical_progress !== null ? (float) $scheme->physical_progress : null; $financial = $scheme->financial_progress !== null ? (float) $scheme->financial_progress : null; $effectiveMoId = $scheme->effectiveMonitoringOfficerUserId($plan); $monitoringOfficerDisplay = '—'; if ($effectiveMoId > 0) { if ((int) ($scheme->monitoring_officer_id ?? 0) > 0 && $scheme->monitoringOfficer) { $monitoringOfficerDisplay = $scheme->monitoringOfficer->name ?? '—'; } elseif ((int) ($plan->created_by ?? 0) === $effectiveMoId && $plan->creator) { $monitoringOfficerDisplay = $plan->creator->name ?? '—'; } else { $monitoringOfficerDisplay = optional(\App\Models\PC\User::find($effectiveMoId))->name ?? ('User #'.$effectiveMoId); } } $isFirst = $idx === 0; $collapseDomId = 'report-scheme-collapse-'.$plan->id.'-'.(int) ($scheme->id ?? 0).'-'.$idx; $headingDomId = 'report-scheme-heading-'.$plan->id.'-'.$idx; @endphp @if($isDeclined)
Declined Pending correction @if(filled($scheme->mo_assignment_banner ?? null)) MO reassigned @endif
Scheme {{ str_pad((string) ($idx + 1), 2, '0', STR_PAD_LEFT) }}
{{ $schemeCode ?: 'Scheme #'.($idx + 1) }}

{{ $schemeName }}

@if($p)
ADP # {{ ($adpLabel = \App\Support\MecReportAdpFiscalYear::displayForUnsavedPlan($plan ?? null, $p)) !== '' ? $adpLabel : '—' }}
UID {{ $schemeCode !== '' ? $schemeCode : '—' }}
Department {{ $deptLabel }}
@endif @if(filled($scheme->rd_rejection_remarks ?? null))

Reason: {{ \Illuminate\Support\Str::limit((string) $scheme->rd_rejection_remarks, 160) }}

@endif
@if(! $isFirst && ($physical !== null || $financial !== null)) @if($physical !== null){{ $physical }}% Physical @endif @if($physical !== null && $financial !== null) · @endif @if($financial !== null){{ $financial }}% Financial @endif @endif
@if(filled($scheme->rd_rejection_remarks ?? null))

RD note: {{ $scheme->rd_rejection_remarks }}

@endif

{{ $scheme->visit_location ?: '—' }}

{{ $monitoringOfficerDisplay }}

@if($scheme->visit_date)
Visit Date: {{ $scheme->visit_date->format('d M Y') }}
@endif
@else
Scheme {{ str_pad((string) ($idx + 1), 2, '0', STR_PAD_LEFT) }} @if(filled($scheme->mo_assignment_banner ?? null)) MO reassigned @endif
{{ $schemeCode ?: 'Scheme #'.($idx + 1) }}

{{ $schemeName }}

@if($p)
ADP # {{ ($adpLabel = \App\Support\MecReportAdpFiscalYear::displayForUnsavedPlan($plan ?? null, $p)) !== '' ? $adpLabel : '—' }}
UID {{ $schemeCode !== '' ? $schemeCode : '—' }}
Department {{ $deptLabel }}
@endif
@if(! $isFirst && ($physical !== null || $financial !== null)) @if($physical !== null){{ $physical }}% Physical @endif @if($physical !== null && $financial !== null) · @endif @if($financial !== null){{ $financial }}% Financial @endif @endif
@if($p && (filled($p->estimated_amount) || filled($p->approved_amount)))
@if(filled($p->estimated_amount))
Estimated amount {{ number_format((float) $p->estimated_amount, 2) }}
@endif @if(filled($p->approved_amount))
Approved amount {{ number_format((float) $p->approved_amount, 2) }}
@endif
@endif

{{ $scheme->visit_location ?: '—' }}

{{ $visitTeamNames ?: '—' }}

{{ $monitoringOfficerDisplay }}

@if($physical !== null || $financial !== null)
@if($physical !== null)
Physical {{ $physical }}%
@endif @if($financial !== null)
Financial {{ $financial }}%
@endif
@endif
@if($additionalDates->isNotEmpty())
@foreach($additionalDates as $dt)
{{ $dt }}
@endforeach
@endif
@if($scheme->visit_date)
Visit Date: {{ $scheme->visit_date->format('d M Y') }}
@endif
@endif @endforeach
@endif