@extends('layouts.app') @section('title', 'PCFMS → PMS Initialization') @push('stylesheets') @endpush @section('contents') @php $decision = $detail['decision'] ?? [ 'status' => 'manual_review_required', 'label' => 'MANUAL REVIEW REQUIRED', 'reason' => '', 'meaning' => '', 'banner' => null, ]; $statusKey = (string) ($decision['status'] ?? ''); $canInit = (bool) ($detail['can_initialize'] ?? false); $pms = $detail['pms'] ?? null; $h = $detail['pcfms_history'] ?? null; $sel = $detail['selected_pc1'] ?? null; @endphp
@if (session('error'))
{{ session('error') }}
@endif @if (session('success'))
{{ session('success') }} @if (session('pc_form_open_url')) @endif
@endif {{-- Decision banner --}}
@if (!empty($decision['banner']))
{{ $decision['banner'] }}
@else
{{ $decision['label'] ?? '' }}
@endif

{{ $decision['meaning'] ?? '' }}

@if ($pms)

Open existing PMS PC form #{{ $pms['pc_form_id'] }}

@endif
{{-- 1. Scheme --}}

1. Scheme

Scheme Name
{{ $detail['scheme_name'] }}
ADP Number
{{ $detail['adp_number'] !== '' ? $detail['adp_number'] : '—' }}
UID
{{ $detail['sc_uid'] }}
BMS Project ID
{{ $detail['bms_project_id'] }}
{{-- 2. Current PMS Status --}}

2. Current PMS Status

{{ $decision['label'] ?? '' }}
@if ($pms)
PMS PC Form
#{{ $pms['pc_form_id'] }} @if ($pms['pc_uid'] !== '') ({{ $pms['pc_uid'] }}) @endif
PMS PC Type
{{ $pms['kind_label'] }}
PMS Status
{{ $pms['state_label'] ?? $pms['state'] }}
PMS Workflow Stage
{{ $pms['workflow_stage'] !== '' ? $pms['workflow_stage'] : '—' }}
Current Actor
@if (($pms['current_actor_id'] ?? 0) > 0) {{ $pms['current_actor_name'] !== '' ? $pms['current_actor_name'] : 'User #'.$pms['current_actor_id'] }} @else — @endif
Last PMS Activity
{{ !empty($pms['last_activity']) ? $pms['last_activity'] : '—' }}
Last PMS Activity Date
{{ !empty($pms['last_activity_at']) ? $pms['last_activity_at'] : '—' }}
@else

No PMS PC form exists yet for this scheme.

@endif
{{-- 3. PCFMS Historical Status --}}

Historical evidence only 3. PCFMS Historical Status

@if (count($detail['pc1_records']) > 1)

Multiple PCFMS PC records — select the record whose history should be considered:

@foreach ($detail['pc1_records'] as $row) @endforeach
PC1ID Version Status Entry Date New/Revised Active Version
{{ $row['pc1_id'] }} {{ $row['version'] }} {{ $row['status'] !== '' ? $row['status'] : '—' }} {{ $row['entry_date'] !== '' ? $row['entry_date'] : '—' }} {{ $row['revision_indicator'] }} @if ($row['is_active_version']) Yes @else No @endif
@elseif (count($detail['pc1_records']) === 1) @php $only = $detail['pc1_records'][0]; @endphp

Single PCFMS PC record: PC1 #{{ $only['pc1_id'] }} (Version {{ $only['version'] }})

@endif @if ($sel && $h)
Selected PCFMS PC
PC1 #{{ $sel['pc1_id'] }}
PCFMS Status
{{ $h['latest_status'] !== '' ? $h['latest_status'] : '—' }}
PCFMS PC Type
{{ $h['pc_type'] ?? ($sel['is_pc2'] ? 'PC-II' : 'PC-I') }}
Version
{{ $h['version'] ?? $sel['version'] }}
Entry Date
{{ ($h['entry_date'] ?? $sel['entry_date']) !== '' ? ($h['entry_date'] ?? $sel['entry_date']) : '—' }}
Workflow history (chronological)
@if (!empty($h['timeline']))
@foreach ($h['timeline'] as $ev) @php $sys = strtoupper((string) ($ev['system'] ?? 'PCFMS')); $userSys = strtoupper((string) ($ev['user_system'] ?? $sys)); $userName = trim((string) ($ev['user'] ?? '')); @endphp @endforeach
System Date Action User State Decision Meeting
@if ($sys === 'PMS') PMS @else PCFMS @endif {{ $ev['date'] !== '' ? \Illuminate\Support\Str::limit($ev['date'], 16, '') : '—' }} {{ $ev['action'] !== '' ? $ev['action'] : '—' }} @if ($userName !== '') {{ $userSys }} {{ $userName }} @else @endif {{ $ev['state'] !== '' ? $ev['state'] : '—' }} {{ $ev['decision'] !== '' ? $ev['decision'] : '—' }} {{ $ev['meeting'] !== '' ? $ev['meeting'] : '—' }}
@else

No PCFMS or PMS workflow history stored for this record.

@endif

Each row is labeled PCFMS or PMS. Users are shown from that system’s stored records. Historical evidence only — does not overwrite PMS status.

@elseif (count($detail['pc1_records']) > 1)

Select a PCFMS PC record above to view its historical summary.

@else

No PCFMS PC record available.

@endif
{{-- 4. What does this mean? --}}

4. What does this mean?

