{{-- Patient Balance Summary Widget ────────────────────────────── Renders a snapshot of outstanding balances for the patient — split into cash-owed (patient must pay) and insurance-pending (payer owes). Includable from any page that has a $patient in scope. Usage: @include('partials._patient-balance-summary', ['patient' => $patient]) Optional parameters: 'compact' => bool — true (default) shows a one-line strip; false shows the full breakdown with invoice list 'show_link' => bool — true (default) includes a "View all bills" deep-link into the billing module filtered to this patient Inline styling is used throughout (not Tailwind utility classes) because it renders reliably against the Tailwind CDN loading order — no flash of unstyled content even on slow networks. --}} @php $compact = isset($compact) ? (bool) $compact : true; $showLink = isset($showLink) ? (bool) $showLink : true; $bal = $patient->balance_summary; @endphp @if($bal['total'] <= 0) {{-- ── Empty state: cheerful all-clear ─────────────────────────────── --}}
No outstanding balance · All invoices settled
@elseif($compact) {{-- ── Compact strip ───────────────────────────────────────────────── --}}
{{-- Total block --}}
Outstanding Balance
KES {{ number_format($bal['total']) }}
{{ $bal['invoice_count'] }} open {{ \Illuminate\Support\Str::plural('invoice', $bal['invoice_count']) }} @if($bal['oldest_days'] !== null && $bal['oldest_days'] > 0) · oldest {{ (int) $bal['oldest_days'] }} day{{ $bal['oldest_days'] === 1 ? '' : 's' }} @endif
{{-- Split blocks (only show if there's actually a split) --}} @if($bal['cash_owed'] > 0 && $bal['insurance_pending'] > 0)
Patient Owes
KES {{ number_format($bal['cash_owed']) }}
Insurance Pending
KES {{ number_format($bal['insurance_pending']) }}
@elseif($bal['insurance_pending'] > 0)
Insurance-pending — patient balance: KES 0
@endif {{-- Action link --}} @if($showLink)
View all bills
@endif
@else {{-- ── Expanded: total card + invoice list ─────────────────────────── --}}
Outstanding Balance — {{ $patient->full_name }}
KES {{ number_format($bal['total']) }}
across {{ $bal['invoice_count'] }} open {{ \Illuminate\Support\Str::plural('invoice', $bal['invoice_count']) }} @if($bal['oldest_days'] !== null && $bal['oldest_days'] > 0) · oldest is {{ (int) $bal['oldest_days'] }} day{{ $bal['oldest_days'] === 1 ? '' : 's' }} old @endif
{{-- Split cards --}}
@if($bal['cash_owed'] > 0)
Patient Owes
KES {{ number_format($bal['cash_owed']) }}
@endif @if($bal['insurance_pending'] > 0)
Insurance Pending
KES {{ number_format($bal['insurance_pending']) }}
@endif
{{-- Invoice list --}}
Open invoices
@foreach($bal['invoices']->take(10) as $inv)
{{ $inv->invoice_number }} @if($inv->visit) · {{ $inv->visit->visit_number }} @endif
{{ $inv->created_at->format('d M Y') }} @if($inv->payment_mode && $inv->payment_mode !== 'cash') · {{ $inv->payment_mode }} @endif @if(in_array($inv->payment_mode, ['insurance', 'corporate'], true)) (pending claim) @endif
KES {{ number_format($inv->balance) }}
@if($inv->amount_paid > 0)
(paid {{ number_format($inv->amount_paid) }} of {{ number_format($inv->total_amount) }})
@endif
@endforeach @if($bal['invoices']->count() > 10)
+ {{ $bal['invoices']->count() - 10 }} more open {{ \Illuminate\Support\Str::plural('invoice', $bal['invoices']->count() - 10) }}
@endif
@if($showLink)
Open full billing view
@endif
@endif