@extends('layouts.app') @section('title', 'Invoice | ' . ($visit->invoice?->invoice_number ?? 'New')) @section('content') @php $isAdmin = auth()->user()->hasAnyRole('Super Admin','Hospital Admin'); $isCashier = auth()->user()->hasAnyRole('Receptionist','Clinician','Nurse','Triage Nurse','Dental User','Super Admin','Hospital Admin'); $invoice = $visit->invoice; $isCompleted = in_array($visit->status, ['completed','discharged']); $invFreshBalance = 0; if ($invoice) { $invFreshTotal = $invoice->items()->sum(\DB::raw('quantity * unit_price')); $invFreshPaid = $invoice->payments()->where('status','completed')->sum('amount'); $invFreshBalance = max(0, $invFreshTotal - $invFreshPaid); } @endphp @if($invoice)
This visit is {{ $visit->status }} — bill is locked for regular users
As admin you can reopen it to make changes, or correct the payer type below.
{{ $visit->patient->full_name }} · {{ $visit->patient->mrn }}
{{-- Show current payer clearly --}}Payer: @if(($invoice?->payment_mode ?? '') === 'insurance') {{ $invoice->insuranceCompany->name ?? 'Insurance' }} @else {{ ucfirst($invoice?->payment_mode ?? 'cash') }} @endif @if($isAdmin && $invoice) @endif
{{-- ── SHA member block in the payer header ────────────── Surfaces the patient's SHA identity right next to the payer label, so anyone reviewing the invoice can see it at a glance (not just on the receipt). Two sources, in priority order: (1) the most-recent SHA-tagged payment on this invoice — the values actually used for THIS bill; (2) the patient's stored SHA cover on file — useful when the invoice exists but no SHA payment has been recorded yet (e.g. visit was flagged SHA at registration). --}} @php $hdrShaCompany = \App\Models\InsuranceCompany::where('code', 'SHA')->first(); $hdrShaPay = null; $hdrShaCover = null; if ($hdrShaCompany) { // Prefer a real SHA payment on this invoice — it // reflects exactly what was captured and printed. $hdrShaPay = $invoice?->payments ?->whereNotNull('sha_number') ?->sortByDesc('created_at') ?->first(); // Fallback: patient's stored coverage. Renders // when the invoice is SHA but no payment has // been recorded yet. if (!$hdrShaPay && ($invoice?->payment_mode ?? '') === 'insurance' && $invoice?->insurance_company_id === $hdrShaCompany->id) { $hdrShaCover = \App\Models\PatientInsurance::where('patient_id', $invoice->patient_id) ->where('insurance_company_id', $hdrShaCompany->id) ->where('is_active', true) ->latest() ->first(); } } $hdrShaNumber = $hdrShaPay->sha_number ?? $hdrShaCover->member_number ?? null; $hdrShaMember = $hdrShaPay->sha_member_name ?? $hdrShaCover->principal_name ?? null; $hdrShaRel = $hdrShaPay->sha_relationship ?? $hdrShaCover->relationship ?? null; $hdrShaAuth = $hdrShaPay->sha_auth_reference ?? null; $hdrShaSource = $hdrShaPay ? 'payment' : ($hdrShaCover ? 'file' : null); @endphp @if($hdrShaNumber)| SHA No. | {{ $hdrShaNumber }} | Relationship | {{ $hdrShaRel ?? '—' }} |
| Member | {{ $hdrShaMember ?? '—' }} | ||
| Auth Ref | {{ $hdrShaAuth }} | ||
Correct the payer type for this invoice
| Item | Category | Qty | Unit Price | Total | |
|---|---|---|---|---|---|
| {{ $item->description }} | {{ $item->category }} | {{-- Qty: editable inline --}}@if($canEditItems) @else {{ $item->quantity }} @endif | {{-- Unit Price: editable inline --}}@if($canEditItems) @else {{ number_format($item->unit_price) }} @endif | KES {{ number_format($item->total) }} | @if($canEditItems) @endif |
| Total: | KES {{ number_format($invoice?->total_amount ?? 0) }} | ||||
Payments are recorded by the Cashier.
Outstanding balance: KES {{ number_format($invFreshBalance) }}
Bill Fully Paid
No outstanding balance
{{ $pay->description ?? ucfirst($pay->payment_method) }}
{{ $pay->created_at->format('d M H:i') }}
KES {{ number_format($pay->amount) }}
No payments yet.
@endforelse