{{ $decision['meaning'] ?? '' }}

{{-- 5. What will happen? --}}

5. What will happen?

If you initialize this record:

  • PCFMS data will not be changed.
  • BMS data will not be changed.
  • PMS will create/initialize the workflow using the existing PMS workflow mechanism.
  • The selected PMS actor will receive the workflow according to existing PMS permissions.
  • The PMS workflow will determine the resulting stage.
  • The administrator cannot bypass the workflow.
{{-- 6. Initialization eligibility --}} @php $suggested = $detail['suggested_actors'] ?? ['items' => [], 'label' => '', 'note' => '']; $suggestedLabel = trim((string) ($suggested['label'] ?? '')); @endphp

6. Initialization Eligibility

Initialization Status

{{ $decision['label'] ?? '' }}

Reason: {{ $decision['reason'] ?? '' }}

@if (count($detail['blockers']) > 0 && $statusKey !== 'ready')
    @foreach ($detail['blockers'] as $blocker)
  • {{ $blocker }}
  • @endforeach
@endif

Suggested Eligible PMS Actor (PCFMS flow)

@if (!empty($suggested['next_hop_label']))

Next PMS hop: {{ $suggested['next_hop_label'] }}

@endif @if ($suggestedLabel !== '')

{{ $suggestedLabel }}

{{ $suggested['note'] ?? '' }} Format: Name - Permission.

@elseif ($canInit)

No eligible PMS actors found for the inferred next hop / scheme department.

@else

Actor suggestion is shown only when initialization is ready.

@endif
{{-- Safe repair / rollback (early mistaken workflow only) --}} @php $rollback = $detail['rollback'] ?? ['allowed' => false]; @endphp @if (!empty($rollback['allowed']))

Safe repair — Roll back early PMS workflow

Use this only to undo early mistaken PMS activity (wrong actor / failed init / legacy reconciliation) and restore a shell so initialization can be retried.

PMS PC Form
@if (!empty($detail['pms']['show_url'])) #{{ $rollback['pc_form_id'] }} @else #{{ $rollback['pc_form_id'] }} @endif
Current actor
{{ $rollback['current_actor_name'] !== '' ? $rollback['current_actor_name'] : '—' }}
Stage / state
{{ $rollback['workflow_stage'] }} / {{ $rollback['state'] !== '' ? $rollback['state'] : '—' }}
Forwards / reviews
{{ $rollback['forward_count'] }} / {{ $rollback['review_count'] }}
This will:
  • Remove early PMS forward trail rows (snapshot saved for audit).
  • Clear current actor and workflow stage (back to shell).
  • Clear any PCFMS→PMS initialization audit for this UID/form.
  • Not change PCFMS or BMS.
  • Not delete the PMS PC form shell.
@csrf
@elseif (!empty($rollback['pc_form_id']) && !($detail['can_initialize'] ?? false) && !empty($rollback['reasons']))

Safe repair — Rollback not available

Early rollback is blocked for this PMS form:

    @foreach ($rollback['reasons'] as $r)
  • {{ $r }}
  • @endforeach
@endif {{-- 8–10. Actor / resolve / confirm — only when READY --}} @if ($canInit)

8. Eligible PMS Actor

@csrf
Format: Name — Permission — Designation — Email. @if (!empty($detail['next_hop']['next_hop_label'])) Filtered to {{ $detail['next_hop']['next_hop_label'] }} from latest PCFMS action @if (!empty($detail['next_hop']['pcfms_action'])) {{ $detail['next_hop']['pcfms_action'] }} @endif @if (!empty($detail['scheme_department_name'])) in {{ $detail['scheme_department_name'] }} @endif. @elseif (!empty($detail['scheme_department_name'])) Limited to {{ $detail['scheme_department_name'] }}. @endif Use the search box to filter. Arbitrary users cannot be selected.
@endif @if ($canInit && $preview)

9. Resolved Stage

Selected Actor
{{ $preview['actor']['name'] }}
Permission
{{ $preview['actor']['permission'] ?? '—' }}
Department
{{ $preview['actor']['department'] !== '' ? $preview['actor']['department'] : '—' }}
Role
{{ $preview['actor']['role'] !== '' ? $preview['actor']['role'] : ($preview['actor']['designation'] ?: '—') }}
Resolved PMS Stage
{{ $preview['resolved_stage'] }} (not editable)
Allowed Actions
{{ implode(', ', $preview['allowed_actions']) }}

10. Final Confirmation

You are about to initialize this PMS workflow.

Scheme
{{ $detail['scheme_name'] }}
UID
{{ $detail['sc_uid'] }}
BMS Project
#{{ $detail['bms_project_id'] }}
Selected PCFMS PC
PC1 #{{ $sel['pc1_id'] }} — {{ $sel['revision_indicator'] }} — {{ $sel['status'] }}
PCFMS historical status
{{ $preview['pcfms_historical_status'] !== '' ? $preview['pcfms_historical_status'] : '—' }}
Selected PMS actor
{{ $preview['actor']['name'] }}
Resolved PMS stage
{{ $preview['resolved_stage'] }}
What will NOT happen:
  • PCFMS will not be changed.
  • BMS will not be changed.
  • Existing PMS workflow will not be overwritten.
  • No workflow stage will be bypassed.
@csrf
Cancel
@endif
@endsection @push('scripts') {{-- Select2 is only auto-loaded on csr-costing routes; load it here for searchable actor picker. --}} @endpush