@extends('pdf.layouts.app')
@section('styles')
@endsection
@section('content')
@php
$isRtl = ($direction ?? 'rtl') === 'rtl';
$thNo = $isRtl ? 'رقم الحساب' : 'Account No.';
$thName = $isRtl ? 'اسم الحساب' : 'Account Name';
$thDebit = $isRtl ? 'مدين' : 'Debit';
$thCredit = $isRtl ? 'دائن' : 'Credit';
$thBalance = $isRtl ? 'الرصيد' : 'Balance';
@endphp
| {{ $thNo }} |
{{ $thName }} |
{{ $thDebit }} |
{{ $thCredit }} |
{{ $thBalance }} |
@php $firstSection = true; @endphp
@foreach($data as $account)
@php
if (!$firstSection) {
// Spacer between top-level sections
echo '
| |
';
// Repeat header row
echo '';
}
$firstSection = false;
renderAccount($account, 1, true);
@endphp
@endforeach
{{ $isRtl ? 'إجمالي الرصيد:' : '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 = 16 * ($level - 1);
$levelClass = 'level-' . min($level, 6);
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 '| ' . (app()->getLocale() === 'ar' ? 'الإجمالي' : '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 '| ' . (app()->getLocale() === 'ar' ? 'صافي الرصيد' : 'Net Balance') . ' | ';
echo '' . number_format($account['balance'], 2) . ' | ';
echo '
';
}
}
}
@endphp