@extends('layouts.app') @section('title', 'Dashboard') @section('content') @php // Format helpers used throughout the view $fmtKes = fn($n) => 'KES ' . number_format((float) $n, 0); $fmtKesNeg= function($n) use ($fmtKes) { $n = (float) $n; return $n < 0 ? '-' . $fmtKes(abs($n)) : $fmtKes($n); }; @endphp @php // Smart period label that adapts to the selected range. // Single-day-today → "Today" // Single-day-other → "Mon, 01 May 2026" // Multi-day → "01 May — 05 May 2026" (or with year prefix if cross-year) $periodLabel = (function() use ($rangeStart, $rangeEnd, $isSingleDay, $isToday) { if ($isToday) return 'Today (' . $rangeStart->format('d M Y') . ')'; if ($isSingleDay) return $rangeStart->format('D, d M Y'); $sameYear = $rangeStart->year === $rangeEnd->year; return $sameYear ? $rangeStart->format('d M') . ' — ' . $rangeEnd->format('d M Y') : $rangeStart->format('d M Y') . ' — ' . $rangeEnd->format('d M Y'); })(); // Preset URL helpers — generate ?from=X&to=Y links. $presetUrl = function($from, $to) { return route('dashboard') . '?from=' . $from . '&to=' . $to; }; $today = \Carbon\Carbon::today(); $yesterday = $today->copy()->subDay(); $sevenDaysAgo = $today->copy()->subDays(6); $thirtyDaysAgo = $today->copy()->subDays(29); $thisMonthStart = $today->copy()->startOfMonth(); $lastMonthStart = $today->copy()->subMonthNoOverflow()->startOfMonth(); $lastMonthEnd = $today->copy()->subMonthNoOverflow()->endOfMonth(); // Detect which preset is currently active (for visual highlight). $isPreset = function($from, $to) use ($rangeStart, $rangeEnd) { return $rangeStart->toDateString() === $from->toDateString() && $rangeEnd->toDateString() === $to->toDateString(); }; $activePreset = match(true) { $isPreset($today, $today) => 'today', $isPreset($yesterday, $yesterday) => 'yesterday', $isPreset($sevenDaysAgo, $today) => 'last7', $isPreset($thirtyDaysAgo, $today) => 'last30', $isPreset($thisMonthStart, $today) => 'thismonth', $isPreset($lastMonthStart, $lastMonthEnd) => 'lastmonth', default => 'custom', }; @endphp {{-- ══════════════ TOP BAR: Title + Date Range Filter ══════════════ --}}
Showing data for {{ $periodLabel }} @if(!$isToday) Historical @endif
Patients{{ $isToday ? ' Today' : '' }}
{{ number_format($row1['patientsToday']) }}
Revenue{{ $isToday ? ' Today' : '' }}
{{ $fmtKes($row1['revenueToday']) }}
Collections{{ $isToday ? ' Today' : '' }}
{{ $fmtKes($row1['collectionsToday'] ?? 0) }}
Cash
{{ $fmtKes($row1['cashToday']) }}
Mobile / Bank
{{ $fmtKes($row1['mobileToday']) }}
Insurance
{{ $fmtKes($row1['insuranceToday']) }}
ARPP
{{ $fmtKes($row1['arpp']) }}
Avg Revenue/Day
{{ $fmtKes($row2['avgRevenuePerDay'] ?? 0) }}
MTD average · {{ $row2['daysElapsed'] ?? 0 }} day{{ ($row2['daysElapsed'] ?? 0) === 1 ? '' : 's' }}
Follow-Ups Due
{{ number_format($row1['followUpsDue'] ?? 0) }}
MTD Revenue
{{ $fmtKes($row2['mtdRevenue']) }}
MTD Expenses
{{ $fmtKes($row2['mtdExpenses']) }}
MTD Net Position
{{ $fmtKesNeg($row2['mtdNet']) }}
Cash in Bank ⓘ
{{ $fmtKesNeg($row2['cashInBank']) }}
Accounts Receivable
{{ $fmtKes($row2['accountsReceivable']) }}
Appointments
{{ number_format($row3['appointments']) }}
{{-- Bed Occupancy --}}Bed Occupancy
{{ $row3['bedOccupancy'] }}%
{{ $row3['occupiedBeds'] }} / {{ $row3['totalBeds'] }} beds occupied
{{-- Active ANC --}}Active ANC Clients
{{ number_format($row3['activeAnc']) }}
{{-- New vs Returning --}}New vs Returning
@php $total = $row3['newCount'] + $row3['returningCount']; @endphp {{ $total > 0 ? round(($row3['newCount'] / $total) * 100) : 0 }}% new
|
{{ $dept->department ?: 'Unassigned' }}
{{ $fmtKes($dept->total) }}
|
No revenue recorded for this date.
@endif{{ $meta['time'] }}
| Cash | {{ $fmtKes($s['cash']) }} |
| M-Pesa / Mobile | {{ $fmtKes($s['mpesa']) }} |
| Insurance | {{ $fmtKes($s['insurance']) }} |
| Card / Bank | {{ $fmtKes($s['card']) }} |
| Shift Total | {{ $fmtKes($s['total']) }} |