@extends('layouts.user_type.auth') @section('content')

Employees Worked Hours - {{ \Carbon\Carbon::parse($month)->format('M Y') }}

Download XLS Attendance
@for ($i = 1; $i <= $daysInMonth; $i++) @php $date = \Carbon\Carbon::parse("$month-$i"); @endphp @endfor @foreach ($employees as $employee) @for ($i = 1; $i <= $daysInMonth; $i++) @php $date = \Carbon\Carbon::parse("$month-$i"); $formattedDate = $date->format('Y-m-d'); $isSunday = $date->isSunday(); $isFutureDate = $date->greaterThan(\Carbon\Carbon::today()); $isHoliday = in_array($formattedDate, $holidays); // Check if employee is on leave $leave = $employee->leaves->first(function ($leave) use ($formattedDate) { return $formattedDate >= $leave->start_date && $formattedDate <= $leave->end_date; }); $attendancesForDay = $employee->attendances ->filter(function ($att) use ($formattedDate) { return \Carbon\Carbon::parse($att->check_in)->format('Y-m-d') === $formattedDate; }); $firstCheckIn = $attendancesForDay->min('check_in'); $lastCheckOut = $attendancesForDay->max('check_out'); $hasAttendance = $firstCheckIn !== null; if ($isHoliday) { $status = 'H'; } elseif ($leave) { // Check if it is a half-day leave if ($leave->half_day) { $status = 'HD'; } else { $status = $leave->leaveType->name ?? 'L'; } } elseif ($isSunday) { $status = 'W'; } elseif ($isFutureDate) { $status = '-'; } else { $status = $attendancesForDay->isNotEmpty() ? 'P' : 'A'; } @endphp @endfor @endforeach
Employee {{ $date->format('M d') }}
{{ $date->format('D') }}
{{ $employee->name ?? ($employee->first_name . ($employee->middle_name ? ' ' . $employee->middle_name : '') . ' ' . $employee->last_name) }} @if ($status === 'P' && $hasAttendance) @php $workedMinutes = 0; $absentFlag = false; foreach ($attendancesForDay as $att) { if ($att->check_in && $att->check_out) { $checkIn = \Carbon\Carbon::parse($att->check_in); $checkOut = \Carbon\Carbon::parse($att->check_out); // ✅ Handle cross-midnight checkout if ($checkOut->lessThan($checkIn)) { $checkOut->addDay(); } $workedMinutes += $checkIn->diffInMinutes($checkOut); } else { // 🚫 If any record has missing checkout, mark as absent $absentFlag = true; break; } } $workedHoursFormatted = (!$absentFlag && $workedMinutes > 0) ? sprintf('%02d:%02d', floor($workedMinutes / 60), $workedMinutes % 60) : 'Absent'; @endphp @if ($workedHoursFormatted !== 'Absent') {{ $workedHoursFormatted }} (H:M) @else {{ $workedHoursFormatted }} @endif @else @php // Check for Regularization (only if status was A) if ($status === 'A') { $regularized = $employee->regularizations->first(function ($reg) use ($formattedDate) { return $reg->date === $formattedDate && $reg->status === 'Pending'; }); if ($regularized) { $status = 'RRC'; } } @endphp {{ $status }} @endif
Legend: P = Present | A = Absent | CL = Casual Leave | SL = Sick Leave | PL = Paid Leave | W = Weekend | H = Holiday | RRC = Regularization Request Created
@endsection