TABEL LAPORAN OMSET PERIODE {{ $tahun_dari }} - {{ $tahun_sampai }} @if (!empty($nama_proyek))
Proyek: {{ $nama_proyek }} @elseif(empty($proyek_id) || $proyek_id == '')
Semua Proyek @endif

@php // Mengecek jika semua proyek; grouping dengan nama proyek $isSemuaProyek = empty($proyek_id) || $proyek_id == ''; @endphp @if ($isSemuaProyek) @php // Group data by project name $grouped = []; foreach ($data as $row) { $grouped[$row['proyek']][] = $row; } // Prepare grand total across all projects (untuk summary akhir) $grandTotalAllProyek = []; for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) { $grandTotalAllProyek[$tahun] = 0; } @endphp @foreach ($grouped as $proyekName => $rows)
Proyek: {{ $proyekName }}
@for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor @php $totalProyek = []; for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) { $totalProyek[$tahun] = 0; } @endphp @foreach ($rows as $row) @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @php $value = isset($row[$tahun]) ? $row[$tahun] : 0; $totalProyek[$tahun] += $value; $grandTotalAllProyek[$tahun] += $value; @endphp @endfor @endforeach @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor
Bulan{{ $tahun }}
{{ $row['bulan'] }}{{ 'Rp ' . number_format($value, 0, ',', '.') }}
Total{{ 'Rp ' . number_format($totalProyek[$tahun], 0, ',', '.') }}
@endforeach
Grand Total Semua Proyek:
@for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor
Total{{ $tahun }}
Rp{{ 'Rp ' . number_format($grandTotalAllProyek[$tahun], 0, ',', '.') }}
@else @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor @php $grandTotal = []; for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) { $grandTotal[$tahun] = 0; } @endphp @foreach ($data as $row) @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @php $value = isset($row[$tahun]) ? $row[$tahun] : 0; $grandTotal[$tahun] += $value; @endphp @endfor @endforeach @for ($tahun = $tahun_dari; $tahun <= $tahun_sampai; $tahun++) @endfor
Bulan{{ $tahun }}
{{ $row['bulan'] }}{{ 'Rp ' . number_format($value, 0, ',', '.') }}
Total{{ 'Rp ' . number_format($grandTotal[$tahun], 0, ',', '.') }}
@endif