@extends('layouts.app_layout') @section('content')
{{-- TABBED INTERFACE START --}}
{{---------------------------------------------------}} {{-- TAB 1: APPLICATION DETAILS (Status + Basic Centre Info + Address) --}} {{---------------------------------------------------}}
{{-- TAB HEADER --}}
Basic Training Centre Details
{{-- Use row and g-3 for consistent gap and alignment --}}
{{-- APPLICATION STATUS --}}
Application Status
@php $status = $centre->application_status ?? 'Not Started'; $statusUpper = strtoupper($status); $badgeClass = 'bg-secondary'; switch (strtolower($status)) { case 'approved': $badgeClass = 'bg-success'; break; case 'rejected': $badgeClass = 'bg-danger'; break; case 'in progress': $badgeClass = 'bg-primary'; break; case 'not started': default: $badgeClass = 'bg-warning text-dark'; break; } @endphp {{ $statusUpper }}
{{-- APPLICATION NUMBER --}}
Application Number

{{ $centre->application_number ?? '❌ Not Generated' }}

{{-- CENTRE NAME --}}
Centre Name

{{ $basicDetails->centre_name ?? '❌ Not Provided' }}

{{-- DIRECTOR NAME --}}
Director Name

{{ $basicDetails->director_name ?? '❌ Not Provided' }}

{{-- EMAIL --}}
Email

{{ $basicDetails->official_email ?? '❌ Not Provided' }}

{{-- PHONE --}}
Phone

{{ $basicDetails->primary_phone ?? '❌ Not Provided' }}

{{-- ESTABLISH YEAR --}}
Establish Year

{{ $basicDetails->establish_year ?? '❌ Not Provided' }}

{{-- WEBSITE --}}
Website

@if($basicDetails->website) {{ $basicDetails->website }} @else ❌ Not Provided @endif

{{-- ADDRESS LINE --}}
Address Line

{{ $address->address ?? '❌ Not Provided' }}

{{-- STATE --}}
State

{{ $address->stateMapped->state_name_en ?? '❌ Not Provided' }}

{{-- DISTRICT --}}
District

{{ $address->districtMapped->district_name_en ?? '❌ Not Provided' }}

{{-- CITY --}}
City

{{ $address->city ?? '❌ Not Provided' }}

{{-- PINCODE --}}
PinCode

{{ $address->pincode ?? '❌ Not Provided' }}

{{-- LANDMARK --}}
Landmark

{{ $address->landmark ?? '❌ Not Provided' }}

{{-- GPS COORDINATES --}}
GPS Coordinates

Lat: {{ $address->latitude ?? '❌ N/A' }}
Long: {{ $address->longitude ?? '❌ N/A' }}

@if ($address->latitude && $address->longitude) @endif
{{-- MAP MODAL --}} @if ($address->latitude && $address->longitude) @else
Map not available: Latitude and/or Longitude coordinates are missing.
@endif
{{-- END ROW --}}
{{-- END CARD BODY --}} {{-- NAVIGATION BUTTON --}}
{{---------------------------------------------------}} {{-- TAB 2: TRAINER INFORMATION --}} {{---------------------------------------------------}}
Trainer Information
{{-- Your main content goes here (trainer list, etc.) --}}
@if ($trainers->count() > 0) @foreach ($trainers as $trainer)
{{-- Main details --}}
{{ $trainer->name ?? 'Not Specified' }}

Date of Birth: {{ $trainer->dob ? \Carbon\Carbon::parse($trainer->dob)->format('d M Y') : 'N/A' }}

Education: {{ $trainer->higher_qualification ?? 'N/A' }}

Experience: {{ $trainer->experience ? $trainer->experience . ' years' : 'N/A' }}

{{-- Document Links - UPDATED CONTAINER --}}
{{-- Education Certificate --}} @if ($trainer->higher_qualification_certificate) Education Certificate @endif {{-- Experience Letter --}} @if ($trainer->experience_certificate) Experience Letter @endif {{-- NISD Certificate --}} {{-- TOT Certificate --}} @if ($trainer->nisd_tot_certificate) NISD TOT Master Trainer Certificate @endif {{-- TOA Certificate (Optional) --}} @if ($trainer->toa_certificate) NISD TOA Certificate @endif {{-- Show message if no documents are uploaded --}} @if ( !($trainer->higher_qualification_certificate || $trainer->experience_certificate || $trainer->nisd_certificate || $trainer->tot_certificate || $trainer->toa_certificate) ) No documents uploaded. @endif
@endforeach @else {{-- Message when no trainers found --}}

