@extends('layouts.app') @section('title', 'كشف حساب — '.($patient->full_name ?? 'مريض')) @push('head') @endpush @php $statusMeta = [ 'draft' => ['label' => 'مسودة', 'color' => 'secondary'], 'sent' => ['label' => 'مُرسلة', 'color' => 'info'], 'partial' => ['label' => 'مدفوعة جزئياً', 'color' => 'warning'], 'paid' => ['label' => 'مدفوعة', 'color' => 'success'], 'overdue' => ['label' => 'متأخرة', 'color' => 'danger'], 'cancelled' => ['label' => 'ملغاة', 'color' => 'secondary'], ]; $methodMeta = [ 'cash' => ['label' => 'نقدي', 'color' => 'success', 'icon' => 'cash'], 'card' => ['label' => 'بطاقة', 'color' => 'info', 'icon' => 'credit-card'], 'transfer' => ['label' => 'تحويل', 'color' => 'primary', 'icon' => 'building-bank'], 'insurance' => ['label' => 'تأمين', 'color' => 'purple', 'icon' => 'shield-check'], 'other' => ['label' => 'أخرى', 'color' => 'secondary', 'icon' => 'circle'], ]; $patientName = trim(($patient->first_name ?? '').' '.($patient->last_name ?? '')) ?: '—'; $initials = collect(preg_split('/\s+/u', $patientName)) ->filter()->take(2) ->map(fn ($w) => mb_substr($w, 0, 1)) ->implode('') ?: '؟'; $genderClass = ($patient->gender ?? null) === 'female' ? 'gender-female' : ''; // Determine the balance card visual state. $balanceState = match (true) { $totals['balance'] <= 0 => 'is-clear', $outstandingByAge['90+'] > 0 || $outstandingByAge['61-90'] > 0 => 'is-overdue', default => '', // mild warning yellow }; @endphp @section('content') {{-- Print-only letterhead — the regular hero has a gradient background that prints poorly. --}} كل التقارير {{-- ============================================================ --}} {{-- Patient identity card --}} {{-- ============================================================ --}}
{{ $initials }}

{{ $patientName }}

@if($patient->file_number) {{ $patient->file_number }} @endif @if($patient->phone) {{ $patient->phone }} @endif @if($patient->age !== null) {{ $patient->age }} سنة @endif @if($patient->gender) {{ $patient->gender === 'female' ? 'أنثى' : 'ذكر' }} @endif
ملف المريض
{{-- ============================================================ --}} {{-- Outstanding balance highlight + aging buckets --}} {{-- ============================================================ --}}
@if($totals['balance'] <= 0)
المريض ليس عليه رصيد متبقي
0
كل الفواتير في الفترة مدفوعة بالكامل.
@else
رصيد متبقي على المريض
{{ number_format($totals['balance'], 0) }}
@if($balanceState === 'is-overdue')
فواتير متأخرة أكثر من 60 يوم — تواصل مع المريض.
@endif @endif

توزيع الرصيد بحسب العمر

@if($totals['balance'] <= 0)
لا توجد فواتير متأخرة 🎉
@else
@php $ageMeta = [ '0-30' => ['label' => '0–30 يوم', 'color' => 'success'], '31-60' => ['label' => '31–60 يوم', 'color' => 'info'], '61-90' => ['label' => '61–90 يوم', 'color' => 'warning'], '90+' => ['label' => '90+ يوم', 'color' => 'danger'], ]; @endphp @foreach($ageMeta as $key => $meta) @php $amt = $outstandingByAge[$key] ?? 0; @endphp
{{ $meta['label'] }}
{{ number_format($amt, 0) }}
@endforeach
@endif
{{-- ============================================================ --}} {{-- Activity overview --}} {{-- ============================================================ --}}
المواعيد
{{ $activity['appointments'] }}
الزيارات
{{ $activity['visits'] }}
الوصفات
{{ $activity['prescriptions'] }}
التحاليل
{{ $activity['lab_tests'] }}
{{-- ============================================================ --}} {{-- Date range filter --}} {{-- ============================================================ --}}
{{ \Carbon\Carbon::parse($from)->translatedFormat('j M Y') }} ← {{ \Carbon\Carbon::parse($to)->translatedFormat('j M Y') }}
{{-- ============================================================ --}} {{-- Invoices + per-invoice payments --}} {{-- ============================================================ --}}

الفواتير في الفترة

اضغط على فاتورة لعرض تفصيل دفعاتها.
@if($invoices->isEmpty())

لا توجد فواتير في هذه الفترة

غيّر النطاق الزمني أو ابحث في فترة أوسع.

@else
@foreach($invoices as $inv) @php $sm = $statusMeta[$inv->status] ?? ['label' => $inv->status, 'color' => 'secondary']; $ageColor = match (true) { $inv->balance <= 0 => 'success', $inv->age_days <= 30 => 'info', $inv->age_days <= 60 => 'warning', default => 'danger', }; @endphp {{-- Inline expandable: payments under each invoice --}} @if($inv->payments->count()) @endif @endforeach
الفاتورة التاريخ عمر الفاتورة الحالة الإجمالي المدفوع المتبقي
@if($inv->payments->count()) @endif {{ $inv->invoice_number }} {{ $inv->issue_date->format('Y-m-d') }} {{ $inv->age_days }} يوم {{ $sm['label'] }} {{ number_format($inv->total, 2) }} {{ number_format($inv->paid_amount, 2) }} {{ number_format($inv->balance, 2) }}
دفعات الفاتورة ({{ $inv->payments->count() }})
@foreach($inv->payments as $pay) @php $mm = $methodMeta[$pay->payment_method] ?? ['label' => $pay->payment_method, 'color' => 'secondary', 'icon' => 'circle']; @endphp
{{ $mm['label'] }} {{ $pay->paid_at->format('Y-m-d H:i') }} @if($pay->reference_number) {{ $pay->reference_number }} @endif @if($pay->receiver) {{ $pay->receiver->name }} @endif
{{ number_format($pay->amount, 2) }}
@endforeach
الإجمالي {{ number_format($totals['invoiced'], 2) }} {{ number_format($totals['paid'], 2) }} {{ number_format($totals['balance'], 2) }}
@endif
{{-- ============================================================ --}} {{-- Full payments audit trail --}} {{-- ============================================================ --}} @if($allPayments->isNotEmpty())

سجل المدفوعات الكامل

{{ $allPayments->count() }} عملية · {{ number_format($allPayments->sum('amount'), 0) }}
@foreach($allPayments as $p) @php $mm = $methodMeta[$p->payment_method] ?? ['label' => $p->payment_method, 'color' => 'secondary', 'icon' => 'circle']; $paidAt = \Carbon\Carbon::parse($p->paid_at); @endphp @endforeach
التاريخ الفاتورة الطريقة المستلم المرجع المبلغ
{{ $paidAt->format('Y-m-d') }}
{{ $paidAt->format('h:i A') }}
{{ $p->invoice_number }} {{ $mm['label'] }} {{ $p->receiver_name ?? '—' }} {{ $p->reference_number ?: '—' }} {{ number_format($p->amount, 2) }}
@endif @endsection