@extends('admin._layout') @section('title', 'لوحة المشرف') @push('head') @endpush @section('content') {{-- ============================================================ --}} {{-- KPI ROW 1 — financials --}} {{-- ============================================================ --}}
@if($financials['mrr_change'] !== null) {{ $financials['mrr_change'] >= 0 ? '+' : '' }}{{ $financials['mrr_change'] }}% @endif
إيرادات شهرية متكررة (MRR)
{{ number_format($financials['mrr'], 0) }} {{ $financials['currency'] }}
إيرادات سنوية متوقعة (ARR)
{{ number_format($financials['arr'], 0) }} {{ $financials['currency'] }}
@php $newDelta = $stats['new_prev_month'] > 0 ? round((($stats['new_this_month'] - $stats['new_prev_month']) / $stats['new_prev_month']) * 100, 1) : null; @endphp @if($newDelta !== null) {{ $newDelta >= 0 ? '+' : '' }}{{ $newDelta }}% @endif
عيادات جديدة هذا الشهر
{{ $stats['new_this_month'] }} / {{ $stats['new_prev_month'] }} الشهر السابق
معدل تحويل التجربة
@if($stats['trial_conversion_rate'] !== null) {{ $stats['trial_conversion_rate'] }}% @else — لا توجد بيانات @endif
{{-- ============================================================ --}} {{-- KPI ROW 2 — clinic statuses --}} {{-- ============================================================ --}}
إجمالي العيادات
{{ number_format($stats['total_clinics']) }}
عيادات نشطة
{{ number_format($stats['active_clinics']) }}
تحت التجربة
{{ number_format($stats['trial_clinics']) }}
موقوفة / منتهية
{{ number_format($stats['suspended_clinics'] + $stats['expired_clinics']) }}
{{-- ============================================================ --}} {{-- CHARTS ROW --}} {{-- ============================================================ --}}

نمو العيادات والإيرادات — آخر 12 شهر

توزيع العيادات حسب الحالة

إيرادات الاشتراكات الشهرية

توزيع الباقات

@if(empty($charts['plan_labels']))
لا توجد عيادات مرتبطة بباقات بعد.
@else
@endif
{{-- ============================================================ --}} {{-- OPERATIONAL ALERTS + RECENT --}} {{-- ============================================================ --}}

اشتراكات / تجارب على وشك الانتهاء

{{ $expiringSoon->count() }}
@if($expiringSoon->isEmpty())
لا توجد عيادات تحتاج اهتمام عاجل.
@else
@foreach($expiringSoon as $c) @php $endsAt = $c->status === 'trial' ? $c->trial_ends_at : $c->subscription_ends_at; $daysLeft = $endsAt ? (int) now()->diffInDays($endsAt, false) : null; @endphp @endforeach
العيادة الحالة ينتهي في المتبقي
{{ $c->name }}
{{ $c->owner_email }}
{{ $c->status === 'trial' ? 'تجريبي' : 'نشط' }} {{ $endsAt?->translatedFormat('j M Y') ?? '—' }} @if($daysLeft !== null) {{ $daysLeft }} يوم @endif
@endif

الأعلى أداءً (بعدد المرضى)

@forelse($topClinics as $row) @php $c = $row['clinic']; $m = $row['metrics']; @endphp
{{ $c->name }} #{{ $loop->iteration }}
{{ number_format($m['patients'] ?? 0) }} مريض {{ number_format($m['doctors'] ?? 0) }} طبيب {{ number_format($m['appointments'] ?? 0) }} حجز
@empty
لا توجد بيانات بعد.
@endforelse
{{-- ============================================================ --}} {{-- AGGREGATE TENANT TOTALS --}} {{-- ============================================================ --}}
إجمالي الأطباء
{{ number_format($totals['doctors']) }}
إجمالي المستخدمين
{{ number_format($totals['users']) }}
إجمالي المرضى
{{ number_format($totals['patients']) }}
إجمالي المواعيد
{{ number_format($totals['appointments']) }}
{{-- ============================================================ --}} {{-- CLINIC LIST (active recently) --}} {{-- ============================================================ --}}

العيادات الأكثر نشاطاً مؤخراً

@forelse($clinicStats as $row) @php $c = $row['clinic']; $m = $row['metrics']; // Pick whichever countdown is currently meaningful: // trial takes precedence while status === 'trial', // otherwise show the subscription runway. $endsAt = $c->status === 'trial' ? $c->trial_ends_at : $c->subscription_ends_at; $daysLeft = $endsAt && $endsAt->isFuture() ? (int) max(0, ceil(now()->diffInDays($endsAt, false))) : null; $countdownColor = $daysLeft === null ? 'secondary' : ($daysLeft <= 3 ? 'danger' : ($daysLeft <= 7 ? 'warning' : 'success')); // Plan-limit shading for the doctors / patients cells. $plan = $c->plan; $docPct = ($plan && $plan->max_doctors && ($m['doctors'] ?? null) !== null) ? (int) min(100, round(($m['doctors'] / $plan->max_doctors) * 100)) : null; $patPct = ($plan && $plan->max_patients && ($m['patients'] ?? null) !== null) ? (int) min(100, round(($m['patients'] / $plan->max_patients) * 100)) : null; $cellColor = fn ($pct) => $pct === null ? '' : ($pct >= 90 ? 'text-danger' : ($pct >= 70 ? 'text-warning' : '')); @endphp @if($m['reachable'] ?? false) @else @endif @empty @endforelse
العيادة الباقة الحالة المتبقي أطباء مرضى مواعيد آخر نشاط
{{ $c->name }}
{{ $c->owner_email }}
{{ $c->plan?->name ?? '—' }} {{ ['active' => 'نشط', 'trial' => 'تجريبي', 'suspended' => 'موقوف', 'expired' => 'منتهي', 'pending' => 'معلّق'][$c->status] ?? $c->status }} @if($daysLeft !== null) {{ $daysLeft }} يوم @else @endif {{ $m['doctors'] ?? 0 }} @if($plan && $plan->max_doctors) / {{ $plan->max_doctors }} @endif {{ number_format($m['patients']) }} @if($plan && $plan->max_patients) / {{ number_format($plan->max_patients) }} @endif {{ number_format($m['appointments']) }} غير متاحة {{ $c->last_active_at?->diffForHumans() ?? 'لا يوجد' }}
لا توجد عيادات بعد. أضف أول عيادة
@endsection @push('scripts') @endpush