@php $kpis = $data['kpis'] ?? []; $perDay = $data['per_day'] ?? []; $topExt = $data['top_ext'] ?? []; $departments = $data['departments'] ?? []; $reportType = $data['type'] ?? 'management_summary'; $reportLabel = $schedule->reportTypeLabel(); $companyName = app(\App\Services\PbxDefaultsService::class)->companyName(); $freqLabel = ucfirst($schedule->frequencyLabel()); @endphp @extends('emails.layouts.base', [ 'subject' => "{$companyName} โ€” {$reportLabel}", 'title' => $reportLabel, 'subtitle' => "{$freqLabel} report ยท {$fromDate} โ€“ {$toDate}", 'icon' => '๐Ÿ“Š', 'iconColor' => '#3b82f6', ]) @section('content') {{-- KPI Hero Tiles --}} @if(!empty($kpis))
Total Calls
{{ number_format($kpis['total'] ?? 0) }}
Answer Rate
{{ $kpis['answer_rate'] ?? 0 }}%
Avg Talk
{{ $kpis['avg_talk'] ?? '0:00' }}
Missed
{{ number_format($kpis['missed_outstanding'] ?? $kpis['noanswer'] ?? 0) }}
{{-- Secondary metrics --}}
Total Talk: {{ $kpis['talk_human'] ?? '0:00' }}  ยท  Busiest Hour: {{ $kpis['busiest_hour'] ?? 'โ€”' }}  ยท  Answered: {{ number_format($kpis['answered'] ?? 0) }}
@endif {{-- Network Health --}} @php $netHealth = $data['network_health'] ?? []; @endphp @if(!empty($netHealth['available']))
๐Ÿ“ถ Network Quality {{ $netHealth['grade'] }}
Avg RTT: {{ $netHealth['avg_rtt'] }}ms  ยท  Best: {{ $netHealth['min_rtt'] }}ms  ยท  Worst: {{ $netHealth['max_rtt'] }}ms  ยท  {{ $netHealth['endpoints'] }} endpoints monitored
@endif {{-- Direction Split (Inbound / Outbound / Internal) --}} @php $direction = $data['direction'] ?? []; @endphp @if(!empty($direction) && $reportType !== 'missed_calls')
โ†“ Inbound
{{ number_format($direction['inbound']['total'] ?? 0) }}
{{ number_format($direction['inbound']['answered'] ?? 0) }} answered
โ†‘ Outbound
{{ number_format($direction['outbound']['total'] ?? 0) }}
{{ number_format($direction['outbound']['answered'] ?? 0) }} connected
โ†” Internal
{{ number_format($direction['internal']['total'] ?? 0) }}
{{ number_format($direction['internal']['answered'] ?? 0) }} answered
@endif {{-- Top Extensions (prominent, first data section) --}} @if(!empty($topExt))

๐Ÿ“ž Top Extensions

@foreach($topExt as $ext) @endforeach
Ext Total In Out Int Missed Talk
{{ $ext['ext'] }}@if(!empty($ext['name']))
{{ $ext['name'] }}@endif
{{ $ext['calls'] }} {{ $ext['inbound'] ?? 0 }} {{ $ext['outbound'] ?? 0 }} {{ $ext['internal'] ?? 0 }} {{ $ext['missed'] ?? 0 }} {{ $ext['talk'] }}
@endif {{-- Top Contacts (phonebook customers by volume) --}} @php $topContacts = $data['top_contacts'] ?? []; @endphp

๐Ÿ‘ค Top Contacts (Phonebook)

@if(!empty($topContacts)) @foreach($topContacts as $contact) @endforeach
Contact Total In Out
{{ $contact['name'] }}
{{ $contact['number'] }}
{{ $contact['total'] }} {{ $contact['inbound'] }} {{ $contact['outbound'] }}
@else
๐Ÿ“’ Your phonebook is empty. Import your customer contacts to unlock caller-name display, missed-call resolution tracking, and this Top Contacts report.
Speak to your V-Connect administrator about importing your customer database.
@endif {{-- Calls per day mini-chart (table-based bars for email client compatibility) --}} @if(!empty($perDay))

