@extends('staff.layouts.app')
@section('content')
@php
$status = strtolower($app->status ?? 'submitted');
$type = strtolower($app->application_type ?? 'document');
$isLeave = $type === 'leave';
$isDocument = $type === 'document';
$statusConfig = [
'submitted' => ['label' => 'Submitted', 'icon' => 'fa-paper-plane', 'dot' => 'bg-slate-500', 'bg' => 'bg-slate-50', 'text' => 'text-slate-700', 'border' => 'border-slate-200'],
'viewed' => ['label' => 'Under Review', 'icon' => 'fa-eye', 'dot' => 'bg-blue-500', 'bg' => 'bg-blue-50', 'text' => 'text-blue-700', 'border' => 'border-blue-200'],
'approved' => ['label' => 'Approved', 'icon' => 'fa-circle-check', 'dot' => 'bg-emerald-500', 'bg' => 'bg-emerald-50', 'text' => 'text-emerald-700', 'border' => 'border-emerald-200'],
'rejected' => ['label' => 'Rejected', 'icon' => 'fa-circle-xmark', 'dot' => 'bg-red-500', 'bg' => 'bg-red-50', 'text' => 'text-red-700', 'border' => 'border-red-200'],
'processed' => ['label' => 'Processed', 'icon' => 'fa-gears', 'dot' => 'bg-amber-500', 'bg' => 'bg-amber-50', 'text' => 'text-amber-700', 'border' => 'border-amber-200'],
'delivered' => ['label' => 'Delivered', 'icon' => 'fa-box-open', 'dot' => 'bg-green-500', 'bg' => 'bg-green-50', 'text' => 'text-green-700', 'border' => 'border-green-200'],
];
$currentStatus = $statusConfig[$status] ?? ['label' => ucfirst($status), 'icon' => 'fa-circle-info', 'dot' => 'bg-gray-500', 'bg' => 'bg-gray-50', 'text' => 'text-gray-700', 'border' => 'border-gray-200'];
if ($isLeave) {
$workflow = [
'submitted' => ['label' => 'Submitted', 'icon' => 'fa-paper-plane'],
'viewed' => ['label' => 'Under Review', 'icon' => 'fa-eye'],
'approved' => ['label' => 'Approved', 'icon' => 'fa-check'],
];
} else {
$workflow = [
'submitted' => ['label' => 'Submitted', 'icon' => 'fa-paper-plane'],
'viewed' => ['label' => 'Under Review', 'icon' => 'fa-eye'],
'approved' => ['label' => 'Approved', 'icon' => 'fa-check'],
'processed' => ['label' => 'Processed', 'icon' => 'fa-gears'],
'delivered' => ['label' => 'Delivered', 'icon' => 'fa-box-open'],
];
}
$workflowKeys = array_keys($workflow);
$currentIndex = array_search($status, $workflowKeys) !== false ? array_search($status, $workflowKeys) : 0;
$studentName = $app->student_name ?? 'Student';
$studentInitial = strtoupper(substr(trim($studentName), 0, 1));
$reference = str_pad($app->id, 6, '0', STR_PAD_LEFT);
$createdDate = $app->created_at ? \Carbon\Carbon::parse($app->created_at) : null;
$description = trim($app->description ?? '');
@endphp
{{-- TOP HEADER --}}
Application Details
Reference #{{ $reference }}
{{ $currentStatus['label'] }}
{{-- 1. STUDENT HERO CARD --}}
{{ $studentInitial }}
{{ $studentName }}
{{ $isLeave ? 'Leave' : 'Document' }}
Admission No: {{ $app->admission_no ?? '—' }}
{{ $app->class_name ?? 'Class' }}
•
{{ $app->section_name ?? 'Section' }}
@if($createdDate)
Submitted on {{ $createdDate->format('d M Y, h:i A') }}
@endif
{{-- 2. REQUEST SUMMARY --}}
Application
Request Information
Subject
{{ $app->subject ?: 'No subject provided' }}
@if($isLeave)
Leave Information
From
{{ $app->leave_from ?: '—' }}
To
{{ $app->leave_to ?: '—' }}
Type
{{ $app->leave_type ?: '—' }}
@else
Document Requested
{{ $app->document_type ?: 'Document' }}
Certificate / Document Request
@endif
Description
@if($description)
{{ $description }}
@else
No description provided.
@endif
@if($app->attachment)
@endif
Current Status & Actions
@php
$statusClasses = [
'submitted' => 'bg-slate-100 text-slate-700', 'viewed' => 'bg-blue-50 text-blue-700',
'approved' => 'bg-emerald-50 text-emerald-700', 'rejected' => 'bg-red-50 text-red-700',
'processed' => 'bg-amber-50 text-amber-700', 'delivered' => 'bg-green-50 text-green-700',
];
// Build Dropdown Items Dynamically
$showDropdown = false;
$dropdownItems = [];
// Only show actions for active statuses (NOT for rejected or delivered)
if (!in_array($app->status, ['rejected', 'delivered'])) {
// 1. LEAVE ACTIONS
if ($app->application_type === 'leave' && in_array($app->status, ['submitted', 'viewed'])) {
$showDropdown = true;
$dropdownItems[] = [
'label' => 'Approve Leave', 'icon' => 'fa-check', 'class' => 'text-emerald-600 hover:bg-emerald-50',
'type' => 'form', 'action' => route('staff.applications.approve', ['slug' => session('staff_school_slug'), 'id' => $app->id]), 'method' => 'POST'
];
if (in_array($designation, ['PRINCIPAL', 'COORDINATOR'])) {
$dropdownItems[] = [
'label' => 'Reject Leave', 'icon' => 'fa-xmark', 'class' => 'text-red-600 hover:bg-red-50',
'type' => 'button', 'action' => 'openRejectModal()'
];
}
}
// 2. DOCUMENT ACTIONS (RECEPTIONIST ONLY)
if ($app->application_type === 'document' && $designation === 'RECEPTIONIST') {
$showDropdown = true;
if (in_array($app->status, ['submitted', 'viewed'])) {
$dropdownItems[] = [
'label' => 'Approve Document', 'icon' => 'fa-check', 'class' => 'text-emerald-600 hover:bg-emerald-50',
'type' => 'form', 'action' => route('staff.applications.approve', ['slug' => session('staff_school_slug'), 'id' => $app->id]), 'method' => 'POST'
];
$dropdownItems[] = [
'label' => 'Reject Document', 'icon' => 'fa-xmark', 'class' => 'text-red-600 hover:bg-red-50',
'type' => 'button', 'action' => 'openRejectModal()'
];
}
if ($app->status === 'approved') {
$dropdownItems[] = [
'label' => 'Mark as Processed', 'icon' => 'fa-gears', 'class' => 'text-amber-600 hover:bg-amber-50',
'type' => 'form', 'action' => route('staff.applications.process', ['slug' => session('staff_school_slug'), 'id' => $app->id]), 'method' => 'POST'
];
}
if ($app->status === 'processed') {
$dropdownItems[] = [
'label' => 'Mark as Delivered', 'icon' => 'fa-box-open', 'class' => 'text-green-600 hover:bg-green-50',
'type' => 'form', 'action' => route('staff.applications.deliver', ['slug' => session('staff_school_slug'), 'id' => $app->id]), 'method' => 'POST'
];
}
}
}
@endphp
{{ ucfirst($app->status) }}
@if($showDropdown)
@foreach($dropdownItems as $item)
@if($item['type'] === 'form')
@else
@endif
@if(!$loop->last)
@endif
@endforeach
@else
No actions available for your role
@endif
@if(in_array($designation, ['PRINCIPAL', 'COORDINATOR', 'RECEPTIONIST']))
@if(in_array($app->status, ['approved', 'delivered']))
@else
Print Application
@endif
@endif
@push('scripts')
@endpush
@endsection