@php use App\Models\Attendance; use App\Models\AttendanceLog; use Illuminate\Support\Facades\Auth; use App\Services\Settings\ModuleSettingsService; use App\Services\AddonService\IAddonService; $todayAttendance = null; $isCheckedIn = false; $checkInTime = null; $checkOutTime = null; $workingHours = null; $isBreakSystemEnabled = false; $isOnBreak = false; if (Auth::check()) { $todayAttendance = Attendance::where('user_id', Auth::id()) ->whereDate('date', today()) ->with('attendanceLogs') ->first(); // Check if BreakSystem addon is enabled $addonService = app(IAddonService::class); $isBreakSystemEnabled = $addonService->isAddonEnabled('BreakSystem'); if ($todayAttendance) { // Check if multiple check-in is enabled $settingsService = app(ModuleSettingsService::class); $isMultipleCheckInEnabled = $settingsService->get('HRCore', 'is_multiple_check_in_enabled', true); if ($isMultipleCheckInEnabled && auth()->user()->can('hrcore.multiple-check-in')) { // For multiple check-in, check the last log $lastLog = $todayAttendance->attendanceLogs->sortByDesc('created_at')->first(); $isCheckedIn = $lastLog && $lastLog->type === 'check_in'; } else { // For single check-in, use attendance table $isCheckedIn = $todayAttendance->check_in_time && !$todayAttendance->check_out_time; } // Get times - fallback to logs if not in attendance table $checkInTime = $todayAttendance->check_in_time; if (!$checkInTime) { $checkInLog = $todayAttendance->attendanceLogs->where('type', 'check_in')->first(); $checkInTime = $checkInLog ? $checkInLog->created_at : null; } $checkOutTime = $todayAttendance->check_out_time; if (!$checkOutTime) { $checkOutLog = $todayAttendance->attendanceLogs->where('type', 'check_out')->last(); $checkOutTime = $checkOutLog ? $checkOutLog->created_at : null; } // Calculate working hours in "Xh Ym" format $workingHours = '0h 0m'; if ($checkInTime) { $checkInCarbon = \Carbon\Carbon::parse($checkInTime); $totalMinutes = 0; // Match web attendance page: always calculate to NOW for live time $totalMinutes = now()->diffInMinutes($checkInCarbon); if ($totalMinutes > 0) { $hours = floor($totalMinutes / 60); $minutes = $totalMinutes % 60; $workingHours = $hours . 'h ' . $minutes . 'm'; } } // Check if user is currently on break (only if break system is enabled and checked in) if ($isBreakSystemEnabled && $isCheckedIn) { // Get the latest check-in log for break tracking $checkInLog = $todayAttendance->attendanceLogs->where('type', 'check_in')->sortByDesc('created_at')->first(); if ($checkInLog && class_exists(\Modules\BreakSystem\App\Models\AttendanceBreak::class)) { $runningBreak = \Modules\BreakSystem\App\Models\AttendanceBreak::where('attendance_log_id', $checkInLog->id) ->whereNull('end_time') ->first(); $isOnBreak = (bool) $runningBreak; } } } } @endphp
{{ now()->format('l, F j, Y') }}