@extends('layouts.app')
@php
$pageTitle = 'Reports';
$currentReportType = $reportType ?? 'section_schedule';
$selectedSchoolYear = $schoolYears->firstWhere('id', $selectedSchoolYearId ?? null);
$selectedTerm = $terms->firstWhere('id', $selectedTermId ?? null);
$selectedGradeLevel = $gradeLevels->firstWhere('id', $selectedGradeLevelId ?? null);
$selectedSection = $sections->firstWhere('id', $selectedSectionId ?? null);
$selectedTeacher = $teachers->firstWhere('id', $selectedTeacherId ?? null);
$selectedRoom = $rooms->firstWhere('id', $selectedRoomId ?? null);
$days = [
'monday' => 'Monday',
'tuesday' => 'Tuesday',
'wednesday' => 'Wednesday',
'thursday' => 'Thursday',
'friday' => 'Friday',
];
$reportMeta = [
'section_schedule' => [
'title' => 'Section Schedule Preview',
'subtitle' => 'Preview of the weekly schedule for the selected section.',
'badge' => 'Section Report',
],
'teacher_schedule' => [
'title' => 'Teacher Schedule Preview',
'subtitle' => 'Preview of all assigned class entries for the selected teacher.',
'badge' => 'Teacher Report',
],
'room_utilization' => [
'title' => 'Room Schedule Preview',
'subtitle' => 'Preview of room usage across scheduled class entries.',
'badge' => 'Room Report',
],
'teacher_load' => [
'title' => 'Teacher Load Preview',
'subtitle' => 'Summary of assigned hours and load status per teacher.',
'badge' => 'Teacher Load',
],
'subject_hours_summary' => [
'title' => 'Subject Hours Summary Preview',
'subtitle' => 'Comparison of scheduled hours and expected subject hours.',
'badge' => 'Subject Hours',
],
'scheduling_readiness' => [
'title' => 'Scheduling Readiness Preview',
'subtitle' => 'Teacher, room, and grid feasibility check for the selected term.',
'badge' => 'Scheduling Readiness',
],
];
$activeMeta = $reportMeta[$currentReportType] ?? $reportMeta['section_schedule'];
// Print/PDF/Excel only cover the two schedule programs, and only once a
// section/teacher with a timetable is selected.
$canExport = match ($currentReportType) {
'section_schedule' => !empty($reportData['section']) && !empty($reportData['grid']),
'teacher_schedule' => !empty($reportData['teacher']) && !empty($reportData['grid']),
default => false,
};
// Every report can be printed once it has something to show.
$canPrint = match ($currentReportType) {
'room_utilization' => !empty($reportData['room']) && !empty($reportData['grid']),
'teacher_load' => !empty($reportData['rows']) && count($reportData['rows']) > 0,
'subject_hours_summary' => !empty($reportData['section']) && !empty($reportData['rows']) && count($reportData['rows']) > 0,
'scheduling_readiness' => !empty($reportData['summary']),
default => $canExport,
};
$buildRouteParams = function (array $extra = []) use (
$selectedSchoolYearId,
$selectedTermId,
$selectedGradeLevelId,
$selectedSectionId,
$selectedTeacherId,
$selectedRoomId,
$currentReportType
) {
return array_filter([
'school_year_id' => $selectedSchoolYearId,
'term_id' => $selectedTermId,
'grade_level_id' => $selectedGradeLevelId,
'section_id' => $selectedSectionId,
'teacher_id' => $selectedTeacherId,
'room_id' => $selectedRoomId,
'report_type' => $currentReportType,
...$extra,
], fn ($value) => !is_null($value) && $value !== '');
};
@endphp
@section('content')
@foreach ([
'section_schedule' => ['Section Schedule', 'bi-grid-3x3-gap'],
'teacher_schedule' => ['Teacher Schedule', 'bi-person-workspace'],
'room_utilization' => ['Room Schedule', 'bi-door-open'],
'teacher_load' => ['Teacher Load', 'bi-speedometer2'],
'subject_hours_summary' => ['Subject Hours', 'bi-clock-history'],
'scheduling_readiness' => ['Readiness', 'bi-clipboard-check'],
] as $tabKey => [$tabLabel, $tabIcon])
{{ $tabLabel }}
@endforeach
@if (!empty($reportData['section']) && !empty($reportData['grid']))
@include('reports.partials._class-program')
@else
Select a valid section and term to preview the section schedule.
@endif
@if (!empty($reportData['teacher']) && !empty($reportData['grid']))
@include('reports.partials._teacher-program')
@else
Select a valid teacher and term to preview the teacher schedule.
@endif
@if (!empty($reportData['room']) && !empty($reportData['grid']))
@include('reports.partials._print-header', [
'printTitle' => 'ROOM SCHEDULE',
'printSubtitle' => $reportData['room']->name . ' (' . ucfirst($reportData['room']->room_type ?? 'general') . ' Room)',
])
Room: {{ $reportData['room']->name }}
{{ ucfirst($reportData['room']->room_type ?? 'general') }} Room
@if ($selectedTerm?->name)
• {{ $selectedTerm->name }}
@endif
@if ($selectedSchoolYear?->name)
• SY {{ $selectedSchoolYear->name }}
@endif
Time
@foreach ($days as $dayLabel)
{{ $dayLabel }}
@endforeach
@foreach ($reportData['grid'] as $row)
@php
$timeSlot = $row['time_slot'];
$isBreak = (bool) ($timeSlot->is_break ?? false);
$timeLabel = $row['time_label'] ?? $timeSlot->time_range;
@endphp
{{ $timeLabel }}
@foreach (array_keys($days) as $dayKey)
@php $entry = $row['days'][$dayKey] ?? null; @endphp
@if ($isBreak)
Break
@elseif ($entry)
{{ $entry['subject'] ?? '—' }}
{{ $entry['section'] ?? 'No Section' }}
@if (!empty($entry['teacher']))
• {{ $entry['teacher'] }}
@endif
@else
—
@endif
@endforeach
@endforeach
@if (!empty($reportData['utilizationRows']) && count($reportData['utilizationRows']) > 0)
Utilization Summary
Day
Total Entries
@foreach ($reportData['utilizationRows'] as $row)
{{ $row['day'] }}
{{ $row['entries'] }}
@endforeach
@endif
@else
Select a valid room and term to preview the room schedule.
@endif
@if ($currentReportType === 'teacher_load' && !empty($reportData['rows']) && count($reportData['rows']) > 0)
@include('reports.partials._print-header', ['printTitle' => 'TEACHER LOAD SUMMARY', 'printSubtitle' => null])
Teacher Load Summary
@if ($selectedTerm?->name)
{{ $selectedTerm->name }}
@endif
@if ($selectedSchoolYear?->name)
• SY {{ $selectedSchoolYear->name }}
@endif
Teacher
Weekly Load
Mon
Tue
Wed
Thu
Fri
Total Entries
@foreach ($reportData['rows'] as $row)
{{ $row['teacher']->full_name }}
{{ number_format((float) $row['assigned_hours'], 2) }}
{{ number_format((float) $row['daily_hours']['monday'], 2) }}
{{ number_format((float) $row['daily_hours']['tuesday'], 2) }}
{{ number_format((float) $row['daily_hours']['wednesday'], 2) }}
{{ number_format((float) $row['daily_hours']['thursday'], 2) }}
{{ number_format((float) $row['daily_hours']['friday'], 2) }}
{{ $row['total_schedule_entries'] }}
@endforeach
@else
No teacher load data is available for the selected term.
@endif
@if ($currentReportType === 'subject_hours_summary' && !empty($reportData['section']) && !empty($reportData['rows']) && count($reportData['rows']) > 0)
@include('reports.partials._print-header', [
'printTitle' => 'SUBJECT HOURS SUMMARY',
'printSubtitle' => collect([
$reportData['section']->name,
$reportData['section']->gradeLevel?->name,
$reportData['section']->pathway?->name,
])->filter()->implode(' • '),
])
Section: {{ $reportData['section']->name }}
{{ $reportData['section']->gradeLevel?->name ?? 'No Grade Level' }}
@if ($reportData['section']->pathway?->name)
• {{ $reportData['section']->pathway->name }}
@endif
@if ($selectedTerm?->name)
• {{ $selectedTerm->name }}
@endif
@if ($selectedSchoolYear?->name)
• SY {{ $selectedSchoolYear->name }}
@endif
Subject
Scheduled Hours
Expected Weekly Hours
Difference
Status
@foreach ($reportData['rows'] as $row)
{{ $row['subject']?->name ?? 'Unknown Subject' }}
{{ number_format((float) $row['scheduled_hours'], 2) }}
{{ number_format((float) $row['required_hours'], 2) }}
{{ number_format((float) $row['difference'], 2) }}
{{ ucfirst($row['status']) }}
@endforeach
@else
Select a valid section and term to preview the subject hours summary.
@endif
@if ($currentReportType === 'scheduling_readiness' && !empty($reportData['summary']))
@php
$summary = $reportData['summary'];
$roomRow = $reportData['roomRow'];
@endphp
@include('reports.partials._print-header', [
'printTitle' => 'SCHEDULING READINESS',
'printSubtitle' => $summary['school_days'] . ' school days / ' . $summary['school_weeks'] . ' weeks',
])
Scheduling Readiness
{{ $reportData['term']?->name }}
({{ $summary['school_days'] }} school days / {{ $summary['school_weeks'] }} weeks)
@if ($selectedSchoolYear?->name)
• SY {{ $selectedSchoolYear->name }}
@endif
{{ $summary['is_ready']
? 'No blocking readiness issues detected for this term.'
: 'One or more readiness issues were found below. Resolve them before scheduling.' }}
Subject Teacher Coverage
Subject
Sections Requiring
Demand (hrs/wk)
Available (hrs/wk)
Additional Hours Needed (hrs/wk)
Qualified Teachers
Additional Teachers Needed
Status
@forelse ($reportData['subjectRows'] as $row)
{{ $row['subject']->name }}
{{ $row['sections_needing'] }}
{{ number_format($row['demand_hours'], 2) }}
{{ number_format($row['available_hours'], 2) }}
{{ number_format($row['needed_more_hours'], 2) }}
{{ $row['qualified_teacher_count'] }}
{{ $row['teachers_needed_more'] }}
@if ($row['status'] === 'ok' && $row['teachers_needed_more'] === 0)
@else
@endif
@empty
No required subjects found for this term.
@endforelse
Specialized Room Capacity
Demand (hrs/wk)
Supply Ceiling (hrs/wk)
Specialized Rooms
Status
{{ number_format($roomRow['demand_hours'], 2) }}
{{ number_format($roomRow['supply_hours'], 2) }}
{{ $roomRow['specialized_room_count'] }}
@if ($roomRow['status'] === 'ok')
@else
@endif
Section Grid Capacity
Section
Required (hrs/wk)
Available (hrs/wk)
Schedulable (hrs/wk)
Unschedulable (hrs/wk)
Blocked Subjects
Status
@php
$blockedReasons = [
'no_teacher' => 'no qualified teacher',
'teacher_conflict' => 'teachers busy elsewhere',
'no_space' => 'not enough grid time',
];
@endphp
@forelse ($reportData['gridRows'] as $row)
{{ $row['section']->name }}
{{ number_format($row['required_hours'], 2) }}
{{ number_format($row['available_hours'], 2) }}
{{ number_format($row['schedulable_hours'], 2) }}
{{ number_format($row['short_hours'], 2) }}
@forelse ($row['blocked_subjects'] as $blocked)
{{ $blocked['subject']->name }}
({{ $blockedReasons[$blocked['reason']] ?? $blocked['reason'] }})
@empty
-
@endforelse
@if ($row['status'] === 'ok')
@else
@endif
@empty
No active sections found for this year.
@endforelse
@else
Select a valid school year and term to preview scheduling readiness.
@endif
@include('reports.partials._program-styles')
@endsection
@push('scripts')
@endpush