@extends('pdf.layouts.app')
@section('styles')
@endsection
@section('content')
| Account No. |
Account Name |
Debit |
Credit |
Balance |
@php $firstSection = true; @endphp
@foreach($data as $account)
@php
if (!$firstSection) {
// Add spacer row
echo ' |
';
// Add header row
echo '';
}
$firstSection = false;
renderAccount($account, 1, true);
@endphp
@endforeach
Total Balance: {{ number_format($totals['grand_total_balance'] ?? 0, 2) }}
@endsection
@php
/**
* Recursive function to render hierarchical accounts.
*/
function renderAccount($account, $level = 1, $isTopLevel = false)
{
$padding = 20 * ($level - 1);
echo '';
echo '| ' . e($account['serial_number']) . ' | ';
echo '' . e($account['title']) . ' | ';
echo '' . number_format($account['total_debit'], 2) . ' | ';
echo '' . number_format($account['total_creditor'], 2) . ' | ';
echo '' . number_format($account['balance'], 2) . ' | ';
echo '
';
// Render children
if (!empty($account['children'])) {
foreach ($account['children'] as $child) {
renderAccount($child, $level + 1, false);
}
// Only add subtotal rows for top-level accounts (level 1)
if ($isTopLevel) {
// Grand Total row
echo '';
echo '| Grand Total | ';
echo '' . number_format($account['total_debit'], 2) . ' | ';
echo '' . number_format($account['total_creditor'], 2) . ' | ';
echo '' . number_format($account['balance'], 2) . ' | ';
echo '
';
// Net Balance row
echo '';
echo '| Net Balance | ';
echo '' . number_format($account['balance'], 2) . ' | ';
echo '
';
}
}
}
@endphp