@extends('layouts.app') @section('title', 'Dispensed Products') @section('content') {{-- ───────────────────────────────────────────────────────────────────── Dispensed Products page (admin only). Lists recent PharmacyDispense rows so admins can find a wrong dispense and click Reverse. The Reverse modal at the bottom posts to the same /pharmacy/dispenses/{id}/reverse endpoint as the per- visit dispense form, so all the safety + audit + invoice handling is shared. ───────────────────────────────────────────────────────────────────── --}}

Dispensed Products

Recent dispense events · Back to Pharmacy

@if(session('success'))
{{ session('success') }}
@endif @if(session('warning'))
{{ session('warning') }}
@endif {{-- Stat strip --}}

Total Dispenses

{{ number_format($stats['total']) }}

Active

{{ number_format($stats['active']) }}

Reversed

{{ number_format($stats['reversed']) }}

Refund Pending

{{ number_format($stats['refund_pending']) }}

{{-- Filter bar --}}
@if(request()->hasAny(['from','to','q','status'])) Reset @endif

Showing dispenses from {{ $from->format('d M Y') }} to {{ $to->format('d M Y') }}. Default window is the last 7 days.

{{-- Table --}}
@forelse($dispenses as $disp) @php $patient = $disp->patient; $drug = $disp->drugItem; $isRev = $disp->reversed_at !== null; @endphp @empty @endforelse
Date / Time Patient Drug Qty Total (KES) Dispensed By Status Action
{{ $disp->dispensed_at?->format('d M Y') }}
{{ $disp->dispensed_at?->format('H:i') }}
@if($patient)
{{ trim(($patient->first_name ?? '') . ' ' . ($patient->last_name ?? '')) ?: '—' }}
{{ $patient->mrn ?? '' }}
@else @endif
{{ $drug->name ?? ($disp->prescription->drug_name ?? '—') }}
@if($drug && $drug->strength)
{{ $drug->strength }}
@endif
{{ $disp->quantity_dispensed }} {{ number_format($disp->total_price ?? 0, 2) }} {{ $disp->dispensedBy->name ?? '—' }} @if($isRev) REVERSED @if($disp->refund_status === 'pending') REFUND PENDING @endif
by {{ $disp->reversedBy->name ?? 'unknown' }} · {{ $disp->reversed_at?->format('d M Y, H:i') }}
@if($disp->reversal_reason)
"{{ Str::limit($disp->reversal_reason, 80) }}"
@endif @else ACTIVE @endif
@if(!$isRev) @endif @if($disp->prescription && $disp->prescription->visit_id) View visit @endif
No dispenses found in this date range. @if($q || $status !== 'all') Try clearing the search or switching status to "All". @endif
@if($dispenses->hasPages())
{{ $dispenses->links() }}
@endif
{{-- ─── Reverse Dispense Modal ───────────────────────────────────────── Same modal as on the per-visit dispense page. Posts to the same endpoint. The page is admin-gated at the route level, so we don't re-check $isAdmin around the modal. --}} @endsection