@extends('pdf.layouts.app')
@section('title', 'General Ledger Report')
@section('styles')
@endsection
@section('content')
@php
$isRtl = ($direction ?? 'rtl') === 'rtl';
// Translation helper
$t = [
'total' => $isRtl ? 'الإجمالي' : 'Total',
'difference' => $isRtl ? 'الفرق' : 'Difference',
'description' => $isRtl ? 'البيان' : 'Description',
'serial_number' => $isRtl ? 'الرقم التسلسلي' : 'Serial Number',
'account' => $isRtl ? 'الحساب' : 'Account',
'opening_debit' => $isRtl ? 'مدين افتتاحي' : 'Opening Debit',
'opening_credit' => $isRtl ? 'دائن افتتاحي' : 'Opening Credit',
'period_debit' => $isRtl ? 'مدين الفترة' : 'Period Debit',
'period_credit' => $isRtl ? 'دائن الفترة' : 'Period Credit',
'total_debit_col' => $isRtl ? 'إجمالي مدين' : 'Total Debit',
'total_credit_col' => $isRtl ? 'إجمالي دائن' : 'Total Credit',
'final_debit' => $isRtl ? 'رصيد مدين' : 'Closing Debit',
'final_credit' => $isRtl ? 'رصيد دائن' : 'Closing Credit',
'no_data' => $isRtl ? 'لا توجد بيانات للعرض' : 'No data available to display',
];
@endphp
@if(isset($data['data']) && is_array($data['data']))
@foreach($data['data'] as $account)
@php renderAccountSection($account, $t, $isRtl); @endphp
@endforeach
@elseif(is_array($data))
@foreach($data as $account)
@php renderAccountSection($account, $t, $isRtl); @endphp
@endforeach
@endif
{{-- Grand total section --}}
| {{ $t['description'] }} |
{{ $t['opening_debit'] }} |
{{ $t['opening_credit'] }} |
{{ $t['period_debit'] }} |
{{ $t['period_credit'] }} |
{{ $t['total_debit_col'] }} |
{{ $t['total_credit_col'] }} |
{{ $t['final_debit'] }} |
{{ $t['final_credit'] }} |
| {{ $t['total'] }} |
{{ number_format($totals['total_debit_initial'] ?? 0, 2) }} |
{{ number_format($totals['total_creditor_initial'] ?? 0, 2) }} |
{{ number_format($totals['total_debit_within'] ?? 0, 2) }} |
{{ number_format($totals['total_creditor_within'] ?? 0, 2) }} |
{{ number_format($totals['total_debit'] ?? 0, 2) }} |
{{ number_format($totals['total_creditor'] ?? 0, 2) }} |
{{ number_format($totals['closing_debit'] ?? 0, 2) }} |
{{ number_format($totals['closing_creditor'] ?? 0, 2) }} |
| {{ $t['difference'] }} |
{{ number_format(($totals['total_debit_initial'] ?? 0) - ($totals['total_creditor_initial'] ?? 0), 2) }} |
{{ number_format(($totals['total_debit_within'] ?? 0) - ($totals['total_creditor_within'] ?? 0), 2) }} |
{{ number_format(($totals['total_debit'] ?? 0) - ($totals['total_creditor'] ?? 0), 2) }} |
{{ number_format(($totals['closing_debit'] ?? 0) - ($totals['closing_creditor'] ?? 0), 2) }} |
@endsection
@php
function renderAccountSection($account, $t, $isRtl)
{
if (!isset($account['title']) || !isset($account['serial_number'])) return;
$serialNumber = $account['serial_number'] ?? '';
$hasChildren = !empty($account['children']);
echo '';
// Account header
echo '';
// Table
echo '';
echo '';
echo '| ' . e($t['account']) . ' | ';
echo '' . e($t['serial_number']) . ' | ';
echo '' . e($t['opening_debit']) . ' | ';
echo '' . e($t['opening_credit']) . ' | ';
echo '' . e($t['period_debit']) . ' | ';
echo '' . e($t['period_credit']) . ' | ';
echo '' . e($t['total_debit_col']) . ' | ';
echo '' . e($t['total_credit_col']) . ' | ';
echo '' . e($t['final_debit']) . ' | ';
echo '' . e($t['final_credit']) . ' | ';
echo '
';
echo '';
// Main account row
renderAccountRow_TB($account, 1, $isRtl);
// Children
if ($hasChildren) {
foreach ($account['children'] as $child) {
renderAllChildren_TB($child, 2, $isRtl);
}
}
echo '';
// Total row
echo '';
echo '| ' . e($t['total']) . ' | ';
echo '' . number_format($account['total_debit_initial'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor_initial'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_debit_within'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor_within'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_debit'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor'] ?? 0, 2) . ' | ';
echo '' . number_format($account['closing_debit'] ?? 0, 2) . ' | ';
echo '' . number_format($account['closing_creditor'] ?? 0, 2) . ' | ';
echo '
';
echo '
';
echo '';
}
function renderAllChildren_TB($account, $level, $isRtl)
{
renderAccountRow_TB($account, $level, $isRtl);
if (!empty($account['children'])) {
foreach ($account['children'] as $child) {
renderAllChildren_TB($child, $level + 1, $isRtl);
}
}
}
function renderAccountRow_TB($account, $level, $isRtl)
{
$indent = ($level - 1) * 18;
$levelClass = 'level-' . min($level, 6);
$padStyle = $isRtl
? 'padding-right:' . $indent . 'px;'
: 'padding-left:' . $indent . 'px;';
echo '
';
echo '| ' . e($account['title']) . ' | ';
echo '' . ($account['serial_number'] ?? '') . ' | ';
echo '' . number_format($account['total_debit_initial'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor_initial'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_debit_within'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor_within'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_debit'] ?? 0, 2) . ' | ';
echo '' . number_format($account['total_creditor'] ?? 0, 2) . ' | ';
echo '' . number_format($account['closing_debit'] ?? 0, 2) . ' | ';
echo '' . number_format($account['closing_creditor'] ?? 0, 2) . ' | ';
echo '
';
}
@endphp