@extends('layouts.admin') @section('title','Тімліди') @section('page_title','Тімліди') @section('page_actions') Додати тімліда @endsection @push('head') @endpush @section('content') @php $tz = config('app.timezone', 'Europe/Kyiv'); $selectedMonth = $selectedMonth ?? \Carbon\Carbon::now($tz)->format('Y-m'); $currentMonthKey = $currentMonthKey ?? \Carbon\Carbon::now($tz)->format('Y-m'); $prevMonthKey = $prevMonthKey ?? \Carbon\Carbon::now($tz)->subMonthNoOverflow()->format('Y-m'); $totalTL = $teamLeads->count(); // ✔ Скільки тімлідів виконали норму по балансах (умовно: balance_score >= 90) $completedNorms = $teamLeads->filter(function ($u) use ($teamLeadRatings) { $rating = $teamLeadRatings[$u->id] ?? null; if (!$rating) return false; $balanceScore = $rating['balance_score'] ?? null; return $balanceScore !== null && $balanceScore >= 90; })->count(); // ✔ Скільки мають високий рейтинг по статистиці (умовно: stats_score >= 63) $highStats = $teamLeads->filter(function ($u) use ($teamLeadRatings) { $rating = $teamLeadRatings[$u->id] ?? null; if (!$rating) return false; $statsScore = $rating['stats_score'] ?? null; return $statsScore !== null && $statsScore >= 63; })->count(); $enriched = $teamLeads->map(function ($u) use ($teamLeadRatings, $totalTL) { $rating = $teamLeadRatings[$u->id] ?? null; $balanceRank = $rating['balance_rank'] ?? null; $statsRank = $rating['stats_rank'] ?? null; $balanceScore = $rating['balance_score'] ?? null; $statsScore = $rating['stats_score'] ?? null; $avgBalanceAmount = $rating['avg_balance_amount'] ?? null; $bestRank = null; if ($balanceRank) { $bestRank = $balanceRank; } if ($statsRank && ($bestRank === null || $statsRank < $bestRank)) { $bestRank = $statsRank; } return [ 'model' => $u, 'balance_rank' => $balanceRank, 'stats_rank' => $statsRank, 'balance_score' => $balanceScore, 'stats_score' => $statsScore, 'avg_balance' => $avgBalanceAmount, 'best_rank' => $bestRank, ]; }); $topThree = $enriched ->filter(fn($row) => $row['best_rank'] !== null) ->sortBy('best_rank') ->take(3) ->values(); @endphp {{-- ВЕРХНЯ ПАНЕЛЬ: ЗАГОЛОВОК + МІСЯЦЬ --}}
Рейтинг тімлідів

Хто тягне зміну вгору

Порівнюємо тімлідів по середніх балансах та статистиці за обраний місяць. Важливо не тільки місце, а й стабільність.

