@php /* |-------------------------------------------------------------------------- | DEVOTEE GROUPS (same logic as receipts index / receipt view) |-------------------------------------------------------------------------- | One group per devotee, each with its own items. | Old receipts (no devotee rows) fall back to devotee_name + items. */ // Normalise anything (null / array / Eloquent collection) into a base Collection $toCollection = fn ($value) => $value instanceof \Illuminate\Support\Collection ? $value : collect($value); $groups = $toCollection($receipt->devotees ?? [])->map(function ($devoteeRow) use ($toCollection) { return [ 'name' => $devoteeRow->devotee_name ?: 'Walk-in Devotee', 'nakshatram' => $devoteeRow->nakshatram, 'items' => $toCollection($devoteeRow->items ?? []), ]; }); if ($groups->isEmpty()) { $groups->push([ 'name' => $receipt->devotee_name ?: 'Walk-in Devotee', 'nakshatram' => $receipt->nakshatram, 'items' => $toCollection($receipt->items ?? []), ]); } $groupCount = $groups->count(); $sumItems = fn ($items) => $items->sum(fn ($item) => (float) ($item->amount ?? 0)); $grandTotal = $groups->sum(fn ($group) => $sumItems($group['items'])); $totalAmount = (float) ($receipt->total_amount ?: $grandTotal); $receiptNo = $receipt->receipt_number ?: '#RC-' . str_pad($receipt->id, 6, '0', STR_PAD_LEFT); $receiptDate = optional($receipt->display_date)->format('d-m-Y'); $templeName = config('app.temple_name', 'TempleMitra Devasthanam'); @endphp
| Sl.No | Vazhipad | Qty | Amount |
|---|---|---|---|
| {{ $loop->iteration }} | {{ $item->vazhipad?->name ?? $item->vazhipad?->vazhipad_name ?? 'Offering' }} | {{ $item->quantity ?? 1 }} | ₹{{ number_format((float) ($item->amount ?? 0), 2) }} |
| No Vazhipad | |||