{{ $lokasi['nama'] }}

LAPORAN SALDO TAGIHAN PER DIKTI

@php // Define base columns (non-numeric) $base_cols = [ ["key" => "no", "label" => "No", "width" => "30px"], ["key" => "kode_lokasi", "label" => "Kode Lokasi", "width" => "90px"], ["key" => "nama", "label" => "Nama Lokasi", "width" => "180px"] ]; // Define grouped header types $groupHeaders = [ ['label' => 'SALOD AWAL', 'prefix' => 'saw_'], ['label' => 'TAGIHAN', 'prefix' => 'debet_'], ['label' => 'PEMBAYARAN', 'prefix' => 'kredit_'], ['label' => 'SALDO AKHIR', 'prefix' => 'sak_'] ]; // Capture keys of dynamic parameters $paramKeys = array_map(fn($p) => $p['key'], $kode_params); // Generate detailed columns with groups $columns = $base_cols; foreach ($groupHeaders as $group) { foreach ($paramKeys as $paramKey) { $columns[] = [ "key" => $group['prefix'] . $paramKey, "label" => strtoupper($paramKey), // Can be replaced with label if needed "width" => "90px" ]; } $columns[] = [ "key" => $group['prefix'] . "total", "label" => "TOTAL", "width" => "90px" ]; } // Header Row 1 (rowspan for base, colspan for grouped) $thead_row1 = []; foreach ($base_cols as $col) { $thead_row1[] = [ 'label' => $col['label'], 'colspan' => 1, 'rowspan' => 2, 'width' => $col['width'] ]; } foreach ($groupHeaders as $group) { $colspan = count($paramKeys) + 1; $thead_row1[] = [ 'label' => $group['label'], 'colspan' => $colspan, 'rowspan' => 1, 'width' => null // for group header, optional ]; } // Header Row 2 (param and TOTAL) $thead_row2 = []; foreach ($groupHeaders as $group) { foreach ($kode_params as $param) { $thead_row2[] = [ 'label' => strtoupper($param['label']), 'width' => "90px" ]; } $thead_row2[] = ['label' => 'TOTAL', 'width' => "90px"]; } // Prepare totals $numeric_keys = []; foreach ($groupHeaders as $group) { foreach ($paramKeys as $paramKey) { $numeric_keys[] = $group['prefix'] . $paramKey; } $numeric_keys[] = $group['prefix'] . 'total'; } $totals = array_fill_keys($numeric_keys, 0); @endphp @foreach ($thead_row1 as $col) @endforeach @foreach ($thead_row2 as $col) @endforeach @foreach ($data as $i => $row) @foreach ($columns as $col) @php $key = $col['key']; $value = $row[$key] ?? ''; $is_numeric = in_array($key, $numeric_keys); if ($is_numeric) $totals[$key] += floatval($value); @endphp @endforeach @endforeach {{-- Totals --}} @foreach ($columns as $col) @if (in_array($col['key'], $numeric_keys)) @endif @endforeach
{{ $col['label'] }}
{{ $col['label'] }}
{{ $is_numeric ? App\Helper\SaiHelpers::number_format_decimal($value, $export_type) : $value }}
Total {{ App\Helper\SaiHelpers::number_format_decimal($totals[$col['key']], $export_type) }}