No trainers have been added yet.

@endif
{{-- NAVIGATION BUTTONS --}}
{{---------------------------------------------------}} {{-- TAB 3: INFRASTRUCTURE --}} {{---------------------------------------------------}}
{{-- Header --}}
Infrastructure Details
{{-- Symmetric grid layout --}} {{-- Total Area --}}
Total Area

{{ $infrastructure->total_area ?? '❌ Not Provided' }} sq ft

{{-- Classrooms --}}
Classrooms

{{ $infrastructure->classrooms ?? '❌ Not Provided' }}

{{-- Classroom Size Confirmation --}}
Classroom Size Confirmed

{{ $infrastructure->classroom_size_confirmation ?? '❌ Not Confirmed' }}

{{-- Demonstration Labs --}}
Demonstration Labs

{{ $infrastructure->number_of_laboratories ?? '❌ Not Provided' }}

{{-- Laboratory Size Confirmation --}}
Demonstration Lab Size Confirmed

{{ $infrastructure->laboratory_size_confirmation ?? '❌ Not Confirmed' }}

{{-- Facilities (Full Width) --}}
Facilities
@if(!empty($facilityList))

{{ $facilityList }}

@else

❌ Not Provided

@endif
{{-- NAVIGATION BUTTONS --}}
{{---------------------------------------------------}} {{-- TAB 4: TRAINING PROGRAMS --}} {{---------------------------------------------------}}
{{-- Header --}}
Training Program(s) Offered
@if($selectedPrograms->count() > 0) @foreach($selectedPrograms as $program)
{{ $program->title ?? 'N/A' }}

Duration: {{ $program->total_hours ?? 'N/A' }} hrs

Type: {{ $program->course_type_desc ?? 'N/A' }}

@endforeach @else
@endif
{{-- NAVIGATION BUTTONS --}}
{{---------------------------------------------------}} {{-- TAB 5: PAYMENT DETAILS --}} {{---------------------------------------------------}} @php $allowedPaymentStatuses = ['PAYMENT_SUBMITTED', 'PAYMENT_RECEIVED']; @endphp @if(isset($centre) && in_array(strtoupper($centre->application_status), $allowedPaymentStatuses))
{{-- Header --}}
Payment Details
@if($payment)
{{-- Payment Mode --}}
Payment Mode

{{ $payment->payment_mode ?? 'N/A' }}

{{-- Transaction ID --}}
Transaction ID

{{ $payment->transaction_id ?? 'N/A' }}

{{-- Transaction Date --}}
Transaction Date

{{ $payment->transaction_date ? \Carbon\Carbon::parse($payment->transaction_date)->format('d M Y') : 'N/A' }}

{{-- Amount --}}
Amount (INR)

{{ $payment->amount ?? 'N/A' }}

{{-- Transaction Details --}}
Transaction Details

{{ $payment->transaction_details ?? '-' }}

{{-- Receipt --}}
Receipt
@if($payment->receipt_path) View Receipt @else No receipt uploaded. @endif
@else @endif
{{-- NAVIGATION --}}
@endif {{-- TAB 6: Documents (PREVIOUS only) --}}
{{-- Header --}}
Documents & Declarations
{{-- Body --}}
{{-- Uploaded Documents Section --}}
Uploaded Documents
@foreach($uploadedFiles as $label => $files)
{{ $label }}

{{ count($files) }} {{ Str::plural('file', count($files)) }}

@forelse($files as $file) @empty No file @endforelse
@endforeach

{{-- Declarations Section --}} @php $declarationLabels = [ 'agree_terms' => 'I agree to the Terms and Conditions and Privacy Policy', 'agree_inspection' => 'I agree to facility inspection by NISD officials', 'declare_info' => 'I declare that all information provided is accurate and complete', ]; @endphp

Declarations

