{{-- ═══ ANC BILLING — mirrors the OPD encounter's Products/Services table + Payments. Plus an ANC-specific "Package Status" banner at the top for package patients. Expects: $registration AncRegistration $backingVisit Visit (has invoice with items/payments loaded) $coverage array from AncPackage::coverage() $invoice shortcut = $backingVisit->invoice Element IDs (billingItems, billingTable, grandTotal, bill-row-*, bill-total-*) are deliberately the same as the OPD view so the shared OPD billing JS (addBillingRow, updateBillItem, selectService) binds. --}} @php $user = auth()->user(); $canEditBilling = $user && ($user->hasRole('Super Admin') || $user->hasRole('Hospital Admin') || $user->hasRole('Receptionist') || $user->hasRole('Clinician') || $user->hasRole('Nurse')); $visit = $backingVisit; $hasPkg = ($coverage['mode'] ?? 'per_visit') === 'package'; $pkg = $coverage['package'] ?? null; @endphp {{-- ═══ PACKAGE STATUS (only for package patients) ═══ Round 10 single-invoice model. The package line lives on the visit invoice below; this panel is a status banner only. There is no Pay Package form here — payments flow through the standard Payments panel at the bottom (same as every other module). --}} @if($hasPkg && $pkg)

Package Status

@if($coverage['fully_paid']) Fully paid @else Balance owed {{-- Round 12: package balance lives on the original --}} {{-- "package invoice" (the one carrying the anc_package --}} {{-- line). We open a modal that submits a payment against --}} {{-- THAT invoice's id, not the current visit's invoice, --}} {{-- so the package debt actually decreases. Only show when --}} {{-- there's a balance owed AND a package invoice exists --}} {{-- (defensive — shouldn't be possible to have a balance --}} {{-- without an invoice, but UI shouldn't crash if it is). --}} @if(($packageInvoice ?? null) && $canEditBilling) @endif @endif

{{ $pkg['label'] }}

{{ $pkg['description'] }}

Paid KES {{ number_format($coverage['paid']) }} of {{ number_format($pkg['price']) }} @if($coverage['balance'] > 0)  ·  Balance: KES {{ number_format($coverage['balance']) }} @endif

Consultations: {{ $coverage['consultations_used'] }} of {{ $coverage['consultations_quota'] }} @if(($coverage['full_profile_quota'] ?? 0) > 0)  ·  Full ANC Profile: {{ $coverage['full_profile_used'] >= $coverage['full_profile_quota'] ? 'used' : 'available' }} @endif @if(($coverage['ultrasounds_quota'] ?? 0) > 0)  ·  Ultrasounds: {{ $coverage['ultrasounds_used'] }} of {{ $coverage['ultrasounds_quota'] }} @endif

@if($coverage['balance'] > 0)

Each visit must collect at least 50% of the current package balance before close. Use the Collect Package Payment button above — payments allocate to the package's original invoice, not to this visit.

@endif
{{-- ─── Collect Package Payment Modal (round 12) ──────────────────── --}} {{-- Renders only when there's an unpaid balance + a package invoice. --}} {{-- Submits to the standard billing.payment route with the PACKAGE --}} {{-- INVOICE'S id, not the current visit's invoice — that's the whole --}} {{-- point: payment lands where the debt is, not where the form lives. --}} @if(($packageInvoice ?? null) && $coverage['balance'] > 0 && $canEditBilling) @endif @endif {{-- ═══ PRODUCTS / SERVICES (visit extras) ═══ --}}

Products / Services

@if($canEditBilling)@endif
@if($canEditBilling)@endif @if($visit->invoice && $visit->invoice?->items->count()) @foreach($visit->invoice?->items as $item) @php // Pharmacy items are managed from the Prescriptions section (same as OPD). // anc_consultation, anc_package, anc_package_carry, anc_full_profile, // anc_ultrasound lines are system-owned — never editable here. $systemOwned = in_array($item->source_type, [ 'prescription', 'anc_consultation', 'anc_package', 'anc_package_carry', 'anc_full_profile', 'anc_ultrasound', ], true); $isEditable = $canEditBilling && ! $systemOwned; $isCovered = (float) $item->total === 0.0 && str_contains(strtolower($item->description), 'covered'); @endphp @if($canEditBilling) @endif @endforeach @endif @if($canEditBilling)@endif
Product or Service Instructions Existing Qty Qty Unit Selling Price TotalDelete
{{ $item->description }} @if($isCovered) PACKAGE @endif {{ $item->notes ?? '—' }} @if($isEditable) @else {{ $item->quantity }} @endif @if($isEditable) @else {{ number_format($item->unit_price) }} @endif {{ number_format($item->total) }} @if($item->source_type === 'prescription') 🔒 @elseif($systemOwned) 🔒 @else
@csrf @method('DELETE')
@endif
Total {{ number_format($visit->invoice?->total_amount ?? 0) }}
{{-- ═══ PAYMENTS (shared partial, same as OPD / Dental / IPD) ═══ --}}

Payments

@include('partials._payment-section', ['visit' => $visit])