@extends('layouts.app')
@section('title', 'Final Receipt | ' . ($invoice->invoice_number ?? ''))
@section('styles')
@endsection
@section('content')
@include('partials._document-header')
Final Receipt
Invoice: {{ $invoice->invoice_number }}
Visit: {{ $invoice->visit->visit_number ?? '' }}
Date: {{ $invoice->created_at->format('d M Y') }}
| Patient | {{ $invoice->patient->full_name ?? '' }} |
| MRN | {{ $invoice->patient->mrn ?? '' }} |
{{-- ── SHA member block (consolidated) ─────────────────────────────
An invoice may carry one or more SHA payments. We surface the
FIRST SHA payment's member identity at the top of the final
receipt because in 99% of cases all SHA payments on a single
visit will share the same principal. Per-payment SHA details
still appear in the Payments Received table below for full
traceability. --}}
@php
$shaPayment = $invoice->payments->first(fn($p) => !empty($p->sha_number));
@endphp
@if($shaPayment)
SHA Member Details
| SHA Number |
{{ $shaPayment->sha_number }} |
Relationship |
{{ $shaPayment->sha_relationship }} |
| Member Name |
{{ $shaPayment->sha_member_name }} |
@if(!empty($shaPayment->sha_auth_reference))
| Auth Reference |
{{ $shaPayment->sha_auth_reference }} |
@endif
@endif
{{-- All services --}}
| Service / Item |
Qty |
Price |
Total |
@foreach($invoice->items as $item)
| {{ $item->description }} |
{{ $item->quantity }} |
{{ number_format($item->unit_price) }} |
{{ number_format($item->total) }} |
@endforeach
| TOTAL BILLED |
KES {{ number_format($invoice->total_amount ?? 0) }} |
{{-- All payments --}}
Payments Received
| Date |
Method |
Reference |
Amount |
@foreach($invoice->payments as $pay)
| {{ $pay->created_at->format('d M H:i') }} |
@if($pay->payment_type === 'copay')
Co-pay
({{ str_replace('_',' ',$pay->payment_method) }})
@else
{{ str_replace('_',' ',$pay->payment_method) }}{{ $pay->description ? ' ('.$pay->description.')' : '' }}
@endif
@if(!empty($pay->sha_number))
SHA {{ $pay->sha_number }} · {{ $pay->sha_member_name }} · {{ $pay->sha_relationship }}@if(!empty($pay->sha_auth_reference)) · Auth {{ $pay->sha_auth_reference }}@endif
@endif
|
{{ $pay->reference_number ?? $pay->mpesa_code ?? '-' }} |
KES {{ number_format($pay->amount) }} |
@endforeach
| TOTAL PAID |
KES {{ number_format($invoice->amount_paid ?? 0) }} |
{{-- Breakdown summary — only shown when payments span multiple categories --}}
{{-- (e.g. an insurance bill with a co-pay). For a simple cash-only or --}}
{{-- mpesa-only receipt this block is skipped to keep the layout clean. --}}
@php
$insTotal = (float) $invoice->payments->where('payment_method', 'insurance')->sum('amount');
$copayTotal = (float) $invoice->payments->where('payment_type', 'copay')->sum('amount');
$cashTotal = (float) $invoice->payments
->where('payment_type', '!=', 'copay')
->whereIn('payment_method', ['cash','mpesa','card','bank_transfer'])
->sum('amount');
$showBreakdown = ($insTotal > 0 && ($copayTotal > 0 || $cashTotal > 0))
|| ($copayTotal > 0 && $cashTotal > 0);
@endphp
@if($showBreakdown)
Settlement breakdown
@if($insTotal > 0)
Insurance receivableKES {{ number_format($insTotal) }}
@endif
@if($copayTotal > 0)
Co-pay (patient out-of-pocket)KES {{ number_format($copayTotal) }}
@endif
@if($cashTotal > 0)
Cash / M-Pesa / CardKES {{ number_format($cashTotal) }}
@endif
@endif
{{-- Balance --}}
@php $bal = $invoice->balance ?? 0; @endphp
Balance Due
KES {{ number_format($bal) }}
Generated on {{ now()->format('d M Y H:i') }} by {{ Auth::user()->name ?? '' }}
@include('partials._document-footer', ['showPaybill' => true])
@endsection