Declarations confirmed for this application:
@foreach($declarations as $key => $value)
@endforeach
{{-- NAVIGATION BUTTONS --}}
{{-- TAB 7: Action Tab --}}
@php $isLorGenerated = isset($centre) && $centre->application_status === 'LOR_GENERATED'; $currentList = $isLorGenerated ? ($inspectionList ?? []) : ($scrutinyList ?? []); $headingText = $isLorGenerated ? 'Inspection Checklist' : 'Scrutiny Checklist'; $isScrutinyPending = isset($centre) && in_array($centre->application_status, ['PENDING','DISCREPANCY_REMOVED']); $isScrutinyCompleted = isset($centre) && in_array($centre->application_status, ['DISCREPANCY_FOUND','LOR_GENERATED']); @endphp
{{-- LEFT COLUMN --}}
{{-- TIMELINE --}}

@if(!empty($timeline) && $timeline->isNotEmpty())
    @foreach($timeline as $step)
  • {{ $step->status ?? 'Status Updated' }}
    {{ $step->status_changed_on ? \Carbon\Carbon::parse($step->status_changed_on)->format('d M Y, h:i A') : 'N/A' }}

    {{$step->user->name ?? 'System' }}

    @if(!empty($step->remarks)) @php $decodedRemarks = json_decode($step->remarks, true); @endphp
    @if(is_array($decodedRemarks))
      @foreach($decodedRemarks as $remark)
    • {{ $remark['item_name'] ?? 'N/A' }}: {!! nl2br(e($remark['remarks'] ?? '-')) !!}
    • @endforeach
    @else {!! nl2br(e($step->remarks)) !!} @endif
    @endif
  • @endforeach
@else

No timeline data available for this application.

@endif
{{-- SCRUTINY --}} @php use Illuminate\Support\Str; @endphp {{-- Make sure Str is available --}} {{-- Force accordion to be closed by default --}} @php // Previously: $shouldBeOpen = $isScrutinyPending; $shouldBeOpen = false; @endphp

{{-- ========== PENDING STATE: SHOW ONLY IF ACTION IS PENDING ========== --}} @if($isScrutinyPending) @php $currentList = $scrutinyList ?? collect(); $previousData = $scrutinyHistory->mapWithKeys(fn($record) => [ $record->scrutinyList->id => [ 'remarks' => $record->remarks, 'status' => $record->discrepancy_removed ? 'no' : 'yes', ] ]); @endphp @if($currentList->isEmpty())
No checklist items available for scrutiny.
@else
Pending Scrutiny
@csrf @foreach($currentList as $list) @php $listId = $list->id; // 1. **FIX: Sanitize the list name for reliable form field names** $baseName = Str::slug($list->name, '_'); $savedStatus = $previousData[$listId]['status'] ?? null; $savedRemarks = $previousData[$listId]['remarks'] ?? ''; $iconClass = match($savedStatus) { 'yes' => 'text-danger fas fa-exclamation-triangle', 'no' => 'text-success fas fa-check-circle', default => 'text-muted far fa-square', }; @endphp
{{ $list->name }}
{{-- YES --}} {{-- NO --}}
@endforeach
@endif @endif {{-- Horizontal line to separate PENDING from HISTORY --}} @if($isScrutinyPending && $scrutinyHistory->isNotEmpty())
@endif {{-- ========== COMPLETED STATE: SHOW ALWAYS IF HISTORY EXISTS ========== --}} @if($scrutinyHistory->isNotEmpty())
Scrutiny History @if($isScrutinyCompleted) Completed @endif
{{-- Full Scrutiny History Table --}}
All Scrutiny Records
{{-- Changed label for clarity --}} @foreach($scrutinyHistory as $index => $record) @endforeach
# Scrutiny Item Remarks Scrutiny Date Discrepancy Exists?
{{ $index + 1 }} {{ $record->scrutinyList->name ?? 'N/A' }} {{ $record->remarks ?? '-' }} {{ \Carbon\Carbon::parse($record->scrutiny_date)->format('d M Y') }} {{-- Note: 'discrepancy_removed' TRUE means NO Discrepancy Exists --}} @if(!$record->discrepancy_removed) Yes @else No @endif
{{-- Previous Discrepancy Records (Items that HAD a discrepancy) --}} @php // Filter for records that *had* a discrepancy (discrepancy_removed is FALSE) $previousScrutinies = $scrutinyHistory->where('discrepancy_removed', false); @endphp @if($previousScrutinies->isNotEmpty())
Records with Discrepancy
@foreach($previousScrutinies as $i => $item) @endforeach
# Scrutiny Item Remarks Date
{{ $i + 1 }} {{ $item->scrutinyList->name ?? 'N/A' }} {{ $item->remarks ?? '-' }} {{ \Carbon\Carbon::parse($item->scrutiny_date)->format('d M Y') }}
@endif
@elseif(!$isScrutinyPending)

