@php use App\Services\Targets\SalesForecastService; use App\Services\Targets\SalesScoreService; use App\Support\SalesPerformanceMetrics; $forecastPaceBadgeClasses = [ SalesForecastService::PACE_AHEAD => 'bg-green-100 text-green-800 border-green-200', SalesForecastService::PACE_ON_TRACK => 'bg-indigo-100 text-indigo-900 border-indigo-200', SalesForecastService::PACE_AT_RISK => 'bg-amber-100 text-amber-900 border-amber-200', SalesForecastService::PACE_BEHIND => 'bg-red-100 text-red-800 border-red-200', SalesForecastService::PACE_NO_TARGET => 'bg-gray-100 text-gray-700 border-gray-200', SalesForecastService::PACE_NO_ELAPSED_DAYS => 'bg-gray-100 text-gray-600 border-gray-200', ]; $forecastPaceLabels = [ SalesForecastService::PACE_AHEAD => 'Ahead', SalesForecastService::PACE_ON_TRACK => 'On track', SalesForecastService::PACE_AT_RISK => 'At risk', SalesForecastService::PACE_BEHIND => 'Behind', SalesForecastService::PACE_NO_TARGET => 'No targets', SalesForecastService::PACE_NO_ELAPSED_DAYS => 'Period not started', ]; $statusBadgeClasses = [ SalesScoreService::STATUS_NO_TARGETS => 'bg-gray-100 text-gray-700 border-gray-200', SalesScoreService::STATUS_BEHIND => 'bg-red-100 text-red-800 border-red-200', SalesScoreService::STATUS_ON_TRACK => 'bg-amber-100 text-amber-900 border-amber-200', SalesScoreService::STATUS_STRONG => 'bg-indigo-100 text-indigo-900 border-indigo-200', SalesScoreService::STATUS_TOP_PERFORMER => 'bg-green-100 text-green-800 border-green-200', 'achieved' => 'bg-green-100 text-green-800 border-green-200', 'no_target' => 'bg-gray-100 text-gray-600 border-gray-200', ]; $statusLabels = [ SalesScoreService::STATUS_NO_TARGETS => 'No targets', SalesScoreService::STATUS_BEHIND => 'Behind', SalesScoreService::STATUS_ON_TRACK => 'On track', SalesScoreService::STATUS_STRONG => 'Strong', SalesScoreService::STATUS_TOP_PERFORMER => 'Top performer', 'achieved' => 'Achieved', 'no_target' => 'No target', 'behind' => 'Behind', 'on_track' => 'On track', ]; $scoringModeLabels = [ SalesScoreService::SCORING_MODE_FULL => 'Activity + sales performance', SalesScoreService::SCORING_MODE_ACTIVITY_ONLY => 'Activity targets only', SalesScoreService::SCORING_MODE_PERFORMANCE_ONLY => 'Sales performance targets only', SalesScoreService::SCORING_MODE_NONE => 'No targets configured', ]; $finalScore = $score['final_score'] ?? null; $overallStatus = (string) ($score['status'] ?? SalesScoreService::STATUS_NO_TARGETS); $overallBadge = $statusBadgeClasses[$overallStatus] ?? $statusBadgeClasses[SalesScoreService::STATUS_NO_TARGETS]; $overallLabel = $statusLabels[$overallStatus] ?? ucfirst(str_replace('_', ' ', $overallStatus)); $activityPillar = $score['pillars']['activity'] ?? []; $performancePillar = $score['pillars']['performance'] ?? []; $activityConfiguredCount = collect($activityPillar['metrics'] ?? []) ->filter(fn ($m) => ($m['configured'] ?? false) === true) ->count(); $performanceConfiguredCount = collect($performancePillar['metrics'] ?? []) ->filter(fn ($m) => ($m['configured'] ?? false) === true) ->count(); $performanceBreakdownMetrics = collect($performancePillar['metrics'] ?? []) ->filter(fn (array $metric) => SalesPerformanceMetrics::isTargetable((string) ($metric['code'] ?? ''))) ->values() ->all(); $formatMetricValue = function (array $metric, string $field): string { $value = $metric[$field] ?? 0; if (($metric['value_type'] ?? 'count') === 'money') { return format_rand($value); } return number_format((float) $value, 0, '.', ','); }; @endphp {{ __('My Performance') }}

