@foreach ($dateRanges as $dateRange)
@php
$isWeekOff = false;
$islate = false;
$weekNameColumn = strtolower(substr($dateRange->format('D'), 0, 2));
if($weekNameColumn == 'sa' && $emp->{$weekNameColumn.'_duration'} )
$minCompletionHour = $emp->{$weekNameColumn.'_duration'};
else
$minCompletionHour = $emp->work_duration ?? $settings['MIN_COMPLETION_HOUR'];
$clonedDate = clone($dateRange);
$currentDate = $clonedDate->toDateString();
$nextDate = $clonedDate->addDay()->toDateString();
$hasPunch = 0;
$hasShift = 0;
if($emp->is_rotational == 0 && $dateRange->isWeekend() && !$emp->{$weekNameColumn.'_duration'}){ $isWeekOff = true; }
else
{
$hasShift = $emp->is_rotational == 0 ? 0 : $emp->empShifts->where('from_date', '>=', $currentDate)->where('from_date', '<', $nextDate)->first();
$isWeekOff = $hasShift && $hasShift->in_time == 'wo' ? true : false;
}
$hasPunch = $emp->punches->where('punch_date', '>=', $currentDate)->where('punch_date', '<', $nextDate)->first();
$hasLeaveApplied = $emp->punches->where('punch_date', '>=', $currentDate)->where('punch_date', '<', $nextDate)->where('leave_type_id', '!=', null)->first();
@endphp
{{ $dateRange->format('d') }}
{{ substr($dateRange->format('D'), 0, 2) }}
@if($hasLeaveApplied)
{{ $leavesArray[$hasLeaveApplied->leave_type_id] }}
@elseif ($isWeekOff)
{{-- @if(!$hasShift && $hasPunch && $hasPunch->punch_by == '0' ) --}}
@if($hasPunch && $hasPunch->punch_by == '0' )
@php $actualPresent++; @endphp
{{ Carbon\Carbon::parse($hasPunch->check_in)->format('h:i A') }}
{{ $hasPunch->check_out ? ( Carbon\Carbon::parse($hasPunch->check_out)->gt(Carbon\Carbon::parse($hasPunch->check_in)->addMinutes(5)) ? Carbon\Carbon::parse($hasPunch->check_out)->format('h:i A') : '-' ) : '-' }}
{{ $hasPunch->duration_in_minute }}
@else
@php $weekOffs++; @endphp
@endif
@else
@if($hasShift && array_key_exists( $hasShift->in_time, $otherLeavesArray ) )
@php $actualPresent++; @endphp
{{ $otherLeavesArray[$hasShift->in_time] }}
@elseif( in_array( $dateRange->format('Y-m-d'), $holidaysArray ) )
@if($hasPunch && $hasPunch->punch_by == '0')
@php $actualPresent++; @endphp
{{ Carbon\Carbon::parse($hasPunch->check_in)->format('h:i A') }}
{{ $hasPunch->check_out ? ( Carbon\Carbon::parse($hasPunch->check_out)->gt(Carbon\Carbon::parse($hasPunch->check_in)->addMinutes(5)) ? Carbon\Carbon::parse($hasPunch->check_out)->format('h:i A') : '-' ) : '-' }}
{{ $hasPunch->duration_in_minute }}
@else
@php $holidayCount++; @endphp
@endif
@elseif (!$hasPunch)
@php $absendDays++; @endphp
@elseif ( $hasPunch->punch_by == '2' )
{{ $leavesArray[$hasPunch->leave_type_id] }}
@elseif( $hasPunch->check_in )
@php
$actualPresent++;
$isNightShift = false;
if( $hasShift)
{
if(
Carbon\Carbon::today()->startOfDay()->diffInMinutes(substr($hasPunch->check_in, 11)) >
Carbon\Carbon::today()->startOfDay()->diffInMinutes( Carbon\Carbon::parse($hasShift->in_time)->addMinutes($latemarkGraceTime) )
)
{
$latemark++; $islate = true;
}
if($hasShift->is_night == 1)
$isNightShift = true;
}
elseif( $emp->is_rotational == 0 &&
Carbon\Carbon::today()->startOfDay()->diffInMinutes(substr($hasPunch->check_in, 11)) >
Carbon\Carbon::today()->startOfDay()->diffInMinutes( Carbon\Carbon::parse($emp->shift?->from_time ?? $defaultShift['from_time'])->addMinutes($latemarkGraceTime) )
)
{ $latemark++; $islate = true; }
if( !$isNightShift && $hasPunch->duration < $minCompletionHour) {$shortDays++;}
@endphp
@if ( $isNightShift )
@php
$nextDayPunch = $emp->punches->where('punch_date', '>', $nextDate)->first();
$checkIn = $hasPunch->check_out ?? $hasPunch->check_in;
$checkOut = $nextDayPunch ? $nextDayPunch->check_in : '';
$duration = $checkOut ? Carbon\Carbon::parse( $checkIn )->diffInSeconds( $checkOut ) : 0;
if($duration < $minCompletionHour) {$shortDays++;}
@endphp
{{ Carbon\Carbon::parse($checkIn)->format('h:i A') }}
{{ $checkOut ? Carbon\Carbon::parse($checkOut)->format('h:i A') : '-' }}
{{ gmdate("H:i", $duration) }}
@else
{{ Carbon\Carbon::parse($hasPunch->check_in)->format('h:i A') }}
{{ $hasPunch->check_out ? ( Carbon\Carbon::parse($hasPunch->check_out)->gt(Carbon\Carbon::parse($hasPunch->check_in)->addMinutes(5)) ? Carbon\Carbon::parse($hasPunch->check_out)->format('h:i A') : '-' ) : '-' }}
{{ $hasPunch->duration_in_minute }}
@endif
@else
-
-
-
@endif
@endif