No scrutiny history found and no pending scrutiny items.

@endif
{{-- SHOW PAYMENT ACCORDION ONLY IF STATUS IS: PAYMENT_SUBMITTED OR PAYMENT_RECEIVED --}} @if(isset($centre) && in_array(strtoupper($centre->application_status), ['PAYMENT_SUBMITTED', 'PAYMENT_RECEIVED']))

{{-- Payment Info --}}
Payment Status:
{{ $centre->application_status ?? 'Not Received' }}
Received Date:
{{ ($payment && $payment->updated_at) ? \Carbon\Carbon::parse($payment->updated_at)->format('d M Y, h:i A') : '-' }}
{{-- SHOW UPDATE BUTTON ONLY IF STATUS IS PAYMENT_SUBMITTED --}} @if(strtoupper($centre->application_status) === 'PAYMENT_SUBMITTED') @endif
@endif {{-- CANVAS FOR UPDATE --}}
Update Payment Status
@csrf {{-- Status Dropdown --}}
{{-- Remarks --}}
{{-- ✅ SHOW ACCORDION IF STATUS = LOR_GENERATED --}} @if(isset($centre) && $centre->application_status === 'PAYMENT_RECEIVED')
{{-- ✅ ONE ACCORDION HEADER ONLY --}}

{{-- ✅ MAIN COLLAPSE --}}
{{-- ✅ IF ANY INSPECTIONS EXIST --}} @if($inspections->isNotEmpty()) @foreach($inspections as $index => $inspection) @php $status = strtolower($inspection->overall_status ?? ''); $badgeClass = match($status) { 'approved' => 'bg-success', 'rejected' => 'bg-danger', 'pending', 'under review' => 'bg-warning text-dark', default => 'bg-info', }; $doneOn = $inspection->inspection_date ? \Carbon\Carbon::parse($inspection->inspection_date)->format('d-m-Y') : 'Not Available'; $doneBy = $inspection->inspector_name ?? 'Not Available'; @endphp {{-- ✅ INSPECTION ROW --}}
Inspection: {{ $index + 1 }}

Done on: {{ $doneOn }}

Status: {{ $inspection->overall_status }}

Done By: {{ $doneBy }}

{{-- ✅ VIEW DETAILS BUTTON --}} View Details
@endforeach @else {{-- ✅ NO INSPECTIONS YET --}}
No inspections done so far.
@endif {{-- ✅ ALWAYS SHOW START NEW INSPECTION BUTTON INSIDE SAME ACCORDION --}}
@endif
{{-- RIGHT COLUMN --}}
Department Noting & File Movement
{{-- NOTES HISTORY --}}
Noting History
@php $currentDate = null; @endphp @foreach($notifications as $note) @php // Chat alignment logic $isSender = ($note->sendBy->id == auth()->id()); // Extract date only $messageDate = $note->created_at->format('Y-m-d'); @endphp {{-- DATE SEPARATOR --}} @if($currentDate !== $messageDate) @php $currentDate = $messageDate; @endphp
{{ $note->created_at->format('d F Y') ?? "N/A" }}
@endif {{-- RECEIVED (LEFT) --}} @if(!$isSender)
{{ $note->sendBy->name }}

{{ $note->message }}

{{ $note->created_at->format('h:i A') ?? "N/A" }}
{{-- SENT (RIGHT) --}} @else
You {{ $note->sendTo->name }}

{{ $note->message }}

{{ $note->created_at->format('h:i A') ?? "N/A" }}
@endif @endforeach
{{-- NAVIGATION BUTTON --}}
@if ($userAssigned->count() == 0) @endif @if ($userAssigned != null) @endif
{{-- TABBED INTERFACE END --}}
@endsection @section('pages-scripts') @yield('assignto-offcanvas-script') @yield('send-noting-offcanvas-script') @endsection