@extends('layouts.app') @section('title', 'Receipt | ' . $receipt->receipt_number) @section('styles') @endsection @section('content') @php // Pre-compute totals so the receipt always shows complete financial picture. $inv = $receipt->invoice; $invTotal = (float) ($inv?->total_amount ?? 0); $invPaid = (float) ($inv?->amount_paid ?? 0); $invBalance = (float) ($inv?->balance ?? max(0, $invTotal - $invPaid)); $isFullyPaid = $inv && $invBalance <= 0; // All payments on this invoice, grouped by method+description so splits // like "GA Insurance" and "SHA" each show as their own line. $allPayments = $inv?->payments ?? collect(); $paymentsGrouped = $allPayments->groupBy(function ($p) { $label = ucfirst(str_replace('_', ' ', $p->payment_method)); if ($p->payment_method === 'insurance' && $p->description) { $label = $p->description; } return $label; })->map(fn($grp, $name) => [ 'name' => $name, 'amount' => $grp->sum('amount'), 'count' => $grp->count(), 'last' => $grp->max('created_at'), ])->values(); @endphp
Back to Billing @if($inv) View Full Receipt @endif Download PDF
@include('partials._document-header')

{{ $isFullyPaid ? 'Payment Receipt' : 'Interim Receipt' }}

This receipt acknowledges one payment transaction on this invoice.

Receipt No: {{ $receipt->receipt_number }}
Date: {{ $receipt->created_at->format('d M Y H:i') }}
@if($receipt->payment->reference_number ?? $receipt->payment->mpesa_code ?? null) @endif
Patient Name{{ $receipt->patient->full_name ?? '' }}
MRN{{ $receipt->patient->mrn ?? '' }}
Invoice No.{{ $inv?->invoice_number ?? '' }}
Payment Method{{ str_replace('_', ' ', $receipt->payment_method) }}{{ $receipt->payment?->description ? ' — '.$receipt->payment->description : '' }}
Reference{{ $receipt->payment->reference_number ?? $receipt->payment->mpesa_code ?? '' }}
{{-- ── SHA member block ──────────────────────────────────────────── Only renders when this receipt's payment carries SHA member identity. We key off sha_number directly (not payment_method) because that's the column the billing controller writes, and a non-SHA payment will simply have a NULL there. --}} @if(!empty($receipt->payment?->sha_number))

SHA Member Details

@if(!empty($receipt->payment->sha_auth_reference)) @endif
SHA Number{{ $receipt->payment->sha_number }}
Member Name{{ $receipt->payment->sha_member_name }}
Relationship{{ $receipt->payment->sha_relationship }}
Auth Reference{{ $receipt->payment->sha_auth_reference }}
@endif {{-- Amount for THIS transaction --}}

Amount Received (This Payment)

KES {{ number_format($receipt->amount, 2) }}

{{-- Invoice-level financial summary so users don't confuse the single payment with the full bill --}} @if($inv)

Invoice Summary ({{ $inv->invoice_number }})

{{-- All payments received on this invoice (not just this receipt) --}} @foreach($paymentsGrouped as $pg) @endforeach
Total Billed: KES {{ number_format($invTotal) }}
· {{ $pg['name'] }}{{ $pg['count'] > 1 ? ' ('.$pg['count'].' payments)' : '' }} + {{ number_format($pg['amount']) }}
Total Paid: KES {{ number_format($invPaid) }}
Balance Due: KES {{ number_format($invBalance) }} @if($invBalance <= 0) FULLY PAID @endif
@endif {{-- Items on the invoice --}} @if($inv && $inv->items->count()) @php $receiptItemIds = $receipt->items ? $receipt->items->pluck('id')->toArray() : []; $isItemized = count($receiptItemIds) > 0; @endphp

{{ $isItemized ? 'Items Covered by This Payment' : 'Services on This Visit' }}

@if($isItemized)@endif @foreach($inv->items as $item) @php $covered = in_array($item->id, $receiptItemIds); @endphp @if($isItemized)@endif @endforeach
Description AmountStatus
{{ $item->description }} KES {{ number_format($item->total) }}{{ $covered ? '✓ PAID' : '' }}
@endif
Issued by: {{ $receipt->issuer->name ?? Auth::user()->name }}
@if($inv && $paymentsGrouped->count() > 1)
Note: This invoice has {{ $paymentsGrouped->count() }} separate payments. For a consolidated receipt showing all payments, click "View Full Receipt" at the top.
@endif @include('partials._document-footer', ['showPaybill' => true])
@endsection