Daily Call Volume

@php $maxCalls = max(array_column($perDay, 'total') ?: [1]); @endphp @foreach(array_slice($perDay, -14) as $day) @php $totalPct = max(5, round($day['total'] / $maxCalls * 100)); $ansPct = $day['total'] > 0 ? round($day['answered'] / $day['total'] * 100) : 0; @endphp @endforeach
{{ $day['date'] }} @if($ansPct < 100)@endif
  
{{ $day['total'] }}

Answered    Unanswered

@endif {{-- Department breakdown with traffic-light --}} @if(!empty($departments))

Department Performance

@foreach(array_slice($departments, 0, 8) as $dept) @php $rate = $dept['answer_rate']; $rateColor = $rate >= 80 ? '#16a34a' : ($rate >= 60 ? '#d97706' : '#dc2626'); $rateBg = $rate >= 80 ? '#f0fdf4' : ($rate >= 60 ? '#fffbeb' : '#fef2f2'); @endphp @endforeach
Department Calls Answer % Talk
{{ $dept['name'] }} {{ $dept['total'] }} {{ $rate }}% {{ $dept['talk_human'] }}
@else
๐Ÿข Did you know? Group your users into departments to see team-level answer rates, talk time, and performance scoring right here.
Configure departments under Applications โ†’ Departments in your V-Connect admin panel.
@endif {{-- โ•โ•โ• CALL ANALYTICS SPECIFIC: Hourly + Duration Bands โ•โ•โ• --}} @if($reportType === 'call_analytics') @php $perHour = $data['per_hour'] ?? []; $durationBands = $data['duration_bands'] ?? []; @endphp @if(!empty($perHour))

๐Ÿ• Hourly Distribution

@php $maxHour = max(array_column($perHour, 'total') ?: [1]); @endphp @foreach($perHour as $h) @if($h['total'] > 0) @php $hPct = max(5, round($h['total'] / $maxHour * 100)); @endphp @endif @endforeach
{{ $h['hour'] }}
 
{{ $h['total'] }}
@endif @if(!empty($durationBands))

โฑ Call Duration Distribution

@foreach($durationBands as $band => $count) @endforeach
Duration Calls
{{ $band }} {{ number_format($count) }}

Longest call: {{ $kpis['longest_call'] ?? 'โ€”' }}  ยท  Avg duration: {{ $kpis['avg_duration'] ?? 'โ€”' }}

@endif @endif {{-- โ•โ•โ• MISSED CALLS SPECIFIC: KPIs + Top Missed โ•โ•โ• --}} @if($reportType === 'missed_calls') @php $missedRows = $data['rows'] ?? []; @endphp @if(!empty($kpis))
Total Missed
{{ number_format($kpis['total_attempts'] ?? 0) }}
Unique Callers
{{ number_format($kpis['unique_callers'] ?? 0) }}
Outstanding
{{ number_format($kpis['outstanding'] ?? 0) }}
Resolved
{{ number_format($kpis['resolved'] ?? 0) }}
Resolution %
{{ $kpis['resolution_rate'] ?? 0 }}%
@endif @if(!empty($missedRows))

๐Ÿ“ฑ Top Missed Callers

@foreach(array_slice($missedRows, 0, 10) as $row) @endforeach
Caller Attempts Last Missed
{{ $row['name'] ?: $row['number'] }}@if($row['name'])
{{ $row['number'] }}@endif
{{ $row['attempts'] }} {{ \Illuminate\Support\Carbon::parse($row['last'])->format('d M H:i') }}
@endif @endif {{-- Report info footer --}}
{{ $companyName }} ยท {{ $freqLabel }} Report ยท {{ $fromDate }} โ€“ {{ $toDate }}
Schedule: {{ $schedule->name }} ยท Attachment: {{ strtoupper($schedule->format) }}
@endsection