Leads Analytics
{{-- KPI row --}}

{{ $conversion_rate }}%

Conversion Rate

{{ $avg_convert_days }}

Avg Days to Win

{{ $total_won }}

Total Won

{{ $total_lost }}

Total Lost

@php $stageOrder = ['new','contacted','trial','negotiation','won','lost']; $stageBadge = ['new'=>'bg-blue-100 text-blue-700','contacted'=>'bg-yellow-100 text-yellow-700','trial'=>'bg-purple-100 text-purple-700','negotiation'=>'bg-orange-100 text-orange-700','won'=>'bg-green-100 text-green-700','lost'=>'bg-red-100 text-red-600']; $stageColors = ['new'=>'#3b82f6','contacted'=>'#eab308','trial'=>'#a855f7','negotiation'=>'#f97316','won'=>'#22c55e','lost'=>'#ef4444']; $sourceLabels = ['walk_in'=>'Walk-in','website'=>'Website','phone'=>'Phone','referral'=>'Referral','social_media'=>'Social','google_ads'=>'Google Ads','trial_pass'=>'Trial Pass','other'=>'Other']; $totalLeads = array_sum(array_map(fn($s) => $by_stage[$s] ?? 0, $stageOrder)); $funnelStages = array_filter(array_map(fn($s) => [ 'stage' => $s, 'count' => $by_stage[$s] ?? 0, 'pct' => $totalLeads > 0 ? round(($by_stage[$s] ?? 0) / $totalLeads * 100) : 0, ], array_filter($stageOrder, fn($s) => $s !== 'lost'))); $maxSource = max(array_column($by_source ?? [['count'=>1]], 'count') ?: [1]); $maxTrend = max(array_column($weekly_trend ?? [['leads'=>1]], 'leads') ?: [1]); @endphp
{{-- Pipeline funnel --}}

🔽 Pipeline Funnel

@foreach($funnelStages as $item)
{{ $item['stage'] }}
{{ $item['count'] }} ({{ $item['pct'] }}%)
@endforeach
Total tracked: {{ $totalLeads }} Lost: {{ $by_stage['lost'] ?? 0 }}
{{-- Weekly trend --}}

📈 Weekly Trend

@foreach($weekly_trend ?? [] as $wk)
{{ $wk['label'] }}
@endforeach
New Leads Won
{{-- Leads by source --}}

Leads by Source

@forelse($by_source ?? [] as $row)
{{ $sourceLabels[$row['source']] ?? $row['source'] }}
{{ $row['count'] }}
@empty
No data.
@endforelse
{{-- Won by source --}}

Conversions by Source

@php $maxWon = max(array_values($won_by_source ?? [0]) ?: [1]); @endphp
@forelse($won_by_source ?? [] as $src => $count)
{{ $sourceLabels[$src] ?? $src }}
{{ $count }}
@empty
No conversions yet.
@endforelse

Which sources close the most deals.