@php $attendancePopupUser = \Illuminate\Support\Facades\Auth::user(); $attendancePopupEmployee = null; $attendancePopupToday = today(); $attendancePopupRecord = null; $attendancePopupSetting = null; $attendancePopupShouldShow = false; $attendancePopupIsAutoAttendance = false; $attendancePopupCanUseAttendance = false; $attendancePopupStatusText = 'Belum absen masuk'; $attendancePopupAction = 'check-in'; $attendancePopupAllowedCheckoutTime = null; $attendancePopupHiddenRoles = ['developer', 'owner']; $attendancePopupUserRoles = []; $attendancePopupIsHiddenRole = false; if ($attendancePopupUser) { if (method_exists($attendancePopupUser, 'getRoleNames')) { $attendancePopupUserRoles = array_merge( $attendancePopupUserRoles, $attendancePopupUser->getRoleNames()->map(fn ($role) => strtolower((string) $role))->toArray() ); } if (method_exists($attendancePopupUser, 'hasAnyRole')) { try { $attendancePopupIsHiddenRole = $attendancePopupUser->hasAnyRole($attendancePopupHiddenRoles); } catch (\Throwable $e) { $attendancePopupIsHiddenRole = false; } } foreach (['role', 'role_name'] as $roleColumn) { if (!empty($attendancePopupUser->{$roleColumn}) && is_string($attendancePopupUser->{$roleColumn})) { $attendancePopupUserRoles[] = strtolower((string) $attendancePopupUser->{$roleColumn}); } } if (!empty($attendancePopupUser->role) && is_object($attendancePopupUser->role) && !empty($attendancePopupUser->role->name)) { $attendancePopupUserRoles[] = strtolower((string) $attendancePopupUser->role->name); } $attendancePopupIsHiddenRole = $attendancePopupIsHiddenRole || count(array_intersect($attendancePopupHiddenRoles, array_unique($attendancePopupUserRoles))) > 0; } if ( $attendancePopupUser && !$attendancePopupIsHiddenRole && \Illuminate\Support\Facades\Route::has('attendance.index') && \Illuminate\Support\Facades\Route::has('attendance.check-in') && \Illuminate\Support\Facades\Route::has('attendance.check-out') ) { if (\Illuminate\Support\Facades\Schema::hasTable('employees')) { if (\Illuminate\Support\Facades\Schema::hasColumn('employees', 'user_id')) { $attendancePopupEmployee = \App\Models\Employee::where('user_id', $attendancePopupUser->id)->first(); } if ( !$attendancePopupEmployee && \Illuminate\Support\Facades\Schema::hasColumn('employees', 'email') && !empty($attendancePopupUser->email) ) { $attendancePopupEmployee = \App\Models\Employee::where('email', $attendancePopupUser->email)->first(); } if ( !$attendancePopupEmployee && \Illuminate\Support\Facades\Schema::hasColumn('employees', 'name') && !empty($attendancePopupUser->name) ) { $attendancePopupEmployee = \App\Models\Employee::where('name', $attendancePopupUser->name)->first(); } } if ($attendancePopupEmployee) { if (\Illuminate\Support\Facades\Schema::hasTable('attendances')) { $attendancePopupRecord = \App\Models\Attendance::where('employee_id', $attendancePopupEmployee->id) ->whereDate('attendance_date', $attendancePopupToday) ->first(); } if (\Illuminate\Support\Facades\Schema::hasColumn('employees', 'is_auto_attendance')) { $attendancePopupIsAutoAttendance = (bool) ($attendancePopupEmployee->is_auto_attendance ?? false); } if (\Illuminate\Support\Facades\Schema::hasTable('attendance_settings')) { $attendancePopupSetting = \App\Models\AttendanceSetting::where('is_active', true)->first(); } if (!$attendancePopupIsAutoAttendance && $attendancePopupSetting) { /* * Belum absen masuk: * Popup dan tombol Absensi muncul. */ if (!$attendancePopupRecord || !$attendancePopupRecord->check_in_at) { $attendancePopupShouldShow = true; $attendancePopupCanUseAttendance = true; $attendancePopupStatusText = 'Belum absen masuk'; $attendancePopupAction = 'check-in'; } /* * Sudah absen masuk, belum absen pulang: * Popup dan tombol Absensi hilang sampai sudah masuk jam pulang. */ elseif ($attendancePopupRecord->check_in_at && !$attendancePopupRecord->check_out_at) { $canCheckoutNow = false; if (!empty($attendancePopupSetting->work_end_time)) { $scheduledEnd = \Carbon\Carbon::parse(now()->toDateString() . ' ' . $attendancePopupSetting->work_end_time); $tolerance = (int) ($attendancePopupSetting->early_leave_tolerance_minutes ?? 0); $attendancePopupAllowedCheckoutTime = $scheduledEnd->copy()->subMinutes($tolerance); $canCheckoutNow = now()->greaterThanOrEqualTo($attendancePopupAllowedCheckoutTime); } else { /* * Kalau jam pulang belum diatur, fallback: tombol pulang tetap muncul * setelah sudah absen masuk agar user masih bisa absen pulang. */ $canCheckoutNow = true; } if ($canCheckoutNow) { $attendancePopupShouldShow = true; $attendancePopupCanUseAttendance = true; $attendancePopupStatusText = 'Sudah waktunya absen pulang'; $attendancePopupAction = 'check-out'; } else { $attendancePopupShouldShow = false; $attendancePopupCanUseAttendance = false; $attendancePopupStatusText = 'Sudah absen masuk, belum waktunya absen pulang'; $attendancePopupAction = 'waiting-checkout'; } } /* * Sudah absen masuk dan pulang: * Popup dan tombol Absensi hilang. */ elseif ($attendancePopupRecord->check_in_at && $attendancePopupRecord->check_out_at) { $attendancePopupShouldShow = false; $attendancePopupCanUseAttendance = false; $attendancePopupStatusText = 'Absensi hari ini sudah lengkap'; $attendancePopupAction = 'done'; } } } } @endphp @if($attendancePopupShouldShow)

Pengingat Absensi

{{ $attendancePopupStatusText }}

{{ $attendancePopupEmployee->name ?? 'Karyawan' }}
Lokasi harus berada dalam radius {{ $attendancePopupSetting->radius_meters ?? 0 }} meter dari {{ $attendancePopupSetting->location_name ?? 'lokasi absensi' }}.
@if($attendancePopupAction === 'check-out' && $attendancePopupAllowedCheckoutTime)
Absen pulang tersedia mulai pukul {{ $attendancePopupAllowedCheckoutTime->format('H:i') }}.
@endif
@if($attendancePopupRecord?->check_in_at)
Masuk
{{ $attendancePopupRecord->check_in_at->format('H:i') }}
Pulang
{{ $attendancePopupRecord->check_out_at?->format('H:i') ?? '-' }}
@endif

@if($attendancePopupAction === 'check-in')
@csrf
@elseif($attendancePopupAction === 'check-out')
@csrf
@endif Buka halaman Absensi
@endif @if($attendancePopupShouldShow && \Illuminate\Support\Facades\Route::has('attendance.index')) Absensi @endif @if($attendancePopupShouldShow) @endif