@php use App\Services\ActivityTargets\ActivityTargetAssignment; $filters = $filters ?? [ 'metric_code' => null, 'period_type' => null, 'assignment_type' => null, 'is_active' => null, ]; $metrics = $metrics ?? []; $targetableMetrics = $targetableMetrics ?? $metrics; $metricLabels = $metricLabels ?? []; $metricValueTypes = $metricValueTypes ?? []; $filterQuery = $filterQuery ?? []; $metricOptions = [['value' => '', 'label' => 'Select a metric…']]; foreach ($targetableMetrics as $metricDef) { $metricOptions[] = ['value' => (string) $metricDef['code'], 'label' => (string) $metricDef['label']]; } $metricFilterMetricDefs = $metrics; $assignmentTypeOptions = [ ['value' => ActivityTargetAssignment::TYPE_DEALER, 'label' => 'Dealer-wide'], ['value' => ActivityTargetAssignment::TYPE_USER, 'label' => 'Specific user'], ['value' => ActivityTargetAssignment::TYPE_ROLE, 'label' => 'Role'], ]; $userOptions = [['value' => '', 'label' => 'Select a user…']]; foreach (($users ?? []) as $u) { $uName = trim(($u->name ?? '').' '.($u->surname ?? '')); $userOptions[] = ['value' => (string) $u->id, 'label' => $uName !== '' ? $uName : 'User #'.$u->id]; } $roleOptions = [['value' => '', 'label' => 'Select a role…']]; foreach (($assignableRoles ?? []) as $role) { $roleOptions[] = ['value' => (string) $role, 'label' => (string) $role]; } $periodTypeOptions = [ ['value' => 'daily', 'label' => 'Daily'], ['value' => 'weekly', 'label' => 'Weekly'], ['value' => 'monthly', 'label' => 'Monthly'], ]; $pageConfig = $pageConfig ?? []; $indexRoute = (string) ($pageConfig['indexRoute'] ?? 'sales-performance-targets.index'); $storeRoute = (string) ($pageConfig['storeRoute'] ?? 'sales-performance-targets.store'); $deactivateRouteName = (string) ($pageConfig['deactivateRouteName'] ?? 'sales-performance-targets.deactivate'); $emptyMessage = (string) ($pageConfig['emptyMessage'] ?? 'No sales performance targets match these filters.'); $config = $salesPerformanceConfig ?? []; $deactivateFormRef = (string) ($config['deactivateFormRef'] ?? 'salesPerformanceDeactivateForm'); $managerUserOnly = (bool) ($managerUserOnly ?? ($config['managerUserOnly'] ?? false)); $modalIdPrefix = (string) ($config['modalIdPrefix'] ?? ''); $summaryMetrics = [ ['label' => 'Total', 'key' => 'total'], ['label' => 'Active', 'key' => 'active', 'value_class' => 'text-emerald-700'], ['label' => 'Inactive', 'key' => 'inactive', 'value_class' => 'text-gray-600'], ]; @endphp
@if (! empty($sectionTitle))

{{ $sectionTitle }}

@endif
@if ($showFlashMessages ?? false) @endif
@foreach ($summaryMetrics as $metric)
{{ $metric['label'] }}
{{ number_format((int) data_get($summary ?? [], $metric['key'], 0)) }}
@endforeach
@php $metricFilterOptions = array_merge( [['value' => '', 'label' => 'All metrics']], collect($metricFilterMetricDefs)->map(fn (array $metricDef) => [ 'value' => (string) $metricDef['code'], 'label' => (string) $metricDef['label'], ])->values()->all(), ); $periodFilterOptions = [ ['value' => '', 'label' => 'All periods'], ['value' => 'daily', 'label' => 'Daily'], ['value' => 'weekly', 'label' => 'Weekly'], ['value' => 'monthly', 'label' => 'Monthly'], ]; $assignmentFilterOptions = $managerUserOnly ? [ ['value' => '', 'label' => 'All managers'], ['value' => ActivityTargetAssignment::TYPE_USER, 'label' => 'Branch Manager'], ] : [ ['value' => '', 'label' => 'All assignments'], ['value' => ActivityTargetAssignment::TYPE_DEALER, 'label' => 'Dealer-wide'], ['value' => ActivityTargetAssignment::TYPE_USER, 'label' => 'Specific user'], ['value' => ActivityTargetAssignment::TYPE_ROLE, 'label' => 'Role'], ]; $statusFilterOptions = [ ['value' => '', 'label' => 'All statuses'], ['value' => '1', 'label' => 'Active'], ['value' => '0', 'label' => 'Inactive'], ]; @endphp
@if (! $managerUserOnly)
@endif

{{ number_format(count($targets ?? [])) }} target(s)

@forelse ($targetGroups ?? [] as $scopeGroup) @php $scopeKey = $scopeGroup['key']; $scopeTargets = $scopeGroup['targets']; $scopeActiveCount = $scopeTargets->where('is_active', true)->count(); @endphp @foreach ($scopeGroup['period_groups'] as $periodGroup) @php $periodKey = $periodGroup['key']; $periodTargets = $periodGroup['targets']; $periodActiveCount = $periodTargets->where('is_active', true)->count(); @endphp @if ($periodTargets->isNotEmpty()) @foreach ($periodTargets as $target) @php $rowMetricLabel = $metricLabels[$target->metric_code] ?? $target->metric_code; $rowValueType = $metricValueTypes[$target->metric_code] ?? 'count'; $rowTargetDisplay = $rowValueType === 'money' ? format_rand($target->target_value) : (string) (int) round((float) $target->target_value); @endphp @endforeach @endif @endforeach @empty @endforelse
Metric Period Target Starts Ends Status
{{ $scopeGroup['label'] }} {{ $scopeTargets->count() }} {{ $scopeTargets->count() === 1 ? 'target' : 'targets' }} @if ($scopeActiveCount < $scopeTargets->count()) · {{ $scopeActiveCount }} active @endif
{{ $periodGroup['label'] }} {{ $periodTargets->count() }}@if ($periodActiveCount < $periodTargets->count()) · {{ $periodActiveCount }} active @endif
{{ $rowMetricLabel }} {{ $target->period_type }} {{ $rowTargetDisplay }} {{ $target->starts_at?->format('Y-m-d') ?? '—' }} {{ $target->ends_at?->format('Y-m-d') ?? '—' }} @if ($target->is_active) Active @else Inactive @endif
{{ $emptyMessage }}