@extends('layouts/layoutMaster') @section('title', 'Attendances') @section('vendor-style') @vite(['resources/assets/vendor/libs/datatables-bs5/datatables.bootstrap5.scss', 'resources/assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.scss', 'resources/assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.scss', 'resources/assets/vendor/libs/select2/select2.scss', 'resources/assets/vendor/libs/@form-validation/form-validation.scss', 'resources/assets/vendor/libs/animate-css/animate.scss', 'resources/assets/vendor/libs/sweetalert2/sweetalert2.scss']) @endsection @section('vendor-script') @vite(['resources/assets/vendor/libs/moment/moment.js', 'resources/assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js', 'resources/assets/vendor/libs/select2/select2.js', 'resources/assets/vendor/libs/@form-validation/popular.js', 'resources/assets/vendor/libs/@form-validation/bootstrap5.js', 'resources/assets/vendor/libs/@form-validation/auto-focus.js', 'resources/assets/vendor/libs/cleavejs/cleave.js', 'resources/assets/vendor/libs/cleavejs/cleave-phone.js', 'resources/assets/vendor/libs/sweetalert2/sweetalert2.js']) @endsection @section('content')
Employees Attendance
@php $selectedDay = \Carbon\Carbon::parse($selected_date ?? date('Y-m-d'))->format('l'); $isWeekend = ($selectedDay == 'Saturday' || $selectedDay == 'Sunday'); // Check if attendance exists for this date $attendanceDate = $selected_date ?? Carbon\Carbon::today()->toDateString(); $attendanceExists = \App\Models\Attendance::where('attendance_date', $attendanceDate)->exists(); $isToday = $attendanceDate == \Carbon\Carbon::today()->toDateString(); @endphp @if($isWeekend)
Note: You are viewing attendance for {{ $selectedDay }}. Weekend attendance options include Week Off.
@endif @if(!$attendanceExists)
Warning: Attendance records have not been submitted for {{ $isToday ? 'today' : 'this date' }}. Please complete and submit attendance information.
@endif
@csrf
@foreach ($employee as $index => $emp) @endforeach
Id Name Attendance
{{ $index + 1 }} @php $profilePhoto = $emp->user->profile_photo_path ?? ''; // dd($emp->user); $name = $emp->name ?? ''; $nameParts = preg_split('/\s+/', trim($name)); $avatarInitials = ''; if (count($nameParts) > 0) { $avatarInitials .= strtoupper($nameParts[0][0] ?? ''); if (count($nameParts) > 1) { $avatarInitials .= strtoupper($nameParts[count($nameParts) - 1][0] ?? ''); } } $states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']; $state = $states[random_int(0, count($states) - 1)]; @endphp
@if($profilePhoto && trim($profilePhoto) !== '') @php if (!Str::startsWith($profilePhoto, ['http://', 'https://', '/'])) { $profilePhoto = "/storage/{$profilePhoto}"; } @endphp Avatar @else {{ $avatarInitials }} @endif
@php $user = \App\Models\User::where('id', $emp->user_id)->first(); $attendanceDate = $selected_date ?? Carbon\Carbon::today()->toDateString(); $attendance = \App\Models\Attendance::where('user_id', $emp->user_id) ->where('attendance_date', $attendanceDate) ->first(); $leavesAccount = \App\Models\LeaveAccounting::where('user_id', $emp->user_id) ->whereDate('start_date', '<=', $attendanceDate) ->whereDate('end_date', '>=', $attendanceDate) ->first(); if(!empty($leavesAccount)) { $leave = \App\Models\Leave::where('leave_accountability_id', $leavesAccount->id) ->where('date', $attendanceDate) ->first(); } @endphp
attendance === 'present') @elseif(!$isWeekend) checked @endif />
attendance === 'absent') @elseif(!empty($leave) && $leave->days == 1) checked @endif />
attendance === 'halfday') @elseif(!empty($leave) && $leave->days == 0.5) checked @endif />
attendance === 'holiday') @endif />
@if($isWeekend)
attendance === 'weekoff') @else checked @endif />
@endif
@php // Get attendance status based on selected date $attendanceDate = $selected_date ?? Carbon\Carbon::today()->toDateString(); $attendance = \App\Models\Attendance::where('attendance_date', $attendanceDate)->get(); @endphp
@endsection