@php use App\Models\RosterTemplate; use App\Models\RosterAssign; use App\Models\LeaveRequest; use App\Models\PublicHoliday; use Carbon\Carbon; function AM_PM($TIME) { $time = new DateTime($TIME); $time = str_replace('M', '', $time->format('g:i A')); $time = str_replace(' ', '', $time); $time = str_replace(':00', '', $time); return $time; } function calculate_time_difference($start_time, $end_time, $break_minutes) { $time_format = 'H:i:s'; $start_datetime = DateTime::createFromFormat($time_format, $start_time); $end_datetime = DateTime::createFromFormat($time_format, $end_time); $time_difference_seconds = $end_datetime->getTimestamp() - $start_datetime->getTimestamp(); $break_minutes = $break_minutes * 60; return round(($time_difference_seconds - $break_minutes) / 3600, 2); } function hasShiftConflict($shifts, $currentShift) { $currentStartDateTime = Carbon::createFromFormat('H:i:s', $currentShift['roster_template']['start_time']); $currentEndDateTime = Carbon::createFromFormat('H:i:s', $currentShift['roster_template']['end_time']); foreach ($shifts as $shift) { if ($shift === $currentShift) { continue; // Skip checking against itself } $startDateTime = Carbon::createFromFormat('H:i:s', $shift['roster_template']['start_time']); $endDateTime = Carbon::createFromFormat('H:i:s', $shift['roster_template']['end_time']); // Check for overlap if ($currentStartDateTime < $endDateTime && $currentEndDateTime > $startDateTime) { return true; // Conflict found } } return false; // No conflicts found } $total_hour = 0; @endphp
@foreach ($dates_array as $date) @php $dateTime = new DateTime($date); $hour_date_wise[$date] = 0; @endphp @endforeach @foreach ($users as $user) @f oreach ($dates_array as $date) @endforeach @endforeach @foreach ($dates_array as $date) @endforeach
CUSTOM {{ $dateTime->format('D d') }}
@php $shifts_of_this_box = RosterAssign::with('rosterTemplate') ->where(['assign_to' => $user->id, 'schedule_date' => $date]) ->get(); $holiday = PublicHoliday::where('from', '<=', $date) ->where('to', '>=', $date) ->first(); $leave = LeaveRequest::where('employee_id', $user->id) ->where('status', '!=', '2') ->where('from', '<=', $date) ->where('to', '>=', $date) ->first(); @endphp
@if ($holiday)
Holiday: {{ $holiday->title }}
Holiday: {{ $holiday->title }}
@php $holiday_conflict = 1; @endphp @else @php $holiday_conflict = 0; @endphp @endif @if ($leave)
Leave: {{ $leave->leavepackage->title ?? ''}}
@if (in_array('Roster Maintain', Session::get('permissions'))) @endif
@php $leave_conflict = 0; @endphp @endif @foreach ($shifts_of_this_box as $shift) @php $conflict = hasShiftConflict( json_decode($shifts_of_this_box, true), json_decode($shift, true), ); $shift = json_decode($shift, true); $hour = calculate_time_difference( $shift['roster_template']['start_time'], $shift['roster_template']['end_time'], $shift['roster_template']['break_minutes'], ); $total_hour += $hour; $hour_date_wise[$date] += $hour; if ($leave) { if ($leave->full_day == '1') { $leave_conflict = 1; } else { $startTime = DateTime::createFromFormat( 'H:i:s', $leave->start_time, ); $endTime = DateTime::createFromFormat('H:i:s', $leave->end_time); $shiftStartTime = DateTime::createFromFormat( 'H:i:s', $shift['roster_template']['start_time'], ); $shiftEndTime = DateTime::createFromFormat( 'H:i:s', $shift['roster_template']['end_time'], ); if ($startTime >= $shiftStartTime && $endTime <= $shiftEndTime) { $leave_conflict = 1; } else { $leave_conflict = 0; } } } else { $leave_conflict = 0; } @endphp
{{ AM_PM($shift['roster_template']['start_time']) }} - {{ AM_PM($shift['roster_template']['end_time']) }} @if ($shift['roster_template']['repeat_shift'] == '1') @else @endif @if ($conflict || $holiday_conflict || $leave_conflict) @else @endif
@if (in_array('Roster Maintain', Session::get('permissions'))) @endif @if ($conflict || $holiday_conflict || $leave_conflict) @endif @if (in_array('Roster Maintain', Session::get('permissions'))) @endif
@endforeach
Assigned total {{ $total_hour }} hours
{{ $hour_date_wise[$date] }}
@php $html = ''; $pages_btn = ''; $count = intval($count) < $per_page ? 1 : intval($count) / $per_page; $count = ceil($count); $c = 0; @endphp