@include('templates.pdf_header', [ 'organisation' => $organisation, 'title' => 'BALANCE SHEET COMPARISON', 'currency_code' => $currency ]) @php function fmtAmount($value) { return ($value ?? 0) != 0 ? number_format($value, 0) : ''; } function findTotalByKey($items, $key, $field) { foreach ($items as $item) { if (($item['total_key'] ?? '') === $key) { return $item[$field] ?? 0; } if (!empty($item['children'])) { $val = findTotalByKey($item['children'], $key, $field); if ($val !== null) return $val; } } return 0; } function renderComparison($items, $level = 0, &$totals = []) { foreach ($items as $item) { // ---------------- CAPTURE TOTALS ---------------- if (($item['total_key'] ?? '') === 'total_equity') { $totals['equity_current'] = $item['value_current'] ?? 0; $totals['equity_previous'] = $item['value_previous'] ?? 0; } if (($item['total_key'] ?? '') === 'total_liabilities') { $totals['liabilities_current'] = $item['value_current'] ?? 0; $totals['liabilities_previous'] = $item['value_previous'] ?? 0; } if (($item['total_key'] ?? '') === 'total_equity_and_liability') { $equityCurrent = findTotalByKey($items, 'closing_equity', 'value_current'); $equityPrevious = findTotalByKey($items, 'closing_equity', 'value_previous'); $liabilityCurrent = findTotalByKey($items, 'total_liabilities', 'value_current'); $liabilityPrevious = findTotalByKey($items, 'total_liabilities', 'value_previous'); $item['value_current'] = $equityCurrent + $liabilityCurrent; $item['value_previous'] = $equityPrevious + $liabilityPrevious; } // Skip separate total_equity row if not needed if (($item['total_key'] ?? '') === 'total_equity') ; $current = $item['value_current'] ?? 0; $previous = $item['value_previous'] ?? 0; // ---------------- SKIP ZERO ROWS ---------------- if ( isset($item['row_type']) && $item['row_type'] !== 'header' && $current == 0 && $previous == 0 ) continue; // ---------------- SUBCATEGORY FIX ---------------- if (($item['level'] ?? '') === "subcategory") { // DO NOT zero out values $current = $item['value_current'] ?? 0; $previous = $item['value_previous'] ?? 0; } // ---------------- RENDER ---------------- $indentClass = $level > 0 ? "indent-{$level}" : ''; $boldClass = !empty($item['bold']) ? 'bold' : ''; echo ''; echo ''; echo ''; echo ''; echo ''; // ---------------- CHILDREN ---------------- if (!empty($item['children'])) { renderComparison($item['children'], $level + 1, $totals); } } } @endphp @php $totals = []; renderComparison($data, 0, $totals); @endphp
Particulars Current Year ({{ $currentYear->financial_year ?? '' }}) Previous Year ({{ $previousYear->financial_year ?? '' }})
' . ($item['label'] ?? '') . '' . fmtAmount($current) . '' . fmtAmount($previous) . '
MWENYEKITI
MENEJA MKUU
MJUMBE