@if (! empty($isManagerPersonal)) Team performance for {{ $reportingPeriod->label() }} @if (($managedSalesmanCount ?? 0) > 0) ({{ number_format((int) $managedSalesmanCount) }} assigned {{ (int) $managedSalesmanCount === 1 ? 'salesperson' : 'salespeople' }}) @else (no salespeople assigned) @endif @else Viewing {{ $reportingPeriod->label() }} @endif

@php $cardCount = count($progressCards ?? []); $gridCols = match (true) { $cardCount >= 4 => 'md:grid-cols-4', $cardCount === 3 => 'md:grid-cols-3', $cardCount === 2 => 'md:grid-cols-2', default => 'md:grid-cols-1', }; @endphp
@foreach (($progressCards ?? []) as $card) @endforeach
@if ($finalScore !== null && (($insights['strengths'] ?? []) !== [] || ($insights['weaknesses'] ?? []) !== []))

Strengths

    @forelse (($insights['strengths'] ?? []) as $item)
  • {{ $item['label'] }} {{ number_format($item['capped_percent'], 0) }}%
  • @empty
  • No configured metrics yet.
  • @endforelse

Areas to improve

    @forelse (($insights['weaknesses'] ?? []) as $item)
  • {{ $item['label'] }} {{ number_format($item['capped_percent'], 0) }}%
  • @empty
  • No configured metrics yet.
  • @endforelse
@endif @if (! empty($conversionMetrics)) @endif @if (($salesLeaderboard ?? []) !== [])

{{ ! empty($isManagerPersonal) ? 'My Team Leaderboard' : 'Sales Leaderboard' }}

{{ ! empty($isManagerPersonal) ? 'Rankings for salespeople assigned to you this month.' : 'Overall salesperson rankings for this month.' }}

@foreach ($salesLeaderboard as $row) ($row['user_id'] ?? 0) === ($currentUserId ?? 0), ])> @endforeach
Rank Salesperson Units Sold Gross Profit Sales Score
{{ (int) ($row['rank'] ?? 0) }} {{ $row['name'] ?? '—' }} @if (($row['user_id'] ?? 0) === ($currentUserId ?? 0)) You @endif @if (! empty($row['top_units_sold'])) Top units @endif @if (! empty($row['top_gross_profit'])) Top GP @endif @if (! empty($row['top_sales_score'])) Top score @endif {{ number_format((int) ($row['units_sold'] ?? 0)) }} {{ format_rand((float) ($row['gross_profit'] ?? 0)) }} {{ ($row['sales_score'] ?? null) !== null ? number_format((float) $row['sales_score'], 1) : '—' }}
@endif @include('my-performance.partials.forecast-projection')

Activity breakdown

@foreach (($activityPillar['metrics'] ?? []) as $metric) @php $rowStatus = (string) ($metric['status'] ?? 'no_target'); $rowBadge = $statusBadgeClasses[$rowStatus] ?? $statusBadgeClasses['no_target']; $rowLabel = $statusLabels[$rowStatus] ?? ucfirst($rowStatus); @endphp ! ($metric['configured'] ?? false)])> @endforeach
Metric Target Actual Achievement % Weight Weighted score Status
{{ $metric['label'] }} {{ $formatMetricValue($metric, 'target') }} {{ $formatMetricValue($metric, 'actual') }} @if ($metric['configured'] ?? false) {{ number_format((float) $metric['achievement_percent'], 1) }}% @else — @endif {{ ($metric['configured'] ?? false) ? number_format((float) $metric['effective_weight'], 1).'%' : '—' }} {{ $metric['weighted_score'] !== null ? number_format((float) $metric['weighted_score'], 1) : '—' }} {{ $rowLabel }}

Performance breakdown

@foreach ($performanceBreakdownMetrics as $metric) @php $rowStatus = (string) ($metric['status'] ?? 'no_target'); $rowBadge = $statusBadgeClasses[$rowStatus] ?? $statusBadgeClasses['no_target']; $rowLabel = $statusLabels[$rowStatus] ?? ucfirst($rowStatus); @endphp ! ($metric['configured'] ?? false)])> @endforeach
Metric Target Actual Achievement % Weight Weighted score Status
{{ $metric['label'] }} {{ $formatMetricValue($metric, 'target') }} {{ $formatMetricValue($metric, 'actual') }} @if ($metric['configured'] ?? false) {{ number_format((float) $metric['achievement_percent'], 1) }}% @else — @endif {{ ($metric['configured'] ?? false) ? number_format((float) $metric['effective_weight'], 1).'%' : '—' }} {{ $metric['weighted_score'] !== null ? number_format((float) $metric['weighted_score'], 1) : '—' }} {{ $rowLabel }}