@extends('layouts.master') @section('title', 'Teachingload') @section('style') @endsection @section('script') @endsection @section('content') @include('layouts.header') @include('layouts.title')
@yield('title')

@if($adcontract_value)
Workload Arrangement
A. Position
Administrative Position : {{ $adcontract->admin_position_name }}
Sub Position : {{ $adcontract->admin_position_sub_name }}
Appointment No. : {{ $adcontract->adcontract_no }}

B. Workload Arrangement for Administrative Position Type
Academic Year : {{ $teachingLoad->teaching_load_year }}
Semester : {{ $teachingLoad->teaching_load_semester }}
Administrative Position Type : {{ $adcontract_value->adposition_type_name }}
Workload Arrangement Table
@php $selectedType = $adcontract_value->adcontract_value_type_id; @endphp @foreach($adposition_types as $item) @endforeach @foreach($Wadpositions as $index => $w) @foreach($adposition_types as $item) @php $value = $wpositions ->where('wposition_name', $w->Wadposition_id) ->where('wposition_type_id', $item->adposition_type_id) ->first(); @endphp @endforeach @endforeach
No. Workload Arrangement Unit {{ $item->adposition_type_name }}
{{ $index + 1 }} {{ $w->Wadposition_title }} {{ $w->unit_name }} {{ $value->wposition_value ?? '-' }}

C. Period
Start Date : {{ $adcontract->adcontract_start_date }}
End Date : {{ $adcontract->adcontract_end_date }}
Arrangement Status : {{ $adcontract_value->status ?? '-' }}

@endif
Teachingload
@if($teachingLoad)
@csrf
@else
Teaching Load header has not been created yet.
@endif
@csrf {{-- ตัวหลักใหม่ --}} {{-- เก็บไว้ช่วง transition --}} @php $roman = [ 1 => 'I', 2 => 'II', 3 => 'III' ]; @endphp {{-- Section Title --}}
1. Teaching Load
a) Lecture
=
12 Credits, 24 Hours/Week
TOR
=
12 Credits, 24 Hours/Week
{{-- ===================== --}} {{-- Lecture --}} {{-- ===================== --}} @foreach([1, 2, 3] as $semester) @php $rows = $lecture[$semester] ?? collect(); $lectureContact = $rows->sum(function ($r){ return (int)$r->course_contact; }); @endphp @php $isEditableSemester = (string) $semester === (string) $teachingLoad->teaching_load_semester; @endphp
Academic Year {{ $teachingLoad->teaching_load_year }} - Semester {{ $semester }}
@if($isEditableSemester) @else View Only @endif
@forelse($rows as $key => $row) {{-- Course No. --}} {{-- Course --}} {{-- Course Level --}} {{-- Portions --}} {{-- Section --}} {{-- Students --}} {{-- Weeks --}} {{-- Lecture --}} {{-- Credit --}} {{-- Contact (Hr/Wk) for Lecture --}} {{-- Source --}} {{-- Action --}} @empty @endforelse
No. Course No. Course Course Level Portions (%) Sec.No. No. of Students No. of Weeks Lecture (Hr/Wk) Credits (Lect.-Pr) Contact (Hr/Wk) for Lecture Source Action
{{ $key + 1 }} {{-- Total Contact เก็บหลังบ้าน --}} @if(($row->source ?? 'AUTO') == 'AUTO') AUTO @else MANUAL @endif @if($isEditableSemester) @else View Only @endif
No lecture courses found for Semester {{ $semester }}
{{-- Remaining --}}
Remaining Semester {{ $semester }} =
4 Credits/Week

@endforeach

