<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body{font-family:DejaVu Sans,sans-serif;font-size:11px;color:#111827}
        h1{font-size:22px;margin:0 0 4px}
        h2{font-size:15px;margin:18px 0 6px}
        .muted{color:#6b7280}
        .grid{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:14px 0}
        .box{border:1px solid #d1d5db;padding:9px}
        .box span{display:block;color:#6b7280;font-size:10px}
        .box strong{font-size:15px}
        table{width:100%;border-collapse:collapse;margin-top:8px}
        th,td{border:1px solid #d1d5db;padding:5px;text-align:left}
        th{background:#f3f4f6}
    </style>
</head>
<body>
<?php
    $money = fn ($amount) => number_format((float) $amount, 2);
    $approvalName = fn ($record) => $record->approver?->name ?? (($record->status ?? 'posted') === 'pending' ? 'Not approved yet' : 'Auto-posted');
    $investmentApprovalName = fn ($record) => $record->approved_by_name ?? (($record->status ?? 'posted') === 'pending' ? 'Not approved yet' : 'Auto-posted');
?>

<h1><?php echo e(auth()->user()->tenant?->name); ?> <?php echo e($reportTitle); ?> Report</h1>
<div class="muted"><?php echo e(app_date($from)); ?> to <?php echo e(app_date($to)); ?> · Generated <?php echo e(app_datetime(now())); ?></div>

<?php if($report === 'overview'): ?>
<div class="grid">
    <div class="box"><span>Members</span><strong><?php echo e(number_format($summary['customers'])); ?></strong></div>
    <div class="box"><span>Savings balance</span><strong><?php echo e($money($summary['savingsBalance'])); ?></strong></div>
    <div class="box"><span>Loan portfolio</span><strong><?php echo e($money($summary['loanPortfolio'])); ?></strong></div>
    <div class="box"><span>Collections</span><strong><?php echo e($money($summary['periodCollections'])); ?></strong></div>
    <div class="box"><span>Repayment rate</span><strong><?php echo e(number_format($summary['repaymentPerformance'], 2)); ?>%</strong></div>
    <div class="box"><span>Overdue</span><strong><?php echo e($money($summary['overdueAmount'])); ?></strong></div>
</div>
<?php endif; ?>

<?php switch($report):
    case ('savings'): ?>
        <h2>Savings Transactions</h2>
        <table>
            <thead><tr><th>Date</th><th>Member</th><th>Account</th><th>Type</th><th>Initiated By</th><th>Approved By</th><th>Amount</th><th>Balance After</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $savingsTransactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_datetime($transaction->transacted_at)); ?></td><td><?php echo e($transaction->customer?->fullName()); ?></td><td><?php echo e($transaction->account?->account_number); ?></td><td><?php echo e(ucfirst($transaction->type)); ?></td><td><?php echo e($transaction->creator?->name ?? 'System / member'); ?></td><td><?php echo e($approvalName($transaction)); ?></td><td><?php echo e($money($transaction->amount)); ?></td><td><?php echo e($money($transaction->balance_after)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="8">No savings transactions in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('withdrawals'): ?>
        <h2>Withdrawal Register</h2>
        <table>
            <thead><tr><th>Date</th><th>Member</th><th>Account</th><th>Status</th><th>Method</th><th>Initiated By</th><th>Approved By</th><th>Amount</th><th>Balance After</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $withdrawals; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_datetime($transaction->transacted_at)); ?></td><td><?php echo e($transaction->customer?->fullName()); ?></td><td><?php echo e($transaction->account?->account_number); ?></td><td><?php echo e(ucfirst($transaction->status ?? 'posted')); ?></td><td><?php echo e(ucfirst($transaction->method)); ?></td><td><?php echo e($transaction->creator?->name ?? 'System / member'); ?></td><td><?php echo e($approvalName($transaction)); ?></td><td><?php echo e($money($transaction->amount)); ?></td><td><?php echo e($money($transaction->balance_after)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9">No withdrawals in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('loans'): ?>
        <h2>Loan Register</h2>
        <table>
            <thead><tr><th>Loan</th><th>Member</th><th>Product</th><th>Status</th><th>Initiated By</th><th>Approved By</th><th>Principal</th><th>Balance</th><th>Due</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $loans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $loan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($loan->loan_number); ?></td><td><?php echo e($loan->customer?->fullName()); ?></td><td><?php echo e($loan->product?->name ?? 'No product'); ?></td><td><?php echo e(ucfirst($loan->status)); ?></td><td><?php echo e($loan->creator?->name ?? 'System / member'); ?></td><td><?php echo e($loan->approver?->name ?? 'Not approved yet'); ?></td><td><?php echo e($money($loan->principal)); ?></td><td><?php echo e($money($loan->balance)); ?></td><td><?php echo e(app_date($loan->due_date) ?? '-'); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9">No loans match this report.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('repayments'): ?>
        <h2>Repayment History</h2>
        <table>
            <thead><tr><th>Date</th><th>Reference</th><th>Member</th><th>Loan</th><th>Method</th><th>Recorded By</th><th>Approved By</th><th>Amount</th><th>Balance After</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_datetime($payment->paid_at)); ?></td><td><?php echo e($payment->reference); ?></td><td><?php echo e($payment->customer?->fullName() ?? $payment->loan?->customer?->fullName()); ?></td><td><?php echo e($payment->loan?->loan_number); ?></td><td><?php echo e(ucfirst($payment->method)); ?></td><td><?php echo e($payment->receiver?->name ?? 'System / member'); ?></td><td>Auto-posted</td><td><?php echo e($money($payment->amount)); ?></td><td><?php echo e($money($payment->balance_after)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9">No repayments in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('risk'): ?>
        <h2>Overdue Schedules</h2>
        <table>
            <thead><tr><th>Due Date</th><th>Member</th><th>Loan</th><th>Status</th><th>Outstanding</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $overdueSchedules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $schedule): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_date($schedule->due_date)); ?></td><td><?php echo e($schedule->loan?->customer?->fullName()); ?></td><td><?php echo e($schedule->loan?->loan_number); ?></td><td><?php echo e(ucfirst($schedule->status)); ?></td><td><?php echo e($money($schedule->total_due - $schedule->paid_amount)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="5">No overdue repayments.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Non-Performing Loans Over <?php echo e($nplDays); ?> Days</h2>
        <table>
            <thead><tr><th>Loan</th><th>Member</th><th>Days Overdue</th><th>Overdue Amount</th><th>Balance</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $nplLoans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($row['loan']?->loan_number); ?></td><td><?php echo e($row['loan']?->customer?->fullName()); ?></td><td><?php echo e(number_format($row['days_overdue'])); ?></td><td><?php echo e($money($row['overdue_amount'])); ?></td><td><?php echo e($money($row['balance'])); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="5">No non-performing loans at this threshold.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('investments'): ?>
        <h2>Investment Accounts</h2>
        <table>
            <thead><tr><th>Member</th><th>Account</th><th>Status</th><th>Amount</th><th>Balance</th><th>Matures</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $investmentAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(trim(($account->first_name ?? '').' '.($account->last_name ?? '')) ?: '-'); ?></td><td><?php echo e($account->account_number ?? '-'); ?></td><td><?php echo e(ucfirst($account->status ?? '-')); ?></td><td><?php echo e($money($account->amount ?? 0)); ?></td><td><?php echo e($money($account->balance ?? 0)); ?></td><td><?php echo e($account->matures_at ?? '-'); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6">No investment accounts yet.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Investment Transactions</h2>
        <table>
            <thead><tr><th>Date</th><th>Type</th><th>Reference</th><th>Initiated By</th><th>Approved By</th><th>Amount</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $investmentTransactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($transaction->transacted_at ?? '-'); ?></td><td><?php echo e(ucfirst($transaction->type ?? '-')); ?></td><td><?php echo e($transaction->reference ?? '-'); ?></td><td><?php echo e($transaction->initiated_by_name ?? 'System / member'); ?></td><td><?php echo e($investmentApprovalName($transaction)); ?></td><td><?php echo e($money($transaction->amount ?? 0)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6">No investment transactions in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('customers'): ?>
        <h2>Member Portfolio</h2>
        <table>
            <thead><tr><th>Member</th><th>Account</th><th>Phone</th><th>Status</th><th>KYC</th><th>Savings</th><th>Loan Balance</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($customer->fullName()); ?></td><td><?php echo e($customer->account_number); ?></td><td><?php echo e($customer->phone); ?></td><td><?php echo e(ucfirst($customer->status)); ?></td><td><?php echo e(ucfirst($customer->kyc_status)); ?></td><td><?php echo e($money($customer->savings_balance)); ?></td><td><?php echo e($money($customer->loan_balance)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="7">No members yet.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('expenses'): ?>
        <h2>Expense Register</h2>
        <table>
            <thead><tr><th>Date</th><th>Category</th><th>Payee</th><th>Branch</th><th>Status</th><th>Recorded By</th><th>Approved By</th><th>Method</th><th>Amount</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $expense): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_date($expense->spent_at)); ?></td><td><?php echo e($expense->categoryModel?->name ?? $expense->category); ?></td><td><?php echo e($expense->payee ?? '-'); ?></td><td><?php echo e($expense->branch?->name ?? 'Head Office'); ?></td><td><?php echo e(ucfirst($expense->status)); ?></td><td><?php echo e($expense->recordedBy?->name ?? 'System'); ?></td><td><?php echo e($expense->approvedBy?->name ?? ($expense->status === 'pending' ? 'Not approved yet' : '-')); ?></td><td><?php echo e(ucfirst($expense->method)); ?></td><td><?php echo e($money($expense->amount)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9">No expenses in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Expense By Category</h2>
        <table>
            <thead><tr><th>Category</th><th>Entries</th><th>Total</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $expenseByCategory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($row->category); ?></td><td><?php echo e(number_format($row->entries_count)); ?></td><td><?php echo e($money($row->total_amount)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="3">No approved expenses by category.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('bill_payments'): ?>
        <h2>Bill Payment Register</h2>
        <table>
            <thead><tr><th>Date</th><th>Reference</th><th>Member</th><th>Service</th><th>Provider</th><th>Status</th><th>Recorded By</th><th>Total</th><th>VTU Earnings</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $billPayments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(app_datetime($payment->created_at)); ?></td><td><?php echo e($payment->reference); ?></td><td><?php echo e($payment->customer?->fullName() ?? $payment->customer_name ?? '-'); ?></td><td><?php echo e(ucfirst(str_replace('_', ' ', $payment->service_type))); ?></td><td><?php echo e(ucfirst($payment->provider)); ?></td><td><?php echo e(ucfirst($payment->status)); ?></td><td><?php echo e($payment->recordedBy?->name ?? 'System / member'); ?></td><td><?php echo e($money($payment->total_amount)); ?></td><td><?php echo e($money((float) $payment->fee + (float) $payment->commission)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="9">No bill payments in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Bill Payments By Service</h2>
        <table>
            <thead><tr><th>Service</th><th>Payments</th><th>Total</th><th>VTU Earnings</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $billPaymentsByService; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(ucfirst(str_replace('_', ' ', $row->service_type))); ?></td><td><?php echo e(number_format($row->payments_count)); ?></td><td><?php echo e($money($row->total_amount)); ?></td><td><?php echo e($money($row->earnings_total)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="4">No service activity yet.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php case ('financials'): ?>
        <h2>Income By Category</h2>
        <table>
            <thead><tr><th>Category</th><th>Entries</th><th>Total</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $incomeByCategory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($row->category); ?></td><td><?php echo e(number_format($row->entries_count)); ?></td><td><?php echo e($money($row->total_amount)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="3">No income in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Expense By Category</h2>
        <table>
            <thead><tr><th>Category</th><th>Entries</th><th>Total</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $expenseByCategory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($row->category); ?></td><td><?php echo e(number_format($row->entries_count)); ?></td><td><?php echo e($money($row->total_amount)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="3">No expenses in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <?php break; ?>

    <?php default: ?>
        <h2>Loan Status Summary</h2>
        <table>
            <thead><tr><th>Status</th><th>Loans</th><th>Principal</th><th>Balance</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $loanStatusBreakdown; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e(ucfirst($row->status)); ?></td><td><?php echo e(number_format($row->loans_count)); ?></td><td><?php echo e($money($row->principal_total)); ?></td><td><?php echo e($money($row->balance_total)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="4">No loan data yet.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
        <h2>Daily Savings Movement</h2>
        <table>
            <thead><tr><th>Date</th><th>Type</th><th>Total</th></tr></thead>
            <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $dailySavings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><?php echo e($row->day); ?></td><td><?php echo e(ucfirst($row->type)); ?></td><td><?php echo e($money($row->total)); ?></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="3">No savings activity in this period.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
<?php endswitch; ?>
</body>
</html>
<?php /**PATH C:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views\tenant\reports\pdf.blade.php ENDPATH**/ ?>