subMonths(1); $previousMonthKey = sprintf('%04d-%02d', $previous->getYear(), $previous->getMonth()); $previousMonthName = $previous->format('%B'); $currentJalaliYear = Jalalian::now()->getYear(); $employeeTotals = []; foreach ($data as $employee) { $recordsGrouped = is_array($employee->records) ? $employee->records : (array)$employee->records; $monthlyTotals = []; foreach ($recordsGrouped as $month => $attendances) { $tsec = 0; foreach ($attendances as $attendance) { if (!empty($attendance->duration)) { [$h, $m, $s] = explode(':', $attendance->duration); $tsec += (int)$h * 3600 + (int)$m * 60 + (int)$s; } } $hours = floor($tsec / 3600); $minutes = floor(($tsec % 3600) / 60); $monthlyTotals[$month] = sprintf('%02d:%02d', $hours, $minutes); } $employeeTotals[$employee->id] = $monthlyTotals; } ?> @extends('app') @section('style') @endsection @section('content')
@if(empty($data) || count($data) == 0)

اطلاعاتی موجود نمیباشد

@else
@foreach($data as $employee) @endforeach
@foreach($data as $employee)

{{ $employee->name }}

کارکرد ماه قبل ({{ $previousMonthName }}): {{ $employeeTotals[$employee->id][$previousMonthKey] ?? '00:00' }}
@php $recordsGrouped = is_array($employee->records) ? $employee->records : (array)$employee->records; @endphp @if(empty($recordsGrouped))
رکورد ترددی برای این شخص ثبت نشده است.
@else @php $allMonthKeys = array_keys($recordsGrouped); $recentMonthKeys = array_slice($allMonthKeys, 0, 3); $olderMonthKeys = array_slice($allMonthKeys, 3); $monthLabelOf = function ($month) use ($currentJalaliYear) { if (preg_match('/^(\d{4})-(\d{2})$/', (string) $month, $mm)) { try { $jj = new Jalalian((int) $mm[1], (int) $mm[2], 1); return ((int) $mm[1] === (int) $currentJalaliYear) ? $jj->format('%B') : $jj->format('%B') . ' ' . $mm[1]; } catch (\Throwable $e) { return $month; } } return $month; }; @endphp
@foreach($recentMonthKeys as $month) @endforeach @if(!empty($olderMonthKeys))
@endif
@foreach($recordsGrouped as $month => $records) @endforeach @endif
@endforeach @endif
@endsection