{{-- ///////////////////////////////////////////////////////////////////////// --}} {{-- Section Title --}}
b) Laboratory
=
7 Credits, 24 Hours/Week
TOR
=
7 Credits, 24 Hours/Week
{{-- ========================================================= --}} {{-- LABORATORY --}} {{-- ========================================================= --}} @foreach([1, 2, 3] as $semester) @php $rows = $laboratory[$semester] ?? collect(); /* |-------------------------------------------------------------------------- | Total a + b |-------------------------------------------------------------------------- | | รวม course_contact_total ของ Laboratory | ใน Semester นี้ | */ $labContactTotal = $rows->sum(function ($row) { return (float) ( $row->course_contact_total ?? 0 ); }); $isEditableSemester = (string) $semester === (string) $teachingLoad->teaching_load_semester; @endphp
Academic Year {{ $teachingLoad->teaching_load_year }} - Semester {{ $semester }}
@if($isEditableSemester) @else View Only @endif
@forelse($rows as $key => $row) {{-- Course No. --}} {{-- Course --}} {{-- Course Level --}} {{-- Portions --}} {{-- Section --}} {{-- Students --}} {{-- No. of Lecturers --}} {{-- Credit --}} {{-- Contact (Hr/Wk) for Lab --}} {{-- Source --}} {{-- Action --}} @empty @endforelse {{-- No. ถึง No. of Lecturers --}} {{-- ใต้คอลัมน์ Credits --}} {{-- ใต้คอลัมน์ Contact (Hr/Wk) for Lab --}} {{-- Source + Action --}}
No. Course No. Course Course Level Portions (%) Sec.No. No. of Students No. of Lecturers Credits (Lect.-Pr) Contact (Hr/Wk) for Lab Source Action
{{ $key + 1 }} {{-- Total Contact เก็บหลังบ้าน --}} @if(($row->source ?? 'AUTO') == 'AUTO') AUTO @else MANUAL @endif @if($isEditableSemester) @else View Only @endif
No laboratory courses found for Semester {{ $semester }}
Total a + b {{ $labContactTotal }}
@endforeach
{{-- ========================================================= --}} {{-- 2a. SENIOR PROJECT --}} {{-- ========================================================= --}} {{-- Section Title --}}
2. Supervision of Senior Project/ Extended Training/ Special Problems/ Selected Topic/ Others
a) Senior Project/ Extended Training Requirement
=
3 Groups/Year, 12 Hours/Year
TOR
=
3 Groups/Year, 12 Hours/Year
@foreach([1, 2, 3] as $semester) @php $rows = $senior[$semester] ?? collect(); $seniorContactTotal = $rows->sum(function ($r) { return (float) ($r->senior_contact ?? 0); }); $isEditableSemester = (string) $semester === (string) $teachingLoad->teaching_load_semester; @endphp
Academic Year {{ $teachingLoad->teaching_load_year }} - Semester {{ $semester }}
@if($isEditableSemester) @else View Only @endif
@forelse($rows as $key => $row) {{-- Course No. --}} {{-- Course --}} {{-- Student --}} {{-- Credit --}} {{-- Contact --}} {{-- Source --}} {{-- Action --}} @empty @endforelse
No. Course No. Course No. of Students Credits Contact (Hr/Wk) Source Action
{{ $key + 1 }} @if(($row->source ?? 'AUTO') == 'AUTO') AUTO @else MANUAL @endif @if($isEditableSemester) @else View Only @endif
No Senior Project found for Semester {{ $semester }}
Total Contact {{ $seniorContactTotal }}
@endforeach
{{-- ========================================================= --}} {{-- 2b. MASTER / DOCTORAL SUPERVISION --}} {{-- ========================================================= --}} {{-- Section Title --}}
b) Supervision for Master and Doctoral Students
=
3 Groups/Year, 12 Hours/Year
TOR
=
3 Groups/Year, 12 Hours/Year
@foreach([1, 2, 3] as $semester) @php $rows = $supervision[$semester] ?? collect(); $isEditableSemester = (string) $semester === (string) $teachingLoad->teaching_load_semester; @endphp
Academic Year {{ $teachingLoad->teaching_load_year }} - Semester {{ $semester }}
@if($isEditableSemester) @else View Only @endif
@forelse($rows as $key => $row) @empty @endforelse
No. Student Code Title First Name Last Name Level No. of Students Credits Contact (Hr/Wk) Source Action
{{ $key + 1 }} {{-- disabled ไม่ submit ดังนั้นมี hidden --}} @if(($row->source ?? 'AUTO') == 'AUTO') AUTO @else MANUAL @endif @if($isEditableSemester) @else View Only @endif
No supervision data found for Semester {{ $semester }}
@endforeach {{-- ========================================================= --}} {{-- 3. Internal Committees --}} {{-- ========================================================= --}}
3. Internal Committees
@forelse($committee as $key => $row) @empty @endforelse
No. Internal Committees Name Document
{{ $key + 1 }} {{ $row->ic_name ?? '-' }} @if(!empty($row->ic_documents)) View File @else - @endif
No Internal Committees found.