Всього тімлідів {{ $totalTL }}
Виконали норму по балансах {{ $completedNorms }} / {{ $totalTL }}
Високий рейтинг по статистиці {{ $highStats }} / {{ $totalTL }}
@if(isset($monthStart, $monthEnd))
{{ $monthStart }} — {{ $monthEnd }}
@endif
{{-- КОРОТКИЙ ПОДІУМ ТОП-3 --}} @if($topThree->count())
@foreach($topThree as $index => $row) @php /** @var \App\Models\User $uModel */ $uModel = $row['model']; $rank = $row['best_rank']; $balanceScore = $row['balance_score']; $statsScore = $row['stats_score']; $avgBalance = $row['avg_balance']; $podiumClass = 'tl-podium-card--other'; if ($index === 0) $podiumClass = 'tl-podium-card--gold'; if ($index === 1) $podiumClass = 'tl-podium-card--silver'; if ($index === 2) $podiumClass = 'tl-podium-card--bronze'; $initial = mb_substr($uModel->name, 0, 1, 'UTF-8'); @endphp
#{{ $rank }}
{{ $initial }}
{{ $uModel->name }}
@if($balanceScore !== null)
Баланс {{ $balanceScore }}/100
@endif @if($statsScore !== null)
Статистика {{ $statsScore }}/100
@endif @if($avgBalance !== null)
Середній денний баланс {{ number_format($avgBalance, 2) }} $
@endif
@endforeach
@endif {{-- ГОЛОВНИЙ ЛІДЕРБОРД (ТАБЛИЦЯ — DESKTOP/TABLET) --}}
Повний список тімлідів
На телефоні можна скролити таблицю по горизонталі.
@forelse($teamLeads as $u) @php /** @var \App\Models\User $u */ $cabCount = $u->cabinets->count(); $rating = $teamLeadRatings[$u->id] ?? null; $balanceScore = $rating['balance_score'] ?? null; $statsScore = $rating['stats_score'] ?? null; $balanceRank = $rating['balance_rank'] ?? null; $statsRank = $rating['stats_rank'] ?? null; $avgBalanceAmount = $rating['avg_balance_amount'] ?? null; $balanceClass = 'tl-badge-empty'; if ($balanceScore !== null) { if ($balanceScore >= 90) { $balanceClass = 'tl-badge-good'; } elseif ($balanceScore < 60) { $balanceClass = 'tl-badge-bad'; } else { $balanceClass = 'tl-badge-mid'; } } $statsClass = 'tl-badge-empty'; if ($statsScore !== null) { if ($statsScore >= 90) { $statsClass = 'tl-badge-good'; } elseif ($statsScore < 60) { $statsClass = 'tl-badge-bad'; } else { $statsClass = 'tl-badge-mid'; } } $bestRank = null; if ($balanceRank) { $bestRank = $balanceRank; } if ($statsRank && ($bestRank === null || $statsRank < $bestRank)) { $bestRank = $statsRank; } $topLabel = null; if ($bestRank === 1) { $topLabel = 'Топ-1'; } elseif ($bestRank === 2) { $topLabel = 'Топ-2'; } elseif ($bestRank === 3) { $topLabel = 'Топ-3'; } $initial = mb_substr($u->name, 0, 1, 'UTF-8'); @endphp {{-- Імʼя + аватар + міні-ранг --}} {{-- Email + очима тімліда --}} {{-- Кабінети --}} {{-- Рейтинг (баланси) --}} {{-- Рейтинг (статистика) --}} {{-- Дії --}} @empty @endforelse
Тімлід Email / Очима тімліда Кабінети Рейтинг (баланси) Рейтинг (статистика) Дії
{{ $initial }}
{{ $u->name }} @if($topLabel) {{ $topLabel }} @endif
@if($balanceRank) По балансах: #{{ $balanceRank }} із {{ $totalTL }} @endif @if($balanceRank && $statsRank)  •  @endif @if($statsRank) По статистиці: #{{ $statsRank }} із {{ $totalTL }} @endif
@if($cabCount)
@foreach($u->cabinets as $c) {{ $c->slug }} @endforeach
Всього: {{ $cabCount }}
@else @endif
@if($balanceScore !== null)
{{ $balanceScore }} / 100
Середній рейтинг по всіх кабінетах (баланси змін).
@if($avgBalanceAmount !== null)
Сер. денний баланс: {{ number_format($avgBalanceAmount, 2) }} $
@endif @if($balanceRank)
Місце по балансах: #{{ $balanceRank }} із {{ $totalTL }}
@endif @else немає даних
Ще немає рейтингів по балансах.
@endif
@if($statsScore !== null)
{{ $statsScore }} / 100
Середній рейтинг по статистиці (New / Young / Old / Spend).
@if($statsRank)
Місце по статистиці: #{{ $statsRank }} із {{ $totalTL }}
@endif @else немає даних
Ще немає розрахованої статистики.
@endif
Редагувати
Поки немає тімлідів
{{-- МОБІЛЬНИЙ ВИГЛЯД: КАРТКИ ТІМЛІДІВ --}}
@forelse($enriched as $row) @php /** @var \App\Models\User $uModel */ $uModel = $row['model']; $balanceRank = $row['balance_rank']; $statsRank = $row['stats_rank']; $balanceScore = $row['balance_score']; $statsScore = $row['stats_score']; $avgBalance = $row['avg_balance']; $bestRank = $row['best_rank']; $cabCount = $uModel->cabinets->count(); $balanceClass = 'tl-badge-empty'; if ($balanceScore !== null) { if ($balanceScore >= 90) { $balanceClass = 'tl-badge-good'; } elseif ($balanceScore < 60) { $balanceClass = 'tl-badge-bad'; } else { $balanceClass = 'tl-badge-mid'; } } $statsClass = 'tl-badge-empty'; if ($statsScore !== null) { if ($statsScore >= 90) { $statsClass = 'tl-badge-good'; } elseif ($statsScore < 60) { $statsClass = 'tl-badge-bad'; } else { $statsClass = 'tl-badge-mid'; } } $topLabel = null; if ($bestRank === 1) { $topLabel = 'Топ-1'; } elseif ($bestRank === 2) { $topLabel = 'Топ-2'; } elseif ($bestRank === 3) { $topLabel = 'Топ-3'; } $initial = mb_substr($uModel->name, 0, 1, 'UTF-8'); @endphp
{{ $initial }}
{{ $uModel->name }} @if($topLabel) {{ $topLabel }} @endif
@if($balanceRank) Баланси: #{{ $balanceRank }} із {{ $totalTL }} @endif @if($statsRank) Статистика: #{{ $statsRank }} із {{ $totalTL }} @endif
Баланси
@if($balanceScore !== null) {{ $balanceScore }}/100 @if($avgBalance !== null)
Сер. денний баланс: {{ number_format($avgBalance, 2) }} $
@endif @else немає даних @endif
Статистика
@if($statsScore !== null) {{ $statsScore }}/100 @else немає даних @endif
Кабінети ({{ $cabCount }})
@if($cabCount)
@foreach($uModel->cabinets as $c) {{ $c->slug }} @endforeach
@else Тімлід ще не привʼязаний до кабінетів @endif
@empty
Поки немає тімлідів
@endforelse
@endsection