@php $grandTotal = 0; @endphp
@foreach($grouped_data as $paymentMethod => $customers)
|
{{ strtoupper($paymentMethod) }}
|
@foreach($customers as $customerName => $details)
| {{ ucfirst($customerName) }} |
@php
$customerTotal = 0;
// Group first by order_id, then inside group by receipt_id
$ordersGrouped = collect($details['orders'])->groupBy('order_id');
@endphp
@foreach($ordersGrouped as $orderId => $orderGroup)
@php
$orderRowCount = $orderGroup->count();
$firstOrderRow = true;
@endphp
@php
$receiptGroups = $orderGroup->groupBy('receipt_id');
@endphp
@foreach($receiptGroups as $receiptId => $transactions)
@php
$receiptRowCount = count($transactions);
$firstReceiptRow = true;
@endphp
@foreach($transactions as $txn)
{{-- Order No (rowspan) --}}
@if($firstOrderRow)
| {{ $txn['order_id'] }} |
{{ ucfirst($customerName) }} |
@php $firstOrderRow = false; @endphp
@endif
{{ date('d-m-Y', strtotime($txn['transaction_date'])) }} |
{{ number_format(floatval(str_replace(',', '', $txn['amount'])), 2) }} |
{{-- Receipt ID (Bill No) (rowspan) --}}
@if($firstReceiptRow)
{{ $txn['receipt_id'] }} |
@php $firstReceiptRow = false; @endphp
@endif
{{ $txn['remark'] }} |
{{ $txn['rcpt_type'] }} |
@php $customerTotal += floatval(str_replace(',', '', $txn['amount'])); @endphp
@endforeach
@endforeach
@endforeach
{{-- Customer Total --}}
| Subtotal for {{ ucfirst($customerName) }}: |
{{ number_format($customerTotal, 2) }} |
@php $grandTotal += $customerTotal; @endphp
@endforeach
@endforeach
{{-- Grand Total --}}
| Grand Total: |
{{ number_format($grandTotal, 2) }} |