Rapport-Laravel/resources/views/widgets/milestone_team_leaderboard_...

148 lines
6.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@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)
<p class="text-muted mb-2">
@if($title)
<strong>{{ $title }}</strong>
@endif
@if($performance_period)
&nbsp;|&nbsp; {{ ucfirst($performance_period) }}
@endif
@if($start_date || $end_date)
&nbsp;|&nbsp; {{ $formatDate($start_date) }} – {{ $formatDate($end_date) }}
@endif
@if($report && isset($report->recipient->name))
&nbsp;|&nbsp; {{ $report->recipient->name }}
@endif
@if($report && isset($report->total_users))
&nbsp;|&nbsp; {{ $report->total_users }} users
@endif
</p>
@endif
@if(!count($users))
<p class="text-muted mb-0">No leaderboard data found.</p>
@else
<div class="table-responsive">
<table class="table table-centered table-nowrap table-hover table-bordered mb-0">
<thead class="table-light">
<tr>
<th>Rank</th>
<th>User</th>
<th>Employee Code</th>
<th>Designation / Position</th>
@foreach($positionColumns as $positionCol)
<th>{{ $positionCol }}</th>
@endforeach
<th>Score</th>
@foreach($metrics as $metric)
<th>{{ $metric->name ?? $metric->metric }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($users as $index => $user)
<tr>
<td>{{ $index + 1 }}</td>
<td>
<div class="d-flex align-items-center">
@if(!empty($user->avatar))
<img src="{{ $user->avatar }}" alt="" class="rounded-circle me-2" width="32" height="32">
@endif
<span>{{ $user->name ?? '' }}</span>
</div>
</td>
<td>{{ $user->employee_code ?? '' }}</td>
<td>
{{ $user->designation ?? '' }}
@if(!empty($user->position_name))
<br><small class="text-muted">{{ $user->position_name }}</small>
@endif
</td>
@foreach($positionColumns as $positionCol)
<td>{{ $positionValue($user, $positionCol) }}</td>
@endforeach
<td>{{ $user->score ?? 0 }}</td>
@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
<td>
@if($cell)
@php
$target = $cell->target ?? null;
$hasTarget = $target !== null && $target !== '' && (float) $target > 0;
@endphp
{{ $cell->value ?? 0 }}@if($hasTarget) / {{ $target }}@endif
<br>
<small class="text-muted">Average: {{ $cell->previous_average ?? 0 }}</small>
@if($hasTarget)
<br>
<small class="text-muted">Target: {{ $target }}</small>
<br>
@if(!empty($cell->completed))
<span class="badge bg-success">Completed</span>
@else
<span class="badge bg-warning">Not completed</span>
@endif
@endif
@else
—
@endif
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
@endif