{{-- ========================================================= --}} {{-- 4. TIMETABLE --}} {{-- ========================================================= --}}
4. Timetable
Teaching Schedule
@foreach([1, 2, 3] as $semester) @php // $rows = $timetable[$semester] ?? collect(); // $isEditableSemester = // (string) $semester // === // (string) $teachingLoad->teaching_load_semester; @endphp @php $rows = ($timetable[$semester] ?? collect()) ->sortBy(function ($row) { return (int) $row->timetable_id; }) ->values(); $isEditableSemester = (string) $semester === (string) $teachingLoad->teaching_load_semester; @endphp
{{-- Header --}}
Academic Year {{ $teachingLoad->teaching_load_year }} - Semester {{ $semester }}
@if($isEditableSemester) @endif
@forelse($rows as $key => $row) {{-- Course No --}} {{-- Course --}} {{-- Teaching Type --}} {{-- Day --}} {{-- Start --}} {{-- End --}} {{-- Room --}} {{-- Activity --}} {{-- Source --}} {{-- Action --}} @empty @endforelse
No. Course No. Course Teaching Type Day Start Time End Time Room Activity Source Action
{{ $key + 1 }} @if(($row->source ?? 'AUTO') == 'AUTO') AUTO @else MANUAL @endif @if($isEditableSemester) @else View Only @endif
No timetable found for Semester {{ $semester }}
{{-- ========================================================= --}} {{-- TIMETABLE GRID PREVIEW --}} {{-- ========================================================= --}} @php /* |-------------------------------------------------------------------------- | ข้อมูล Timetable ของ Semester นี้ |-------------------------------------------------------------------------- */ $semesterTimetableRows = $timetable[$semester] ?? collect(); /* |-------------------------------------------------------------------------- | แยก Regular |-------------------------------------------------------------------------- */ $regularTimetableRows = $semesterTimetableRows ->filter(function ($row) { return trim( $row->timetable_activity ?? '' ) === 'Regular Teaching Schedule'; }) ->values(); /* |-------------------------------------------------------------------------- | แยก Extra |-------------------------------------------------------------------------- */ $extraTimetableRows = $semesterTimetableRows ->filter(function ($row) { return trim( $row->timetable_activity ?? '' ) === 'Extra Teaching Schedule'; }) ->values(); /* |-------------------------------------------------------------------------- | สองตารางที่จะ Preview |-------------------------------------------------------------------------- */ $scheduleGroups = [ 'Regular Teaching Schedule' => $regularTimetableRows, 'Extra Teaching Schedule' => $extraTimetableRows ]; @endphp
{{-- ===================================================== --}} {{-- Semester Header --}} {{-- ===================================================== --}}
Teaching Schedule Preview - Semester {{ $semester }}
{{-- ===================================================== --}} {{-- Regular + Extra --}} {{-- ===================================================== --}} @foreach($scheduleGroups as $scheduleName => $gridRows)
{{-- =============================================== --}} {{-- Schedule Type --}} {{-- =============================================== --}}
@if($scheduleName == 'Regular Teaching Schedule') Regular @else Extra @endif
{{ $scheduleName }}
{{-- =============================================== --}} {{-- ไม่มีข้อมูล --}} {{-- =============================================== --}} @if($gridRows->isEmpty())
No {{ $scheduleName }} found for Semester {{ $semester }}.
@else @php /* |-------------------------------------------------------------------------- | Day |-------------------------------------------------------------------------- */ $days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]; /* |-------------------------------------------------------------------------- | Convert Time -> Minute |-------------------------------------------------------------------------- */ $timeToMinutes = function ($time) { if (empty($time)) { return null; } $time = substr( $time, 0, 5 ); [$hour, $minute] = array_map( 'intval', explode(':', $time) ); return ($hour * 60) + $minute; }; /* |-------------------------------------------------------------------------- | 1 Slot = 30 นาที |-------------------------------------------------------------------------- */ $slotMinutes = 30; /* |-------------------------------------------------------------------------- | หาเวลาเริ่มเร็วที่สุด |-------------------------------------------------------------------------- */ $minStart = $gridRows ->map(function ($row) use ($timeToMinutes) { return $timeToMinutes( $row->timetable_time_start ); }) ->filter(function ($value) { return $value !== null; }) ->min(); /* |-------------------------------------------------------------------------- | หาเวลาจบช้าที่สุด |-------------------------------------------------------------------------- */ $maxEnd = $gridRows ->map(function ($row) use ($timeToMinutes) { return $timeToMinutes( $row->timetable_time_end ); }) ->filter(function ($value) { return $value !== null; }) ->max(); /* |-------------------------------------------------------------------------- | ใช้ช่วงเวลาจริงของแต่ละ Schedule |-------------------------------------------------------------------------- | | Regular เช่น 08:00 - 17:00 | Extra เช่น 18:00 - 21:00 | |-------------------------------------------------------------------------- */ $gridStart = $minStart ?? (8 * 60); $gridEnd = $maxEnd ?? (17 * 60); /* |-------------------------------------------------------------------------- | ปัดเป็น 30 นาที |-------------------------------------------------------------------------- */ $gridStart = floor( $gridStart / $slotMinutes ) * $slotMinutes; $gridEnd = ceil( $gridEnd / $slotMinutes ) * $slotMinutes; /* |-------------------------------------------------------------------------- | จำนวนช่อง |-------------------------------------------------------------------------- */ $slotCount = ($gridEnd - $gridStart) / $slotMinutes; @endphp
{{-- ========================================= --}} {{-- HEADER --}} {{-- ========================================= --}} @for( $slot = 0; $slot < $slotCount; $slot++ ) @php $startMinutes = $gridStart + ($slot * $slotMinutes); $endMinutes = $startMinutes + $slotMinutes; $startHour = floor( $startMinutes / 60 ); $startMinute = $startMinutes % 60; $endHour = floor( $endMinutes / 60 ); $endMinute = $endMinutes % 60; $startLabel = sprintf( '%02d:%02d', $startHour, $startMinute ); $endLabel = sprintf( '%02d:%02d', $endHour, $endMinute ); @endphp @endfor {{-- ========================================= --}} {{-- BODY --}} {{-- ========================================= --}} @foreach($days as $day) @php /* |-------------------------------------------------------------------------- | วิชาของวันนั้น |-------------------------------------------------------------------------- */ $dayRows = $gridRows ->filter(function ($row) use ($day) { return strtoupper( trim( $row->timetable_date ) ) === strtoupper($day); }) ->sortBy( 'timetable_time_start' ) ->values(); $position = 0; @endphp {{-- Day --}} {{-- ================================= --}} {{-- Slot --}} {{-- ================================= --}} @while($position < $slotCount) @php $slotStart = $gridStart + ( $position * $slotMinutes ); /* |-------------------------------------------------------------------------- | หาวิชาที่เริ่มใน Slot นี้ |-------------------------------------------------------------------------- */ $classes = $dayRows ->filter( function ($row) use ( $timeToMinutes, $slotStart, $slotMinutes, $gridStart ) { $start = $timeToMinutes( $row->timetable_time_start ); if ($start === null) { return false; } $normalizedStart = $gridStart + floor( ( $start - $gridStart ) / $slotMinutes ) * $slotMinutes; return $normalizedStart == $slotStart; } ); $hasClass = $classes->count() > 0; @endphp {{-- ================================= --}} {{-- มีวิชา --}} {{-- ================================= --}} @if($hasClass) @php /* |-------------------------------------------------------------------------- | เวลาจบสูงสุด |-------------------------------------------------------------------------- */ $classMaxEnd = $classes ->map( function ($row) use ($timeToMinutes) { return $timeToMinutes( $row->timetable_time_end ); } ) ->filter() ->max(); /* |-------------------------------------------------------------------------- | Duration |-------------------------------------------------------------------------- */ $duration = max( $slotMinutes, $classMaxEnd - $slotStart ); /* |-------------------------------------------------------------------------- | Colspan |-------------------------------------------------------------------------- */ $colspan = (int) ceil( $duration / $slotMinutes ); /* |-------------------------------------------------------------------------- | ป้องกันเกิน Grid |-------------------------------------------------------------------------- */ $remainingSlots = $slotCount - $position; $colspan = min( $colspan, $remainingSlots ); @endphp @php $position += $colspan; @endphp {{-- ================================= --}} {{-- Lunch 12:00 - 13:00 --}} {{-- ================================= --}} @elseif( $slotStart == (12 * 60) ) @php /* |-------------------------------------------------------------------------- | Lunch จะแสดงก็ต่อเมื่อ | Grid มีช่วง 12:00 - 13:00 |-------------------------------------------------------------------------- */ $remainingSlots = $slotCount - $position; $lunchColspan = min( 2, $remainingSlots ); @endphp @php $position += $lunchColspan; @endphp {{-- ================================= --}} {{-- Empty --}} {{-- ================================= --}} @else @php $position++; @endphp @endif @endwhile @endforeach
Day / Time
{{ $startLabel }}
-
{{ $endLabel }}
{{ $day }} @foreach($classes as $class)
{{-- Course Code --}}
{{ $class->timetable_course_code }}
{{-- Course Name --}}
{{ $class->timetable_course_name }}
{{-- Time --}}
{{ substr( $class->timetable_time_start, 0, 5 ) }} - {{ substr( $class->timetable_time_end, 0, 5 ) }}
{{-- Room --}} @if( !empty( $class->timetable_room ) )
Room: {{ $class->timetable_room }}
@endif {{-- Badges --}}
{{-- Activity --}} @if( $class->timetable_activity == 'Regular Teaching Schedule' ) Regular @else Extra @endif {{-- Teaching Type --}} @if( $class->timetable_teaching_type == 'Lecture' ) Lecture @elseif( $class->timetable_teaching_type == 'Laboratory' ) Laboratory @endif {{-- Source --}} @if( ($class->source ?? 'AUTO') == 'MANUAL' ) MANUAL @endif
@endforeach
Lunch
12:00 - 13:00
 
@endif
@endforeach
{{-- ========================================================= --}}

@endforeach
Preview
@include('layouts.footer') @endsection