@php $users = []; if ($report && isset($report->users)) { $users = is_array($report->users) ? $report->users : array_values((array) $report->users); } $metrics = []; if (count($users)) { $first = is_object($users[0]) ? $users[0] : (object) $users[0]; if (isset($first->metrics)) { $metrics = is_array($first->metrics) ? $first->metrics : array_values((array) $first->metrics); } } $positionColumns = ['Zone', 'Region', 'Area', 'Territory']; $positionValue = function ($user, $column) { $user = is_object($user) ? $user : (object) $user; $positions = $user->positions ?? null; if ($positions === null || $positions === '') { return ''; } $positions = is_object($positions) ? (array) $positions : $positions; if (!is_array($positions)) { return ''; } foreach ($positions as $key => $value) { if (strcasecmp((string) $key, $column) === 0) { return $value; } } return ''; }; $formatDate = function ($value) { if ($value === null || $value === '') { return ''; } if (is_numeric($value)) { return date('d M Y', (int) $value); } $ts = strtotime((string) $value); return $ts ? date('d M Y', $ts) : (string) $value; }; @endphp @if($title || $performance_period || $start_date || $end_date)

@if($title) {{ $title }} @endif @if($performance_period)  |  {{ ucfirst($performance_period) }} @endif @if($start_date || $end_date)  |  {{ $formatDate($start_date) }} – {{ $formatDate($end_date) }} @endif @if($report && isset($report->recipient->name))  |  {{ $report->recipient->name }} @endif @if($report && isset($report->total_users))  |  {{ $report->total_users }} users @endif

@endif @if(!count($users))

No leaderboard data found.

@else
@foreach($positionColumns as $positionCol) @endforeach @foreach($metrics as $metric) @endforeach @foreach($users as $index => $user) @foreach($positionColumns as $positionCol) @endforeach @foreach($metrics as $metricCol) @php $cell = null; if (isset($user->metrics) && is_array($user->metrics)) { foreach ($user->metrics as $userMetric) { if (($userMetric->metric ?? '') === ($metricCol->metric ?? '')) { $cell = $userMetric; break; } } } @endphp @endforeach @endforeach
Rank User Employee Code Designation / Position{{ $positionCol }}Score{{ $metric->name ?? $metric->metric }}
{{ $index + 1 }}
@if(!empty($user->avatar)) @endif {{ $user->name ?? '' }}
{{ $user->employee_code ?? '' }} {{ $user->designation ?? '' }} @if(!empty($user->position_name))
{{ $user->position_name }} @endif
{{ $positionValue($user, $positionCol) }}{{ $user->score ?? 0 }} @if($cell) @php $target = $cell->target ?? null; $hasTarget = $target !== null && $target !== '' && (float) $target > 0; @endphp {{ $cell->value ?? 0 }}@if($hasTarget) / {{ $target }}@endif
Average: {{ $cell->previous_average ?? 0 }} @if($hasTarget)
Target: {{ $target }}
@if(!empty($cell->completed)) Completed @else Not completed @endif @endif @else — @endif
@endif