@php $pageConfig = $pageConfig ?? []; $pageTitle = (string) ($pageConfig['title'] ?? 'Targets vs Actuals'); $formRoute = (string) ($pageConfig['formRoute'] ?? 'targets-vs-actuals.sales'); $teamLabel = (string) ($pageConfig['teamLabel'] ?? 'Team'); $filterUserLabel = (string) ($pageConfig['filterUserLabel'] ?? 'Person'); $filterAllUsersLabel = (string) ($pageConfig['filterAllUsersLabel'] ?? 'All'); $entityCountLabel = (string) ($pageConfig['entityCountLabel'] ?? 'person(s)'); $tablePersonColumn = (string) ($pageConfig['tablePersonColumn'] ?? 'Person'); $chartCanvasId = (string) ($pageConfig['chartCanvasId'] ?? 'targets-vs-actuals-chart'); $showCharts = (bool) ($showCharts ?? true); $showAssignedSalesmanCount = (bool) ($pageConfig['showAssignedSalesmanCount'] ?? false); $showTeamLabel = (bool) ($pageConfig['showTeamLabel'] ?? true); $metricFilterOptions = $metricFilterOptions ?? []; $selectedMetricKey = (string) ($selectedMetricKey ?? ''); $activityStatusBadgeClasses = [ 'behind' => 'bg-red-100 text-red-800 border-red-200', 'on_track' => 'bg-amber-100 text-amber-900 border-amber-200', 'achieved' => 'bg-green-100 text-green-800 border-green-200', 'no_target' => 'bg-gray-100 text-gray-700 border-gray-200', ]; $activityStatusLabels = [ 'behind' => 'Behind', 'on_track' => 'On track', 'achieved' => 'Achieved', 'no_target' => 'No target set', ]; $monthNames = [ 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December', ]; $monthSelectOptions = []; foreach ($monthNames as $num => $label) { $monthSelectOptions[] = ['value' => (string) $num, 'label' => $label]; } $yearSelectOptions = collect($yearOptions ?? [])->map(fn ($y) => ['value' => (string) $y, 'label' => (string) $y])->all(); $periodTypeOptions = [ ['value' => 'daily', 'label' => 'Daily'], ['value' => 'weekly', 'label' => 'Weekly'], ['value' => 'monthly', 'label' => 'Monthly'], ]; $userFilterOptions = [['value' => '', 'label' => $filterAllUsersLabel]]; foreach (($users ?? []) as $u) { $uName = trim(($u->name ?? '').' '.($u->surname ?? '')); $userFilterOptions[] = [ 'value' => (string) $u->id, 'label' => $uName !== '' ? $uName : 'User #'.$u->id, ]; } $chartMetricOptions = $chartMetricOptions ?? []; $chartMetricKey = (string) ($chartMetricKey ?? 'performance:gross_profit'); $chartsByKey = $chartsByKey ?? []; @endphp {{ __($pageTitle) }}
@if ($showTeamLabel)

{{ $teamLabel }}

@endif

{{ number_format(count($userGroups ?? [])) }} {{ $entityCountLabel }}

@if ($showCharts)

Targets vs actuals

Team totals for the selected filters (no forecasts).

No target data is available for this metric in the selected period.
@else

Activity & sales performance

Aggregated actuals for salespeople assigned to each manager. Period: {{ $periodRangeLabel ?? '' }}.

@endif
@if ($showAssignedSalesmanCount) @endif @forelse (($userGroups ?? []) as $group) @php $userId = (int) $group['user_id']; $groupAvg = (float) ($group['average_achievement_percent'] ?? 0); $metricCount = count($group['activities'] ?? []); @endphp @if ($showAssignedSalesmanCount) @endif @foreach (($group['activities'] ?? []) as $row) @php $status = (string) ($row['status'] ?? 'no_target'); $badgeClass = $activityStatusBadgeClasses[$status] ?? $activityStatusBadgeClasses['no_target']; $statusLabel = $activityStatusLabels[$status] ?? $status; $hasTarget = (bool) ($row['has_target'] ?? false); $percent = (float) ($row['achievement_percent'] ?? 0); $valueType = (string) ($row['value_type'] ?? 'count'); $targetDisplay = $valueType === 'money' ? format_rand((float) ($row['target'] ?? 0)) : number_format((int) ($row['target'] ?? 0)); $actualDisplay = $valueType === 'money' ? format_rand((float) ($row['actual'] ?? 0)) : number_format((int) ($row['actual'] ?? 0)); $remainingDisplay = $valueType === 'money' ? format_rand((float) ($row['remaining'] ?? 0)) : number_format((int) ($row['remaining'] ?? 0)); @endphp @if ($showAssignedSalesmanCount) @endif @endforeach @empty @endforelse
{{ $tablePersonColumn }}SalespeopleMetric Period Target Actual Remaining Achievement Status
{{ $group['user_name'] }} ({{ $metricCount }} metrics) {{ number_format((int) ($group['assigned_salesman_count'] ?? 0)) }} Summary {{ number_format($groupAvg, $groupAvg === floor($groupAvg) ? 0 : 1) }}% avg Expand for detail
{{ $row['metric_label'] ?? '—' }} {{ $row['period_label'] ?? '—' }} {{ $targetDisplay }} {{ $actualDisplay }} {{ $remainingDisplay }} @if ($hasTarget) {{ number_format($percent, $percent === floor($percent) ? 0 : 1) }}% @else — @endif {{ $statusLabel }}
No results for the selected filters.