{{-- Statement "By type" layout: one table per kind of bill (Pharmacy, Appointment, Lab, Admission …) like the paper statement. Display only — paying stays in the Pay form. Needs $typeGroups, $money, $fmt. --}} @php $titles = [ 'pharmacy' => 'Pharmacy Info', 'appointment' => 'Appointment Info', 'lab' => 'Lab Info', 'image' => 'Imaging Info', 'admission' => 'Admission Info', 'emergency' => 'Emergency Info', 'service' => 'Services Info', 'operation' => 'Operations Info', 'delivery' => 'Delivery Info', ]; $num = fn ($v) => number_format((float) $v, 2); @endphp
@foreach ($typeGroups as $type => $rows)
{{ $titles[$type] ?? ucfirst($type) . ' Info' }}
@if ($type === 'pharmacy') {{-- Every drug on the day it was given (medication chart: date, time, nurse), a total per day, then the grand total with what was paid. With the Product filter, only that product's lines (e.g. IV each day). --}} @php $productFilter = $filters['product'] ?? ''; $lines = $rows->flatMap(fn ($it) => collect($it['details'])->map(fn ($d) => $d + [ 'day' => $d['date'] ?? $it['date'], 'at' => $d['time'] ?? $it['time'], 'ref' => $it['ref'], 'invoice_note' => $it['note'], ]))->sortBy(fn ($l) => ($l['day'] ?? '') . ' ' . ($l['at'] ? \Carbon\Carbon::parse($l['at'])->format('H:i:s') : '99'))->values(); $showBy = $lines->contains(fn ($l) => !empty($l['by'])); $cols = 7 + ($showBy ? 1 : 0); // columns before Paid @endphp @if ($productFilter !== '')
Only {{ $productFilter }} — {{ $lines->pluck('day')->unique()->count() }} day(s), {{ $lines->count() }} time(s) given.
@endif @if ($showBy)@endif @if ($productFilter === '')@endif @foreach ($lines->groupBy('day') as $day => $dayLines) @foreach ($dayLines as $l) @if ($showBy)@endif @if ($productFilter === '')@endif @endforeach @if ($productFilter === '')@endif @endforeach @foreach ($rows->pluck('note')->filter()->unique() as $note) @endforeach @if ($productFilter === '') @else @endif
DateTime givenGiven / created byPOS numberProductQuantityUnit price TotalPaidDiscountBalance
{{ $fmt($day) }} {{ !$l['at'] ? '—' : (!empty($l['time_local']) ? \Carbon\Carbon::parse($l['at'])->format('h:i A') : local_time($l['at'])) }}{{ $l['by'] ?? '—' }}{{ $l['ref'] }} {{ $l['name'] }}@if (!empty($l['note']))
{{ $l['note'] }}
@endif
{{ $l['qty'] }} {{ $money($l['price']) }} {{ $money($l['amount']) }}
{{ $fmt($day) }} — total {{ $dayLines->sum(fn ($l) => (float) ($l['qty_num'] ?? 0)) + 0 }} {{ $num($dayLines->sum('amount')) }}
{{ $note }}
Total ({{ $rows->count() }} invoice{{ $rows->count() == 1 ? '' : 's' }}: {{ $rows->pluck('ref')->implode(', ') }}) {{ $money($rows->sum('charge')) }} {{ $money($rows->sum('paid')) }} {{ $money($rows->sum('discount')) }} {{ $money($rows->sum('balance')) }}Total {{ $productFilter }} {{ $lines->sum(fn ($l) => (float) ($l['qty_num'] ?? 0)) + 0 }} {{ $money($lines->sum('amount')) }}
@elseif ($type === 'admission') @foreach ($rows as $it) @if ($it['note']) @endif @endforeach
AdmissionDate inDate outDoctorRoomDays CostPaidDiscountBalance
{{ $it['ref'] }} {{ $fmt($it['date_in']) }} {{ $it['date_out'] ? $fmt($it['date_out']) : '—' }} {{ $it['doctor'] }} {{ $it['room'] }} {{ $it['days'] ?? '—' }} {{ $num($it['charge']) }} {{ $num($it['paid']) }} {{ $num($it['discount']) }} {{ $num($it['balance']) }}
{{ $it['note'] }}
Total {{ $num($rows->sum('charge')) }} {{ $num($rows->sum('paid')) }} {{ $num($rows->sum('discount')) }} {{ $num($rows->sum('balance')) }}
@else {{-- appointment, lab, imaging, emergency, services, operations, delivery --}} @php $refHead = ['appointment' => 'App no.', 'emergency' => 'Emergency'][$type] ?? 'No.'; $showKind = $rows->contains(fn ($i) => $i['kind']); $showDoctor = $rows->contains(fn ($i) => $i['doctor']); $span = 4 + ($showKind ? 1 : 0) + ($showDoctor ? 1 : 0); @endphp @if ($showDoctor)@endif @if ($showKind)@endif @foreach ($rows as $it) @php $desc = $type === 'lab' && $it['details'] ? collect($it['details'])->pluck('name')->implode(', ') : preg_replace('/^[^·]*·\s*/', '', $it['label']); @endphp @if ($showDoctor)@endif @if ($showKind)@endif @endforeach
{{ $refHead }}DateTimeDoctor{{ $type === 'appointment' || $type === 'emergency' ? 'Department' : 'Type' }}Description Total amountPaidDiscountBalance
{{ $it['ref'] }} {{ $fmt($it['date']) }} {{ local_time($it['time']) }}{{ $it['doctor'] }}{{ ucfirst((string) $it['kind']) }}{{ $desc }}@if ($it['note'])
{{ $it['note'] }}
@endif
{{ $num($it['charge']) }} {{ $num($it['paid']) }} {{ $num($it['discount']) }} {{ $num($it['balance']) }}
Total {{ $num($rows->sum('charge')) }} {{ $num($rows->sum('paid')) }} {{ $num($rows->sum('discount')) }} {{ $num($rows->sum('balance')) }}
@endif
@endforeach