@extends('crm.layouts.master') @section('title','CRM Dashboard') @section('page-css') @endsection @php $welcomeName = explode(' ', trim(Auth::user()->name ?? 'there'))[0]; $isManager = in_array(Auth::user()->access_level, ['Admin', 'Office Manager']); $depositSeries = json_decode($deposit_amount, true) ?: []; $depositCountSeries = json_decode($deposit_count, true) ?: []; $statusLabels = json_decode($lead_status, true) ?: []; $statusCounts = json_decode($status_count, true) ?: []; $qualifiedCount = 0; foreach ($statusLabels as $i => $label) { if ($label === 'FTD') { $qualifiedCount += (int) ($statusCounts[$i] ?? 0); } } $qualifiedPct = $leads > 0 ? min(100, (int) round(($qualifiedCount / max(1, $leads)) * 100)) : 0; $dealsClosed = array_sum($depositCountSeries); $totalRevenue = $tradingStats['total_revenue'] ?? 0; $statusColors = \App\Support\LeadStatusRegistry::badgeClasses(); @endphp @section('main-content')
{{-- Page title --}}

CRM

{{-- ═══════════ Row 1: Welcome + 4 KPI cards ═══════════ --}}
{{-- Welcome card --}}

Good Day,

{{ $welcomeName }}!

{{ now()->format('l, M j Y') }}

{{-- Leads Generated --}}
Leads Generated

0

@if($isManager) ${{ number_format($tradingStats['client_assets'] ?? 0, 0) }} client assets @else All assigned leads @endif

{{-- Qualified Leads --}}
Qualified Leads

0

{{ $qualifiedPct }}% of pipeline

{{-- Revenue Generated --}}
Total Revenue

$0

@if($isManager) {{ $tradingStats['active_clients'] ?? 0 }} active clients @else Deposits approved @endif

{{-- end row 1 --}} {{-- ═══════════ Row 2: Overview + Lead Source ═══════════ --}}

Overview (Last 30 Days)

Revenue

$0

All time

Active Clients

0

Portal

Client Assets

$0

Cash + positions

KYC Pending

0

Review

Lead Source

@if(count($statusLabels))
@foreach($statusLabels as $i => $label)
{{ $label }} {{ $statusCounts[$i] ?? 0 }}
@endforeach
@else

No lead status data yet.

@endif
{{-- end row 2 --}} {{-- ═══════════ Row 3: Deal Status / Recent Leads ═══════════ --}}

Deal Status

View All Clients
@foreach($recentLeads as $lead) @php $statusClass = $statusColors[$lead->status ?? 'New'] ?? 'text-bg-light'; $initial = strtoupper(substr($lead->fname ?? '?', 0, 1)); $bgMap = ['A'=>'primary','B'=>'success','C'=>'info','D'=>'warning','E'=>'danger','F'=>'secondary']; $bg = $bgMap[$initial] ?? 'primary'; $pipelineStatuses = ['Need to call','In Call','Straight to voicemail','No answer','Call back','FTD']; $currentStep = array_search($lead->status ?? 'Need to call', $pipelineStatuses); if ($currentStep === false) $currentStep = 0; $totalSteps = count($pipelineStatuses); @endphp @endforeach
Lead Email Country Agent Pipeline Registered Status
{{ $initial }}
{{ $lead->fname }} {{ $lead->lname }}
{{ $lead->email }} {{ $lead->country ?? '—' }} {{ $lead->user->name ?? '—' }}
{{ $lead->create_date }} {{ $lead->status ?? 'New' }}
{{-- end row 3 --}} {{-- ═══════════ Row 4: Map + Activity + Agent (manager only) ═══════════ --}} @if($isManager)
{{-- Location By Session --}} {{-- Recent Activity --}}

Recent Activity

@forelse($recentActivity as $activity)

{{ Str::limit($activity->description, 60) }}

By {{ $activity->user->name ?? 'System' }} • {{ $activity->created_at ? \Carbon\Carbon::parse($activity->created_at)->diffForHumans() : '' }}

@empty

No recent activity.

@endforelse
{{-- Agent Performance --}}

Agent Performance

{{-- end row 4 --}} {{-- ═══════════ Row 5: Lead Funnel + Lead Lists table ═══════════ --}}

Lead Status Funnel

@if(count($statusLabels))
@else

No funnel data yet.

@endif

Lead Lists

@foreach($leadLists as $list) @endforeach
#List NameOfficeTotal Need to CallCall BackFTDCreated
{{ $list->id }} {{ $list->list_name }} {{ $list->office_names }} {{ $list->total }} {{ $list->need_to_call_count }} {{ $list->call_back_count }} {{ $list->ftd_count }} {{ date('d M Y', strtotime($list->create_date)) }}
@endif {{-- end manager-only rows --}}
{{-- end container-fluid --}} @endsection @section('page-js') @endsection