@extends('layouts.app') @section('title', 'Dashboard') @php $sentimentSlices = $stats['sentiment']; $sentimentTotal = array_sum(array_column($sentimentSlices, 'total')); $categorySlices = array_values(array_filter($stats['categories'], fn($slice) => $slice['total'] > 0)); $categoryTotal = array_sum(array_column($categorySlices, 'total')); $leadTotal = $stats['leads']['total'] ?? 0; $leadSlices = array_values(array_filter($stats['leads']['slices'] ?? [], fn($slice) => $slice['total'] > 0)); $leadPriorities = $stats['leads']['priorities'] ?? []; $prioritySlices = array_values(array_filter($leadPriorities, fn($band) => $band['total'] > 0)); $highBand = collect($leadPriorities)->firstWhere('key', \App\Models\LeadType::PRIORITY_HIGH); $canManage = (Auth::check() && Auth::user()->auth_id == 0) || Auth::user()->user_level != 0; $turnaround = $stats['turnaround']; $volumeSum = array_sum(array_column($stats['volume'], 'total')); $humaniseGap = function (?int $minutes) { if ($minutes === null) { return '—'; } if ($minutes < 60) { return $minutes . ' min'; } if ($minutes < 1440) { $hours = intdiv($minutes, 60); $rest = $minutes % 60; return $hours . ' h' . ($rest > 0 ? ' ' . $rest . ' m' : ''); } $days = intdiv($minutes, 1440); $hours = intdiv($minutes % 1440, 60); return $days . ($days === 1 ? ' day' : ' days') . ($hours > 0 ? ' ' . $hours . ' h' : ''); }; $toChart = fn(array $rows) => array_map( fn($row) => [ 'label' => $row['label'], 'colour' => $row['colour'], 'total' => $row['total'], 'url' => route('mails.filter', [$row['filter']]), ], $rows, ); $sentimentChartData = $toChart($sentimentSlices); $priorityChartData = $toChart($prioritySlices); $leadChartData = $toChart($leadSlices); $categoryChartData = $toChart($categorySlices); $senderChartData = $stats['topSenders'] ->map(fn($sender) => [ 'label' => $sender->sender_email, 'colour' => '#3355d1', 'total' => (int) $sender->total, 'url' => null, ]) ->values() ->all(); $replyChartData = [ [ 'label' => 'Replied', 'colour' => '#067647', 'total' => $stats['replied'], 'url' => route('mails.filter', ['replied_mail']), ], [ 'label' => 'Awaiting', 'colour' => '#b54708', 'total' => $stats['awaiting'], 'url' => route('mails.filter', ['send-mail']), ], ]; $barHeight = fn(int $rows) => max(140, $rows * 32 + 30); @endphp @section('content') @if ($is_app_pwd == 0) @endif @unless ($canManage) @endunless
Total mail
{{ number_format($stats['total']) }} Conversations in this mailbox
Unread
{{ number_format($stats['unread']) }} @if ($stats['total'] > 0) {{ round(($stats['unread'] / $stats['total']) * 100) }}% of all mail @else Nothing received yet @endif
Awaiting reply
{{ number_format($stats['awaiting']) }} Flagged as needing a response
High priority
{{ number_format($highBand['total'] ?? 0) }} of {{ number_format($leadTotal) }} open leads
Reply rate
{{ $stats['replyRate'] === null ? '—' : $stats['replyRate'] . '%' }} @if ($stats['replyRate'] === null) No mail has needed a reply yet @else {{ number_format($stats['replied']) }} of {{ number_format($stats['needingAction']) }} answered @endif

Mail received

Last 30 days {{ number_format($volumeSum) }} total
@if ($volumeSum === 0)

No mail in the last 30 days

@else
@endif

Sentiment

Click to open
@if ($sentimentTotal === 0)

Nothing analysed yet

@else
@endif

Leads by type

View all leads
@if (count($leadChartData) === 0)

No opportunities detected yet

Adjust the confidence floor per type on the Lead Types screen.

@else
@endif

Lead urgency

{{ number_format($leadTotal) }} open
@if (count($priorityChartData) === 0)

Nothing to prioritise

@else
@endif

Reply turnaround

How long answered mail waited View replied
@if ($turnaround['total'] === 0)

No replies to measure yet

@else

Median {{ $humaniseGap($turnaround['medianMinutes']) }} across {{ number_format($turnaround['total']) }} answered {{ $turnaround['total'] === 1 ? 'mail' : 'mails' }}.

@endif

Reply status

Mail needing a response
@if ($stats['needingAction'] === 0)

Nothing is waiting

@else
@endif

Categories

{{ number_format($categoryTotal) }} classified
@if (count($categoryChartData) === 0)

Nothing categorised yet

@else
@endif

Top senders

Last 30 days
@if (count($senderChartData) === 0)

No senders in the last 30 days

@else
@endif
@endsection @push('scripts') @endpush