<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>كشف حساب مجمع - <?php echo e($displayMode === 'combined' ? 'مدمج' : 'منفصل'); ?></title>
    
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(isset($settings['font_print']) && $settings['font_print']): ?>
        <link href="https://fonts.googleapis.com/css2?family=<?php echo e(str_replace(' ', '+', $settings['font_print'])); ?>:wght@400;500;700;900&display=swap" rel="stylesheet">
    <?php else: ?>
        <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;900&display=swap" rel="stylesheet">
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/xlsx-js-style@1.2.0/dist/xlsx.min.js"></script>
    
    <?php echo app('Illuminate\Foundation\Vite')(['resources/css/app.css', 'resources/js/app.js']); ?>
    
    <style>
        body {
            font-family: '<?php echo e($settings['font_print'] ?? 'Tajawal'); ?>', sans-serif;
            background-color: #f8fafc;
            color: #0f172a;
        }
        
        .print-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 2rem;
            background: white;
            min-height: 100vh;
            box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
        }

        table {
            border-collapse: collapse;
            width: 100%;
        }
        
        @media print {
            body { background: white; }
            .print-container { box-shadow: none; padding: 0; margin: 0; max-width: 100%; min-height: auto; }
            .no-print { display: none !important; }
            @page { margin: 1cm; }
            
            tr { page-break-inside: avoid; }
            thead { display: table-header-group; }
            tfoot { display: table-footer-group; }
            
            * {
                -webkit-print-color-adjust: exact !important;
                color-adjust: exact !important;
                print-color-adjust: exact !important;
            }
            .page-break { page-break-after: always; }
            .page-number:after { content: counter(page); }
        }
        
        @media screen {
            .page-number:after { content: '1'; }
            .page-break { border-bottom: 8px dashed #e2e8f0; margin: 4rem 0; }
        }
    </style>
</head>
<body>

    <div class="no-print bg-slate-800 text-white p-4 sticky top-0 z-50 flex justify-between items-center shadow-lg">
        <div class="font-bold">خيارات التقرير (المجمع)</div>
        <div class="flex gap-2">
            <button onclick="window.print()" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded shadow font-bold text-sm flex items-center gap-2">
                <span>🖨️ طباعة / PDF</span>
            </button>
            <button onclick="exportExcel()" class="bg-emerald-600 hover:bg-emerald-500 text-white px-4 py-2 rounded shadow font-bold text-sm flex items-center gap-2">
                <span>📊 تصدير Excel</span>
            </button>
            <button onclick="window.close()" class="bg-slate-600 hover:bg-slate-500 text-white px-4 py-2 rounded shadow font-bold text-sm flex items-center gap-2">
                <span>إغلاق</span>
            </button>
        </div>
    </div>

    <div class="print-container">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($displayMode === 'separated'): ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $reportData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                <?php
                    $page = $data['page'];
                    $transactions = $data['transactions'];
                    $openingBalance = $data['openingBalance'];
                    $openingDebit = $data['openingDebit'];
                    $openingCredit = $data['openingCredit'];
                    $totalDebit = $data['totalDebit'];
                    $totalCredit = $data['totalCredit'];
                    $netBalance = $data['netBalance'];
                    $tafqeet = $data['tafqeet'];
                    $finalStatus = $data['finalStatus'];
                ?>
                <div class="<?php echo e(!$loop->last ? 'page-break' : ''); ?> flex flex-col justify-between" style="min-height: 100vh;">
                    <div>
                        <!-- HEADER -->
                        <div class="border-b-2 border-indigo-900 pb-6 mb-6 flex justify-between items-start">
                            <div class="space-y-1">
                                <h1 class="text-xl font-black text-indigo-900 mb-2"><?php echo e($headerEntityName); ?></h1>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($page->ledger->branch): ?> <div class="text-xs font-bold text-slate-700">الفرع: <?php echo e($page->ledger->branch->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($page->ledger->center): ?> <div class="text-xs font-bold text-slate-700">المركز: <?php echo e($page->ledger->center->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($page->ledger->project): ?> <div class="text-xs font-bold text-slate-700">المشروع: <?php echo e($page->ledger->project->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </div>
                            
                            <div class="text-left space-y-1">
                                <h2 class="text-lg font-black text-slate-800 mb-2">كشف حساب</h2>
                                <div class="text-xs font-bold text-slate-700"><?php echo e($page->name); ?> <span dir="ltr">(<?php echo e($page->page_number); ?>)</span></div>
                                <div class="text-xs font-bold text-slate-700"><?php echo e($page->ledger->name); ?> <span dir="ltr">(<?php echo e($page->ledger->code); ?>)</span></div>
                                <div class="text-xs font-bold text-slate-700">
                                    الفترة: 
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($dateFrom || $dateTo): ?>
                                        من <span dir="ltr"><?php echo e($dateFrom ?? 'البداية'); ?></span> إلى <span dir="ltr"><?php echo e($dateTo ?? 'النهاية'); ?></span>
                                    <?php else: ?>
                                        كافة العمليات
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <!-- PARTIES INFO -->
                        <div class="mb-4 text-xs font-bold border border-slate-300 bg-slate-50">
                            <div class="flex flex-col sm:flex-row sm:items-center px-3 py-1.5 <?php echo e(!$hideCreditParty ? 'border-b border-slate-200' : ''); ?>">
                                <div class="flex items-center ml-4 shrink-0 whitespace-nowrap">
                                    <div class="w-2 h-2 ml-2 shrink-0" style="background-color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>"></div>
                                    <span class="text-slate-600">الطرف المدين:</span>
                                </div>
                                <div class="flex flex-wrap items-center gap-x-4">
                                    <div class="text-slate-900"><?php echo e($page->debitAccount->party->name ?? '-'); ?> <span class="text-[11px] text-slate-500 ml-1" dir="ltr">(<?php echo e($page->debitAccount->party->code ?? '-'); ?>)</span></div>
                                    <div class="text-slate-300 hidden sm:block">|</div>
                                    <div class="text-slate-700">الحساب: <?php echo e($page->debitAccount->name ?? '-'); ?> <span class="text-indigo-700 ml-1" dir="ltr">[<?php echo e($page->debitAccount->account_number ?? '-'); ?>]</span></div>
                                </div>
                            </div>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideCreditParty): ?>
                            <div class="flex flex-col sm:flex-row sm:items-center px-3 py-1.5">
                                <div class="flex items-center ml-4 shrink-0 whitespace-nowrap">
                                    <div class="w-2 h-2 ml-2 shrink-0" style="background-color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>"></div>
                                    <span class="text-slate-600">الطرف الدائن:</span>
                                </div>
                                <div class="flex flex-wrap items-center gap-x-4">
                                    <div class="text-slate-900"><?php echo e($page->creditAccount->party->name ?? '-'); ?> <span class="text-[11px] text-slate-500 ml-1" dir="ltr">(<?php echo e($page->creditAccount->party->code ?? '-'); ?>)</span></div>
                                    <div class="text-slate-300 hidden sm:block">|</div>
                                    <div class="text-slate-700">الحساب: <?php echo e($page->creditAccount->name ?? '-'); ?> <span class="text-indigo-700 ml-1" dir="ltr">[<?php echo e($page->creditAccount->account_number ?? '-'); ?>]</span></div>
                                </div>
                            </div>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </div>

                        <!-- TABLE -->
                        <table class="w-full text-right text-xs mb-8 border-collapse">
                            <thead class="bg-indigo-50 text-indigo-900" style="border-bottom: 2px solid #c7d2fe;">
                                <tr>
                                    <th class="px-3 py-3 font-bold text-center w-12 border border-slate-200">#</th>
                                    <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">التاريخ</th>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> <th class="px-3 py-3 font-bold border border-slate-200">رقم الحركة</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <th class="px-3 py-3 font-bold border border-slate-200">البيان</th>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <th class="px-3 py-3 font-bold border border-slate-200">المرجع</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">مدين (+)</th>
                                    <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">دائن (-)</th>
                                    <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">الرصيد</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-slate-200">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($withOpeningBalance): ?>
                                <tr class="bg-slate-50 font-bold" style="background-color: #f8fafc;">
                                    <td class="px-3 py-3 text-center border border-slate-200">-</td>
                                    <td class="px-3 py-3 border border-slate-200 whitespace-nowrap"><?php echo e($dateFrom ?? '-'); ?></td>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> <td class="px-3 py-3 border border-slate-200">-</td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <td class="px-3 py-3 border border-slate-200">رصيد افتتاحي (ما قبل الفترة)</td>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <td class="px-3 py-3 border border-slate-200">-</td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <td class="px-3 py-3 border border-slate-200 text-left whitespace-nowrap" dir="ltr"><?php echo e($openingDebit > 0 ? number_format($openingDebit, 2) : '-'); ?></td>
                                    <td class="px-3 py-3 border border-slate-200 text-left whitespace-nowrap" dir="ltr"><?php echo e($openingCredit > 0 ? number_format($openingCredit, 2) : '-'); ?></td>
                                    <td class="px-3 py-3 border border-slate-200 text-left font-black whitespace-nowrap" dir="ltr" style="color: <?php echo e($openingBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($openingBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>"><?php echo e($openingBalance > 0 ? '+' : ($openingBalance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($openingBalance), 2)); ?></td>
                                </tr>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tIndex => $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                                <tr style="<?php echo e($trx->type === 'note' ? 'background-color: #fffbeb;' : ''); ?>" class="font-bold text-slate-900">
                                    <td class="px-3 py-2 text-center border border-slate-200 text-[11px]"><?php echo e($tIndex + 1); ?></td>
                                    <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap" dir="ltr"><?php echo e($trx->transaction_date->format($settings['date_format'] ?? 'Y-m-d')); ?></td>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> 
                                        <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap" dir="ltr">
                                            <?php echo e($trx->transaction_number); ?>

                                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?> 📝 <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                        </td> 
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    <td class="px-3 py-2 border border-slate-200"><?php echo e($trx->description); ?></td>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap"><?php echo e($trx->reference_number ?? '-'); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?>
                                        <td class="px-3 py-2 border border-slate-200 text-center text-slate-400">-</td>
                                        <td class="px-3 py-2 border border-slate-200 text-center text-slate-400">-</td>
                                    <?php else: ?>
                                        <td class="px-3 py-2 border border-slate-200 text-left font-bold whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->debit_amount > 0 ? ($settings['color_debit_text'] ?? '#166534') : 'inherit'); ?>">
                                            <?php echo e($trx->debit_amount > 0 ? number_format($trx->debit_amount, 2) : '-'); ?>

                                        </td>
                                        <td class="px-3 py-2 border border-slate-200 text-left font-bold whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->credit_amount > 0 ? ($settings['color_credit_text'] ?? '#991b1b') : 'inherit'); ?>">
                                            <?php echo e($trx->credit_amount > 0 ? number_format($trx->credit_amount, 2) : '-'); ?>

                                        </td>
                                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    
                                    <td class="px-3 py-2 border border-slate-200 text-left font-black whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->running_balance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($trx->running_balance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>">
                                        <?php echo e($trx->running_balance > 0 ? '+' : ($trx->running_balance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($trx->running_balance), 2)); ?>

                                    </td>
                                </tr>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                            </tbody>
                            
                            <!-- TOTALS -->
                            <tfoot class="bg-indigo-50 font-black" style="background-color: #eef2ff; border-top: 2px solid #c7d2fe;">
                                <tr>
                                    <td colspan="<?php echo e(3 + ($hideTransactionNumber ? 0 : 1) + ($hideReference ? 0 : 1)); ?>" class="px-3 py-4 text-left border border-slate-200">الإجماليات الكلية:</td>
                                    <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>">
                                        <?php echo e(number_format($totalDebit, 2)); ?>

                                    </td>
                                    <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>">
                                        <?php echo e(number_format($totalCredit, 2)); ?>

                                    </td>
                                    <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>">
                                        <?php echo e($netBalance > 0 ? '+' : ($netBalance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($netBalance), 2)); ?>

                                    </td>
                                </tr>
                                <tr style="background-color: #f8fafc;">
                                    <td colspan="<?php echo e(6 + ($hideTransactionNumber ? 0 : 1) + ($hideReference ? 0 : 1)); ?>" class="px-2 py-1.5 border border-slate-200 text-right leading-snug">
                                        <div class="text-xs font-bold text-slate-600">الرصيد كتابة: <span class="text-indigo-700 font-black"><?php echo e($tafqeet ?: 'صفر'); ?></span></div>
                                        <div class="text-xs font-bold text-slate-600">الحالة النهائية: <span class="text-indigo-900 font-black"><?php echo e($finalStatus); ?></span></div>
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <div>
                        <!-- NOTES -->
                        <div class="mt-auto text-center text-xs font-bold text-slate-600 border-t border-slate-200 pt-6 mb-6">
                            <?php echo e($settings['footer_print_notes'] ?? ''); ?>

                        </div>

                        <!-- PRINT FOOTER (Right, Center, Left) -->
                        <div class="w-full flex justify-between items-center text-[11px] font-bold text-slate-500 border-t border-slate-200 pt-4 pb-2">
                            <div class="text-right"><?php echo $footerRight; ?></div>
                            <div class="text-center"><?php echo $footerCenter; ?></div>
                            <div class="text-left" dir="ltr"><?php echo $footerLeft; ?></div>
                        </div>
                    </div>
                </div>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
        <?php else: ?>
            <!-- COMBINED MODE -->
            <?php
                $transactions = $reportData['transactions'];
                $openingBalance = $reportData['openingBalance'];
                $openingDebit = $reportData['openingDebit'];
                $openingCredit = $reportData['openingCredit'];
                $totalDebit = $reportData['totalDebit'];
                $totalCredit = $reportData['totalCredit'];
                $netBalance = $reportData['netBalance'];
                $tafqeet = $reportData['tafqeet'];
                $finalStatus = $reportData['finalStatus'];
                $commonDebitParty = $reportData['commonDebitParty'];
                $commonCreditParty = $reportData['commonCreditParty'];
                $commonDebitAccount = $reportData['commonDebitAccount'];
                $commonCreditAccount = $reportData['commonCreditAccount'];
                $commonLedger = $reportData['commonLedger'];
            ?>
            <div class="flex flex-col justify-between" style="min-height: 100vh;">
                <div>
                    <!-- HEADER -->
                    <div class="border-b-2 border-indigo-900 pb-6 mb-6 flex justify-between items-start">
                        <div class="space-y-1">
                            <h1 class="text-xl font-black text-indigo-900 mb-2"><?php echo e($headerEntityName); ?></h1>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commonLedger): ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commonLedger->branch): ?> <div class="text-xs font-bold text-slate-700">الفرع: <?php echo e($commonLedger->branch->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commonLedger->center): ?> <div class="text-xs font-bold text-slate-700">المركز: <?php echo e($commonLedger->center->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commonLedger->project): ?> <div class="text-xs font-bold text-slate-700">المشروع: <?php echo e($commonLedger->project->name); ?></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </div>
                        
                        <div class="text-left space-y-1">
                            <h2 class="text-lg font-black text-slate-800 mb-2">كشف حساب مجمع (مدمج)</h2>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commonLedger): ?> <div class="text-xs font-bold text-slate-700"><?php echo e($commonLedger->name); ?> <span dir="ltr">(<?php echo e($commonLedger->code); ?>)</span></div> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            <div class="text-xs font-bold text-slate-700">عدد الصفحات المحددة: <?php echo e($pages->count()); ?></div>
                            <div class="text-xs font-bold text-slate-700">
                                الفترة: 
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($dateFrom || $dateTo): ?>
                                    من <span dir="ltr"><?php echo e($dateFrom ?? 'البداية'); ?></span> إلى <span dir="ltr"><?php echo e($dateTo ?? 'النهاية'); ?></span>
                                <?php else: ?>
                                    كافة العمليات
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </div>
                        </div>
                    </div>

                    <!-- PARTIES INFO -->
                    <div class="mb-4 text-xs font-bold border border-slate-300 bg-slate-50">
                        <div class="flex flex-col sm:flex-row sm:items-center px-3 py-1.5 <?php echo e(!$hideCreditParty ? 'border-b border-slate-200' : ''); ?>">
                            <div class="flex items-center ml-4 shrink-0 whitespace-nowrap">
                                <div class="w-2 h-2 ml-2 shrink-0" style="background-color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>"></div>
                                <span class="text-slate-600">الطرف المدين:</span>
                            </div>
                            <div class="flex flex-wrap items-center gap-x-4">
                                <div class="text-slate-900"><?php echo e($commonDebitParty ? $commonDebitParty->name : 'أطراف متعددة (مدمجة)'); ?> <span class="text-[11px] text-slate-500 ml-1" dir="ltr"><?php echo e($commonDebitParty ? '('.$commonDebitParty->code.')' : ''); ?></span></div>
                                <div class="text-slate-300 hidden sm:block">|</div>
                                <div class="text-slate-700">الحساب: <?php echo e($commonDebitAccount ? $commonDebitAccount->name : 'حسابات متعددة'); ?> <span class="text-indigo-700 ml-1" dir="ltr"><?php echo e($commonDebitAccount ? '['.$commonDebitAccount->account_number.']' : ''); ?></span></div>
                            </div>
                        </div>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideCreditParty): ?>
                        <div class="flex flex-col sm:flex-row sm:items-center px-3 py-1.5">
                            <div class="flex items-center ml-4 shrink-0 whitespace-nowrap">
                                <div class="w-2 h-2 ml-2 shrink-0" style="background-color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>"></div>
                                <span class="text-slate-600">الطرف الدائن:</span>
                            </div>
                            <div class="flex flex-wrap items-center gap-x-4">
                                <div class="text-slate-900"><?php echo e($commonCreditParty ? $commonCreditParty->name : 'أطراف متعددة (مدمجة)'); ?> <span class="text-[11px] text-slate-500 ml-1" dir="ltr"><?php echo e($commonCreditParty ? '('.$commonCreditParty->code.')' : ''); ?></span></div>
                                <div class="text-slate-300 hidden sm:block">|</div>
                                <div class="text-slate-700">الحساب: <?php echo e($commonCreditAccount ? $commonCreditAccount->name : 'حسابات متعددة'); ?> <span class="text-indigo-700 ml-1" dir="ltr"><?php echo e($commonCreditAccount ? '['.$commonCreditAccount->account_number.']' : ''); ?></span></div>
                            </div>
                        </div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>

                    <!-- TABLE -->
                    <table class="w-full text-right text-xs mb-8 border-collapse">
                        <thead class="bg-indigo-50 text-indigo-900" style="border-bottom: 2px solid #c7d2fe;">
                            <tr>
                                <th class="px-3 py-3 font-bold text-center w-12 border border-slate-200">#</th>
                                <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">التاريخ</th>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hidePageName): ?> <th class="px-3 py-3 font-bold border border-slate-200">الصفحة (الدفتر)</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> <th class="px-3 py-3 font-bold border border-slate-200">رقم الحركة</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <th class="px-3 py-3 font-bold border border-slate-200">البيان</th>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <th class="px-3 py-3 font-bold border border-slate-200">المرجع</th> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">مدين (+)</th>
                                <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">دائن (-)</th>
                                <th class="px-3 py-3 font-bold border border-slate-200 whitespace-nowrap w-[1%]">الرصيد</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-slate-200">
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($withOpeningBalance): ?>
                            <tr class="bg-slate-50 font-bold" style="background-color: #f8fafc;">
                                <td class="px-3 py-3 text-center border border-slate-200">-</td>
                                <td class="px-3 py-3 border border-slate-200 whitespace-nowrap"><?php echo e($dateFrom ?? '-'); ?></td>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hidePageName): ?> <td class="px-3 py-3 border border-slate-200">-</td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> <td class="px-3 py-3 border border-slate-200">-</td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <td class="px-3 py-3 border border-slate-200">رصيد افتتاحي مجمع (ما قبل الفترة)</td>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <td class="px-3 py-3 border border-slate-200">-</td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <td class="px-3 py-3 border border-slate-200 text-left whitespace-nowrap" dir="ltr"><?php echo e($openingDebit > 0 ? number_format($openingDebit, 2) : '-'); ?></td>
                                <td class="px-3 py-3 border border-slate-200 text-left whitespace-nowrap" dir="ltr"><?php echo e($openingCredit > 0 ? number_format($openingCredit, 2) : '-'); ?></td>
                                <td class="px-3 py-3 border border-slate-200 text-left font-black whitespace-nowrap" dir="ltr" style="color: <?php echo e($openingBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($openingBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>"><?php echo e($openingBalance > 0 ? '+' : ($openingBalance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($openingBalance), 2)); ?></td>
                            </tr>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                            <tr style="<?php echo e($trx->type === 'note' ? 'background-color: #fffbeb;' : ''); ?>" class="font-bold text-slate-900">
                                <td class="px-3 py-2 text-center border border-slate-200 text-[11px]"><?php echo e($index + 1); ?></td>
                                <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap" dir="ltr"><?php echo e($trx->transaction_date->format($settings['date_format'] ?? 'Y-m-d')); ?></td>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hidePageName): ?> 
                                    <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap text-slate-600">
                                        <?php echo e($trx->page->name ?: $trx->page->code); ?> 
                                        <div class="text-[10px] text-slate-400 mt-0.5"><?php echo e($trx->page->ledger->name ?? '-'); ?></div>
                                    </td> 
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideTransactionNumber): ?> 
                                    <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap" dir="ltr">
                                        <?php echo e($trx->transaction_number); ?>

                                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?> 📝 <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                    </td> 
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <td class="px-3 py-2 border border-slate-200"><?php echo e($trx->description); ?></td>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$hideReference): ?> <td class="px-3 py-2 border border-slate-200 text-[11px] whitespace-nowrap"><?php echo e($trx->reference_number ?? '-'); ?></td> <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($trx->type === 'note'): ?>
                                    <td class="px-3 py-2 border border-slate-200 text-center text-slate-400">-</td>
                                    <td class="px-3 py-2 border border-slate-200 text-center text-slate-400">-</td>
                                <?php else: ?>
                                    <td class="px-3 py-2 border border-slate-200 text-left font-bold whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->debit_amount > 0 ? ($settings['color_debit_text'] ?? '#166534') : 'inherit'); ?>">
                                        <?php echo e($trx->debit_amount > 0 ? number_format($trx->debit_amount, 2) : '-'); ?>

                                    </td>
                                    <td class="px-3 py-2 border border-slate-200 text-left font-bold whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->credit_amount > 0 ? ($settings['color_credit_text'] ?? '#991b1b') : 'inherit'); ?>">
                                        <?php echo e($trx->credit_amount > 0 ? number_format($trx->credit_amount, 2) : '-'); ?>

                                    </td>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                
                                <td class="px-3 py-2 border border-slate-200 text-left font-black whitespace-nowrap" dir="ltr" style="color: <?php echo e($trx->running_balance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($trx->running_balance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>">
                                    <?php echo e($trx->running_balance > 0 ? '+' : ($trx->running_balance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($trx->running_balance), 2)); ?>

                                </td>
                            </tr>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                        </tbody>
                        
                        <!-- TOTALS -->
                        <tfoot class="bg-indigo-50 font-black" style="background-color: #eef2ff; border-top: 2px solid #c7d2fe;">
                            <tr>
                                <td colspan="<?php echo e(3 + ($hidePageName ? 0 : 1) + ($hideTransactionNumber ? 0 : 1) + ($hideReference ? 0 : 1)); ?>" class="px-3 py-4 text-left border border-slate-200">الإجماليات الكلية:</td>
                                <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($settings['color_debit_text'] ?? '#166534'); ?>">
                                    <?php echo e(number_format($totalDebit, 2)); ?>

                                </td>
                                <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($settings['color_credit_text'] ?? '#991b1b'); ?>">
                                    <?php echo e(number_format($totalCredit, 2)); ?>

                                </td>
                                <td class="px-3 py-4 text-left border border-slate-200 whitespace-nowrap" dir="ltr" style="color: <?php echo e($netBalance > 0 ? ($settings['color_debit_text'] ?? '#166534') : ($netBalance < 0 ? ($settings['color_credit_text'] ?? '#991b1b') : '#1e293b')); ?>">
                                    <?php echo e($netBalance > 0 ? '+' : ($netBalance < 0 ? '-' : '')); ?><?php echo e(number_format(abs($netBalance), 2)); ?>

                                </td>
                            </tr>
                            <tr style="background-color: #f8fafc;">
                                <td colspan="<?php echo e(6 + ($hidePageName ? 0 : 1) + ($hideTransactionNumber ? 0 : 1) + ($hideReference ? 0 : 1)); ?>" class="px-2 py-1.5 border border-slate-200 text-right leading-snug">
                                    <div class="text-xs font-bold text-slate-600">الرصيد كتابة: <span class="text-indigo-700 font-black"><?php echo e($tafqeet ?: 'صفر'); ?></span></div>
                                    <div class="text-xs font-bold text-slate-600">الحالة النهائية: <span class="text-indigo-900 font-black"><?php echo e($finalStatus); ?></span></div>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>

                <div>
                    <!-- NOTES -->
                    <div class="mt-auto text-center text-xs font-bold text-slate-600 border-t border-slate-200 pt-6 mb-6">
                        <?php echo e($settings['footer_print_notes'] ?? ''); ?>

                    </div>

                    <!-- PRINT FOOTER (Right, Center, Left) -->
                    <div class="w-full flex justify-between items-center text-[11px] font-bold text-slate-500 border-t border-slate-200 pt-4 pb-2">
                        <div class="text-right"><?php echo $footerRight; ?></div>
                        <div class="text-center"><?php echo $footerCenter; ?></div>
                        <div class="text-left" dir="ltr"><?php echo $footerLeft; ?></div>
                    </div>
                </div>
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>

    <!-- Export Excel Script -->
    <script>
        function exportExcel() {
            var wb = XLSX.utils.book_new();
            
            // --- Styles ---
            var titleStyle = { font: { bold: true, sz: 16, color: { rgb: "FFFFFF" } }, fill: { fgColor: { rgb: "312e81" } }, alignment: { horizontal: "center", vertical: "center" } };
            var subHeaderStyle = { font: { bold: true, sz: 12 }, alignment: { horizontal: "center" } };
            var boldCenter = { font: { bold: true }, alignment: { horizontal: "center", vertical: "center" } };
            var boldRight = { font: { bold: true }, alignment: { horizontal: "right", vertical: "center" } };
            var amountStyle = { numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" } };
            var boldAmountStyle = { font: { bold: true }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "f8fafc" } } };
            var partiesHeaderStyle = { font: { bold: true }, fill: { fgColor: { rgb: "e2e8f0" } }, alignment: { horizontal: "center", vertical: "center" } };
            var tableHeaderStyle = { font: { bold: true, color: { rgb: "FFFFFF" } }, fill: { fgColor: { rgb: "4f46e5" } }, alignment: { horizontal: "center", vertical: "center" } };
            var finalStatusStyle = { font: { bold: true, sz: 12, color: { rgb: "1e3a8a" } }, alignment: { horizontal: "right", vertical: "center" } };

            <?php if($displayMode === 'separated'): ?>
                <?php $__currentLoopData = $reportData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $page = $data['page'];
                        $transactions = $data['transactions'];
                        $openingBalance = $data['openingBalance'];
                        $totalDebit = $data['totalDebit'];
                        $totalCredit = $data['totalCredit'];
                        $netBalance = $data['netBalance'];
                        $tafqeet = $data['tafqeet'];
                        $finalStatus = $data['finalStatus'];
                    ?>
                    var data_<?php echo e($index); ?> = [];
                    var mergeCells_<?php echo e($index); ?> = [];
                    var r_<?php echo e($index); ?> = 0;
                    
                    data_<?php echo e($index); ?>.push([{ v: "<?php echo e($page->ledger->entity->name ?? $settings['site_name'] ?? 'اسم الشركة'); ?>", s: titleStyle }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;

                    data_<?php echo e($index); ?>.push([{ v: "كشف حساب: <?php echo e($page->name); ?> (<?php echo e($page->page_number); ?>)", s: subHeaderStyle }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                    
                    data_<?php echo e($index); ?>.push([{ v: "الدفتر: <?php echo e($page->ledger->name); ?> (<?php echo e($page->ledger->code); ?>)", s: subHeaderStyle }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;

                    data_<?php echo e($index); ?>.push([{ v: "الفترة: <?php if($dateFrom || $dateTo): ?> من <?php echo e($dateFrom ?? 'البداية'); ?> إلى <?php echo e($dateTo ?? 'النهاية'); ?> <?php else: ?> كافة العمليات <?php endif; ?>", s: boldCenter }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                    data_<?php echo e($index); ?>.push([]); r_<?php echo e($index); ?>++; // Empty row

                    <?php if(!$hideCreditParty): ?>
                        data_<?php echo e($index); ?>.push([{ v: "الطرف المدين", s: partiesHeaderStyle }, "", "", "", { v: "الطرف الدائن", s: partiesHeaderStyle }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 3 } });
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 4 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;

                        data_<?php echo e($index); ?>.push([{ v: "الاسم: <?php echo e($page->debitAccount->party->name ?? '-'); ?> (<?php echo e($page->debitAccount->party->code ?? '-'); ?>)", s: boldRight }, "", "", "", { v: "الاسم: <?php echo e($page->creditAccount->party->name ?? '-'); ?> (<?php echo e($page->creditAccount->party->code ?? '-'); ?>)", s: boldRight }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 3 } });
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 4 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                        
                        data_<?php echo e($index); ?>.push([{ v: "الحساب: <?php echo e($page->debitAccount->name ?? '-'); ?> [<?php echo e($page->debitAccount->account_number ?? '-'); ?>]", s: boldRight }, "", "", "", { v: "الحساب: <?php echo e($page->creditAccount->name ?? '-'); ?> [<?php echo e($page->creditAccount->account_number ?? '-'); ?>]", s: boldRight }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 3 } });
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 4 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                    <?php else: ?>
                        data_<?php echo e($index); ?>.push([{ v: "الطرف المدين", s: partiesHeaderStyle }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                        data_<?php echo e($index); ?>.push([{ v: "الاسم: <?php echo e($page->debitAccount->party->name ?? '-'); ?> (<?php echo e($page->debitAccount->party->code ?? '-'); ?>)", s: boldRight }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                        data_<?php echo e($index); ?>.push([{ v: "الحساب: <?php echo e($page->debitAccount->name ?? '-'); ?> [<?php echo e($page->debitAccount->account_number ?? '-'); ?>]", s: boldRight }]);
                        mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: 7 } }); r_<?php echo e($index); ?>++;
                    <?php endif; ?>
                    data_<?php echo e($index); ?>.push([]); r_<?php echo e($index); ?>++;

                    var colHeaders_<?php echo e($index); ?> = [{ v: "#", s: tableHeaderStyle }, { v: "التاريخ", s: tableHeaderStyle }];
                    <?php if(!$hideTransactionNumber): ?> colHeaders_<?php echo e($index); ?>.push({ v: "رقم الحركة", s: tableHeaderStyle }); <?php endif; ?>
                    <?php if(!$hideReference): ?> colHeaders_<?php echo e($index); ?>.push({ v: "المرجع", s: tableHeaderStyle }); <?php endif; ?>
                    colHeaders_<?php echo e($index); ?>.push( { v: "البيان", s: tableHeaderStyle }, { v: "مدين (+)", s: tableHeaderStyle }, { v: "دائن (-)", s: tableHeaderStyle }, { v: "الرصيد", s: tableHeaderStyle } );
                    data_<?php echo e($index); ?>.push(colHeaders_<?php echo e($index); ?>); r_<?php echo e($index); ?>++;

                    <?php if($withOpeningBalance): ?>
                        var openingRow_<?php echo e($index); ?> = [{ v: "-", s: boldCenter }, { v: "-", s: boldCenter }];
                        <?php if(!$hideTransactionNumber): ?> openingRow_<?php echo e($index); ?>.push({ v: "-", s: boldCenter }); <?php endif; ?>
                        <?php if(!$hideReference): ?> openingRow_<?php echo e($index); ?>.push({ v: "-", s: boldCenter }); <?php endif; ?>
                        openingRow_<?php echo e($index); ?>.push(
                            { v: "الرصيد الافتتاحي", s: { font: { bold: true }, alignment: { horizontal: "right", vertical: "center" }, fill: { fgColor: { rgb: "f8fafc" } } } },
                            { v: <?php echo e($openingBalance > 0 ? $openingBalance : 0); ?>, s: boldAmountStyle },
                            { v: <?php echo e($openingBalance < 0 ? abs($openingBalance) : 0); ?>, s: boldAmountStyle },
                            { v: <?php echo e($openingBalance); ?>, s: boldAmountStyle }
                        );
                        data_<?php echo e($index); ?>.push(openingRow_<?php echo e($index); ?>); r_<?php echo e($index); ?>++;
                    <?php endif; ?>

                    <?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tIndex => $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        var trxRow_<?php echo e($index); ?>_<?php echo e($tIndex); ?> = [{ v: <?php echo e($tIndex + 1); ?>, s: boldCenter }, { v: "<?php echo e($trx->transaction_date->format($settings['date_format'] ?? 'Y-m-d')); ?>", s: boldCenter }];
                        <?php if(!$hideTransactionNumber): ?> trxRow_<?php echo e($index); ?>_<?php echo e($tIndex); ?>.push({ v: "<?php echo e($trx->transaction_number); ?>", s: boldCenter }); <?php endif; ?>
                        <?php if(!$hideReference): ?> trxRow_<?php echo e($index); ?>_<?php echo e($tIndex); ?>.push({ v: "<?php echo e($trx->reference_number ?? '-'); ?>", s: boldCenter }); <?php endif; ?>
                        trxRow_<?php echo e($index); ?>_<?php echo e($tIndex); ?>.push(
                            { v: "<?php echo addslashes(str_replace(["\r", "\n"], ' ', $trx->description)); ?>", s: { font: { bold: true }, alignment: { horizontal: "right", vertical: "center" } } },
                            { v: <?php echo e($trx->debit_amount); ?>, s: amountStyle },
                            { v: <?php echo e($trx->credit_amount); ?>, s: amountStyle },
                            { v: <?php echo e($trx->running_balance); ?>, s: boldAmountStyle }
                        );
                        data_<?php echo e($index); ?>.push(trxRow_<?php echo e($index); ?>_<?php echo e($tIndex); ?>); r_<?php echo e($index); ?>++;
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    var totalRow_<?php echo e($index); ?> = [{ v: "", s: boldCenter }, { v: "", s: boldCenter }];
                    <?php if(!$hideTransactionNumber): ?> totalRow_<?php echo e($index); ?>.push({ v: "", s: boldCenter }); <?php endif; ?>
                    <?php if(!$hideReference): ?> totalRow_<?php echo e($index); ?>.push({ v: "", s: boldCenter }); <?php endif; ?>
                    totalRow_<?php echo e($index); ?>.push(
                        { v: "الإجمالي", s: { font: { bold: true, sz: 12 }, alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                        { v: <?php echo e($totalDebit); ?>, s: { font: { bold: true }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                        { v: <?php echo e($totalCredit); ?>, s: { font: { bold: true }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                        { v: <?php echo e($netBalance); ?>, s: { font: { bold: true, color: { rgb: "FFFFFF" } }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "4338ca" } } } }
                    );
                    data_<?php echo e($index); ?>.push(totalRow_<?php echo e($index); ?>); r_<?php echo e($index); ?>++;
                    data_<?php echo e($index); ?>.push([]); r_<?php echo e($index); ?>++;

                    var finalColsCount = 3;
                    <?php if(!$hideTransactionNumber): ?> finalColsCount++; <?php endif; ?>
                    <?php if(!$hideReference): ?> finalColsCount++; <?php endif; ?>
                    
                    data_<?php echo e($index); ?>.push([{ v: "الرصيد كتابة: <?php echo e($tafqeet ?: 'صفر'); ?>", s: finalStatusStyle }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: finalColsCount + 3 } }); r_<?php echo e($index); ?>++;
                    
                    data_<?php echo e($index); ?>.push([{ v: "الحالة النهائية: <?php echo e($finalStatus); ?>", s: finalStatusStyle }]);
                    mergeCells_<?php echo e($index); ?>.push({ s: { r: r_<?php echo e($index); ?>, c: 0 }, e: { r: r_<?php echo e($index); ?>, c: finalColsCount + 3 } }); r_<?php echo e($index); ?>++;

                    var ws_<?php echo e($index); ?> = XLSX.utils.aoa_to_sheet(data_<?php echo e($index); ?>);
                    ws_<?php echo e($index); ?>['!dir'] = 'rtl';
                    ws_<?php echo e($index); ?>['!merges'] = mergeCells_<?php echo e($index); ?>;
                    var cols_<?php echo e($index); ?> = [{ wpx: 40 }, { wpx: 90 }];
                    <?php if(!$hideTransactionNumber): ?> cols_<?php echo e($index); ?>.push({ wpx: 90 }); <?php endif; ?>
                    <?php if(!$hideReference): ?> cols_<?php echo e($index); ?>.push({ wpx: 90 }); <?php endif; ?>
                    cols_<?php echo e($index); ?>.push({ wpx: 350 }, { wpx: 110 }, { wpx: 110 }, { wpx: 120 });
                    ws_<?php echo e($index); ?>['!cols'] = cols_<?php echo e($index); ?>;

                    XLSX.utils.book_append_sheet(wb, ws_<?php echo e($index); ?>, ("P<?php echo e($page->page_number); ?> - <?php echo e($page->name); ?>").substring(0, 31));
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                XLSX.writeFile(wb, "كشف_مجمع_منفصل_<?php echo e(date('Ymd')); ?>.xlsx");
            <?php else: ?>
                <?php
                    $transactions = $reportData['transactions'];
                    $openingBalance = $reportData['openingBalance'];
                    $totalDebit = $reportData['totalDebit'];
                    $totalCredit = $reportData['totalCredit'];
                    $netBalance = $reportData['netBalance'];
                    $tafqeet = $reportData['tafqeet'];
                    $finalStatus = $reportData['finalStatus'];
                    $commonDebitParty = $reportData['commonDebitParty'];
                    $commonCreditParty = $reportData['commonCreditParty'];
                    $commonDebitAccount = $reportData['commonDebitAccount'];
                    $commonCreditAccount = $reportData['commonCreditAccount'];
                    $commonLedger = $reportData['commonLedger'];
                ?>
                var data = [];
                var mergeCells = [];
                var r = 0;
                
                data.push([{ v: "<?php echo e($headerEntityName); ?>", s: titleStyle }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;

                data.push([{ v: "كشف حساب مجمع (مدمج)", s: subHeaderStyle }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                
                <?php if($commonLedger): ?>
                data.push([{ v: "الدفتر: <?php echo e($commonLedger->name); ?> (<?php echo e($commonLedger->code); ?>)", s: subHeaderStyle }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                <?php endif; ?>

                data.push([{ v: "الفترة: <?php if($dateFrom || $dateTo): ?> من <?php echo e($dateFrom ?? 'البداية'); ?> إلى <?php echo e($dateTo ?? 'النهاية'); ?> <?php else: ?> كافة العمليات <?php endif; ?>", s: boldCenter }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                data.push([]); r++; 

                <?php if(!$hideCreditParty): ?>
                    data.push([{ v: "الطرف المدين", s: partiesHeaderStyle }, "", "", "", { v: "الطرف الدائن", s: partiesHeaderStyle }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 3 } });
                    mergeCells.push({ s: { r: r, c: 4 }, e: { r: r, c: 8 } }); r++;

                    data.push([{ v: "الاسم: <?php echo e($commonDebitParty ? $commonDebitParty->name : 'أطراف متعددة'); ?> <?php echo e($commonDebitParty ? '('.$commonDebitParty->code.')' : ''); ?>", s: boldRight }, "", "", "", { v: "الاسم: <?php echo e($commonCreditParty ? $commonCreditParty->name : 'أطراف متعددة'); ?> <?php echo e($commonCreditParty ? '('.$commonCreditParty->code.')' : ''); ?>", s: boldRight }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 3 } });
                    mergeCells.push({ s: { r: r, c: 4 }, e: { r: r, c: 8 } }); r++;
                    
                    data.push([{ v: "الحساب: <?php echo e($commonDebitAccount ? $commonDebitAccount->name : 'حسابات متعددة'); ?> <?php echo e($commonDebitAccount ? '['.$commonDebitAccount->account_number.']' : ''); ?>", s: boldRight }, "", "", "", { v: "الحساب: <?php echo e($commonCreditAccount ? $commonCreditAccount->name : 'حسابات متعددة'); ?> <?php echo e($commonCreditAccount ? '['.$commonCreditAccount->account_number.']' : ''); ?>", s: boldRight }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 3 } });
                    mergeCells.push({ s: { r: r, c: 4 }, e: { r: r, c: 8 } }); r++;
                <?php else: ?>
                    data.push([{ v: "الطرف المدين", s: partiesHeaderStyle }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                    data.push([{ v: "الاسم: <?php echo e($commonDebitParty ? $commonDebitParty->name : 'أطراف متعددة'); ?> <?php echo e($commonDebitParty ? '('.$commonDebitParty->code.')' : ''); ?>", s: boldRight }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                    data.push([{ v: "الحساب: <?php echo e($commonDebitAccount ? $commonDebitAccount->name : 'حسابات متعددة'); ?> <?php echo e($commonDebitAccount ? '['.$commonDebitAccount->account_number.']' : ''); ?>", s: boldRight }]);
                    mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: 8 } }); r++;
                <?php endif; ?>
                data.push([]); r++;

                var colHeaders = [{ v: "#", s: tableHeaderStyle }, { v: "التاريخ", s: tableHeaderStyle }];
                <?php if(!$hidePageName): ?> colHeaders.push({ v: "الصفحة", s: tableHeaderStyle }); <?php endif; ?>
                <?php if(!$hideTransactionNumber): ?> colHeaders.push({ v: "رقم الحركة", s: tableHeaderStyle }); <?php endif; ?>
                <?php if(!$hideReference): ?> colHeaders.push({ v: "المرجع", s: tableHeaderStyle }); <?php endif; ?>
                colHeaders.push( { v: "البيان", s: tableHeaderStyle }, { v: "مدين (+)", s: tableHeaderStyle }, { v: "دائن (-)", s: tableHeaderStyle }, { v: "الرصيد", s: tableHeaderStyle } );
                data.push(colHeaders); r++;

                <?php if($withOpeningBalance): ?>
                    var openingRow = [{ v: "-", s: boldCenter }, { v: "-", s: boldCenter }];
                    <?php if(!$hidePageName): ?> openingRow.push({ v: "-", s: boldCenter }); <?php endif; ?>
                    <?php if(!$hideTransactionNumber): ?> openingRow.push({ v: "-", s: boldCenter }); <?php endif; ?>
                    <?php if(!$hideReference): ?> openingRow.push({ v: "-", s: boldCenter }); <?php endif; ?>
                    openingRow.push(
                        { v: "رصيد افتتاحي مجمع", s: { font: { bold: true }, alignment: { horizontal: "right", vertical: "center" }, fill: { fgColor: { rgb: "f8fafc" } } } },
                        { v: <?php echo e($openingBalance > 0 ? $openingBalance : 0); ?>, s: boldAmountStyle },
                        { v: <?php echo e($openingBalance < 0 ? abs($openingBalance) : 0); ?>, s: boldAmountStyle },
                        { v: <?php echo e($openingBalance); ?>, s: boldAmountStyle }
                    );
                    data.push(openingRow); r++;
                <?php endif; ?>

                <?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tIndex => $trx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    var trxRow = [{ v: <?php echo e($tIndex + 1); ?>, s: boldCenter }, { v: "<?php echo e($trx->transaction_date->format($settings['date_format'] ?? 'Y-m-d')); ?>", s: boldCenter }];
                    <?php if(!$hidePageName): ?> trxRow.push({ v: "<?php echo e($trx->page->name ?: $trx->page->code); ?>", s: boldCenter }); <?php endif; ?>
                    <?php if(!$hideTransactionNumber): ?> trxRow.push({ v: "<?php echo e($trx->transaction_number); ?>", s: boldCenter }); <?php endif; ?>
                    <?php if(!$hideReference): ?> trxRow.push({ v: "<?php echo e($trx->reference_number ?? '-'); ?>", s: boldCenter }); <?php endif; ?>
                    trxRow.push(
                        { v: "<?php echo addslashes(str_replace(["\r", "\n"], ' ', $trx->description)); ?>", s: { font: { bold: true }, alignment: { horizontal: "right", vertical: "center" } } },
                        { v: <?php echo e($trx->debit_amount); ?>, s: amountStyle },
                        { v: <?php echo e($trx->credit_amount); ?>, s: amountStyle },
                        { v: <?php echo e($trx->running_balance); ?>, s: boldAmountStyle }
                    );
                    data.push(trxRow); r++;
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                var totalRow = [{ v: "", s: boldCenter }, { v: "", s: boldCenter }];
                <?php if(!$hidePageName): ?> totalRow.push({ v: "", s: boldCenter }); <?php endif; ?>
                <?php if(!$hideTransactionNumber): ?> totalRow.push({ v: "", s: boldCenter }); <?php endif; ?>
                <?php if(!$hideReference): ?> totalRow.push({ v: "", s: boldCenter }); <?php endif; ?>
                totalRow.push(
                    { v: "الإجمالي", s: { font: { bold: true, sz: 12 }, alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                    { v: <?php echo e($totalDebit); ?>, s: { font: { bold: true }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                    { v: <?php echo e($totalCredit); ?>, s: { font: { bold: true }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "e2e8f0" } } } },
                    { v: <?php echo e($netBalance); ?>, s: { font: { bold: true, color: { rgb: "FFFFFF" } }, numFmt: "#,##0.00", alignment: { horizontal: "center", vertical: "center" }, fill: { fgColor: { rgb: "4338ca" } } } }
                );
                data.push(totalRow); r++;
                data.push([]); r++;

                var finalColsCount = 3;
                <?php if(!$hidePageName): ?> finalColsCount++; <?php endif; ?>
                <?php if(!$hideTransactionNumber): ?> finalColsCount++; <?php endif; ?>
                <?php if(!$hideReference): ?> finalColsCount++; <?php endif; ?>
                
                data.push([{ v: "الرصيد كتابة: <?php echo e($tafqeet ?: 'صفر'); ?>", s: finalStatusStyle }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: finalColsCount + 3 } }); r++;
                
                data.push([{ v: "الحالة النهائية: <?php echo e($finalStatus); ?>", s: finalStatusStyle }]);
                mergeCells.push({ s: { r: r, c: 0 }, e: { r: r, c: finalColsCount + 3 } }); r++;

                var ws = XLSX.utils.aoa_to_sheet(data);
                ws['!dir'] = 'rtl';
                ws['!merges'] = mergeCells;
                var cols = [{ wpx: 40 }, { wpx: 90 }];
                <?php if(!$hidePageName): ?> cols.push({ wpx: 100 }); <?php endif; ?>
                <?php if(!$hideTransactionNumber): ?> cols.push({ wpx: 90 }); <?php endif; ?>
                <?php if(!$hideReference): ?> cols.push({ wpx: 90 }); <?php endif; ?>
                cols.push({ wpx: 350 }, { wpx: 110 }, { wpx: 110 }, { wpx: 120 });
                ws['!cols'] = cols;

                XLSX.utils.book_append_sheet(wb, ws, "كشف مجمع مدمج");
                XLSX.writeFile(wb, "كشف_مجمع_مدمج_<?php echo e(date('Ymd')); ?>.xlsx");
            <?php endif; ?>
        }
    </script>
</body>
</html>
<?php /**PATH D:\laragon\www\Ledger\resources\views/reports/print/aggregated-statement.blade.php ENDPATH**/ ?>