@php $peakMonth = $monthly->sortByDesc('total_amount')->first(); $maxAmt = $monthly->max('total_amount'); // Build pivot matrix for category breakdown $months = $monthlyByItem->pluck('month')->unique()->sort()->values(); $itemNames = $monthlyByItem->pluck('expense_item_name')->unique()->values(); $matrix = []; foreach ($monthlyByItem as $row) { $matrix[$row->month][$row->expense_item_name] = $row->total_amount; } @endphp {{-- Stat cards --}}
| Month | Entries | Branches | Total Amount | vs Avg | Volume |
|---|---|---|---|---|---|
| {{ $row->month }} | {{ number_format($row->entry_count) }} | {{ number_format($row->branch_count) }} | {{ number_format($row->total_amount, 2) }} | {{ $diff > 0 ? '+' : '' }}{{ number_format($diff, 2) }} |
|
| Total | {{ number_format($totals['grand_total'], 2) }} | ||||
| Month | @foreach($itemNames as $name){{ $name }} | @endforeachRow Total |
|---|---|---|
| {{ $month }} | @foreach($itemNames as $name)@if(!empty($matrix[$month][$name])) {{ number_format($matrix[$month][$name], 2) }} @else — @endif | @endforeach{{ number_format($rowTotal, 2) }} |
| Column Total | @foreach($itemNames as $name){{ number_format($monthlyByItem->where('expense_item_name', $name)->sum('total_amount'), 2) }} | @endforeach{{ number_format($totals['grand_total'], 2) }} |