

<?php $__env->startSection('title', 'Deposits'); ?>
<?php $__env->startSection('page-title', 'Deposit Center'); ?>
<?php $__env->startSection('page-subtitle', 'Post, approve, review, and receipt member savings deposits'); ?>

<?php $__env->startSection('content'); ?>
<?php
    $canManageSavings = auth()->user()->hasPermission('savings.manage');
    $canApproveSavings = auth()->user()->hasPermission('savings.approve');
    $canUseDepositApproval = $canApproveSavings && $depositApprovalRequired;
    $currency = auth()->user()->tenant->settings['currency'] ?? 'NGN';
    $compactNumber = function ($amount) {
        $amount = (float) $amount;
        $absolute = abs($amount);
        $format = fn ($value, $suffix) => rtrim(rtrim(number_format($value, 1), '0'), '.').$suffix;

        if ($absolute >= 1000000000) {
            return $format($amount / 1000000000, 'b');
        }

        if ($absolute >= 1000000) {
            return $format($amount / 1000000, 'm');
        }

        if ($absolute >= 1000) {
            return $format($amount / 1000, 'k');
        }

        return number_format($amount, 2);
    };
    $money = fn ($amount) => $currency.' '.number_format((float) $amount, 2);
    $compactMoney = fn ($amount) => $currency.' '.$compactNumber($amount);
    $depositCards = [
        ['Deposited today', $compactMoney($depositStats['today_amount'] ?? 0), $compactNumber($depositStats['today_count'] ?? 0).' posted today', 'bi-arrow-down-circle', 'teal'],
        ['Pending approval', $compactMoney($depositStats['pending_amount'] ?? 0), $compactNumber($depositStats['pending_count'] ?? 0).' waiting', 'bi-hourglass-split', 'amber'],
        ['This month', $compactMoney($depositStats['month_amount'] ?? 0), $compactNumber($depositStats['month_count'] ?? 0).' posted', 'bi-calendar2-week', 'blue'],
        ['Active accounts', $compactNumber($depositStats['active_accounts'] ?? 0), 'Available for deposit', 'bi-wallet2', 'green'],
    ];
    $historyFiltersActive = filled($search) || filled($status) || filled($initiatedBy) || filled($approvedBy) || filled($from) || filled($to);
    $statusClass = fn (?string $value) => match ($value) {
        'posted' => 'success',
        'pending' => 'warning',
        'rejected' => 'danger',
        'canceled' => 'secondary',
        default => 'light',
    };
?>

<section class="finance-hero finance-hero-deposits mb-4">
    <div class="finance-hero-copy">
        <span>Transaction center</span>
        <h2>Record savings deposits from one dedicated workspace.</h2>
        <p>
            <?php if($depositApprovalRequired): ?>
                Select a member savings account, submit the deposit for approval, then track receipts, initiators, approvers, and posted balances without opening the Savings module.
            <?php else: ?>
                Select a member savings account, post the deposit directly, then track receipts, initiators, and posted balances without opening the Savings module.
            <?php endif; ?>
        </p>
    </div>
    <div class="finance-metric-grid">
        <?php $__currentLoopData = $depositCards; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $hint, $icon, $tone]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="finance-metric-card <?php echo e($tone); ?>">
                <i class="bi <?php echo e($icon); ?>"></i>
                <span><?php echo e($label); ?></span>
                <strong><?php echo e($value); ?></strong>
                <small><?php echo e($hint); ?></small>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
</section>

<div class="card border-0 shadow-sm finance-workspace">
    <div class="finance-tabbar">
        <ul class="nav nav-pills finance-tabs" role="tablist">
            <?php if($canManageSavings): ?>
                <li class="nav-item" role="presentation">
                    <button class="nav-link active" data-bs-toggle="tab" data-bs-target="#record-deposit" type="button">
                        <i class="bi bi-plus-circle me-1"></i> Record deposit
                    </button>
                </li>
            <?php endif; ?>
            <?php if($canUseDepositApproval): ?>
                <li class="nav-item" role="presentation">
                    <button class="<?php echo \Illuminate\Support\Arr::toCssClasses(['nav-link', 'active' => ! $canManageSavings]); ?>" data-bs-toggle="tab" data-bs-target="#pending-deposits" type="button">
                        <i class="bi bi-hourglass-split me-1"></i> Pending approval
                        <?php if(($depositStats['pending_count'] ?? 0) > 0): ?>
                            <span class="badge text-bg-warning ms-1"><?php echo e($compactNumber($depositStats['pending_count'])); ?></span>
                        <?php endif; ?>
                    </button>
                </li>
                <li class="nav-item" role="presentation">
                    <button class="nav-link" data-bs-toggle="tab" data-bs-target="#member-deposit-requests" type="button">
                        <i class="bi bi-person-check me-1"></i> Member request
                        <?php if(($depositStats['member_request_count'] ?? 0) > 0): ?>
                            <span class="badge text-bg-info ms-1"><?php echo e($compactNumber($depositStats['member_request_count'])); ?></span>
                        <?php endif; ?>
                    </button>
                </li>
            <?php endif; ?>
            <li class="nav-item" role="presentation">
                <button class="nav-link" data-bs-toggle="tab" data-bs-target="#deposit-accounts" type="button">
                    <i class="bi bi-wallet2 me-1"></i> Accounts
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="<?php echo \Illuminate\Support\Arr::toCssClasses(['nav-link', 'active' => ! $canManageSavings && ! $canUseDepositApproval]); ?>" data-bs-toggle="tab" data-bs-target="#deposit-history" type="button">
                    <i class="bi bi-clock-history me-1"></i> History
                </button>
            </li>
        </ul>
    </div>

    <div class="tab-content">
        <?php if($canManageSavings): ?>
            <div class="tab-pane fade show active" id="record-deposit">
                <div class="finance-pane-title">
                    <div>
                        <span>New deposit</span>
                        <h3><?php echo e($depositApprovalRequired ? 'Submit a deposit for approval' : 'Post a deposit directly'); ?></h3>
                        <p><?php echo e($depositApprovalRequired ? 'Deposits remain pending until an authorized user approves them. Balance updates and receipts happen after approval.' : 'Deposit approval is turned off, so balances and receipts update immediately after submission.'); ?></p>
                    </div>
                    <a href="<?php echo e(route('tenant.savings.index')); ?>" class="btn btn-outline-primary btn-sm">
                        <i class="bi bi-wallet2 me-1"></i> Savings accounts
                    </a>
                </div>
                <div class="p-3">
                    <?php if($depositAccounts->isNotEmpty()): ?>
                        <form method="POST" action="<?php echo e(route('tenant.deposits.store')); ?>" class="row g-3">
                            <?php echo csrf_field(); ?>
                            <div class="col-lg-6">
                                <label class="form-label">Savings account</label>
                                <select name="savings_account_id" class="form-select form-select-lg" required>
                                    <option value="">Select member account</option>
                                    <?php $__currentLoopData = $depositAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($account->id); ?>" <?php if(old('savings_account_id') == $account->id): echo 'selected'; endif; ?>>
                                            <?php echo e($account->account_number); ?> - <?php echo e($account->customer?->fullName()); ?> - <?php echo e($account->product_name); ?> - <?php echo e($money($account->balance)); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="form-text">Only active savings accounts are listed.</div>
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Amount</label>
                                <input name="amount" type="number" step="0.01" min="0.01" value="<?php echo e(old('amount')); ?>" class="form-control form-control-lg" required>
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Payment method</label>
                                <select name="method" class="form-select form-select-lg" required>
                                    <?php $__currentLoopData = ['cash' => 'Cash', 'bank_transfer' => 'Bank transfer', 'pos' => 'POS', 'virtual_account' => 'Virtual account', 'gateway' => 'Gateway', 'other' => 'Other']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($value); ?>" <?php if(old('method', 'cash') === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-12">
                                <label class="form-label">Narration</label>
                                <textarea name="description" class="form-control" rows="3" placeholder="Optional note, teller number, collector, or channel detail"><?php echo e(old('description')); ?></textarea>
                            </div>
                            <div class="col-12 d-flex justify-content-end">
                                <button class="btn btn-primary btn-lg">
                                    <i class="bi bi-send-check me-1"></i> <?php echo e($depositApprovalRequired ? 'Submit deposit' : 'Post deposit'); ?>

                                </button>
                            </div>
                        </form>
                    <?php else: ?>
                        <div class="pending-empty-state">
                            <i class="bi bi-wallet2"></i>
                            <strong>No active savings account found</strong>
                            <span>Create or activate a savings account before recording deposits.</span>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endif; ?>

        <?php if($canUseDepositApproval): ?>
            <div class="<?php echo \Illuminate\Support\Arr::toCssClasses(['tab-pane fade', 'show active' => ! $canManageSavings]); ?>" id="pending-deposits">
                <div class="finance-pane-title">
                    <div>
                        <span>Approval queue</span>
                        <h3>Pending deposit approvals</h3>
                        <p>Review deposits before they update member balances. The person who initiated each transaction is shown clearly.</p>
                    </div>
                    <strong class="text-warning"><?php echo e($compactMoney($depositStats['pending_amount'] ?? 0)); ?></strong>
                </div>
                <?php if($pendingDeposits->isNotEmpty()): ?>
                    <div class="table-responsive">
                        <table class="table align-middle mb-0">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Member</th>
                                    <th>Account</th>
                                    <th>Amount</th>
                                    <th>Initiated by</th>
                                    <th class="text-end">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $pendingDeposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e(app_datetime($transaction->transacted_at)); ?></td>
                                        <td>
                                            <div class="fw-semibold"><?php echo e($transaction->customer?->fullName()); ?></div>
                                            <div class="text-muted small"><?php echo e($transaction->customer?->account_number); ?></div>
                                        </td>
                                        <td>
                                            <div><?php echo e($transaction->account?->account_number); ?></div>
                                            <div class="text-muted small"><?php echo e($transaction->account?->product_name); ?></div>
                                        </td>
                                        <td class="fw-semibold"><?php echo e($money($transaction->amount)); ?></td>
                                        <td><?php echo e($transaction->creator?->name ?: 'System'); ?></td>
                                        <td class="text-end">
                                            <div class="dropdown">
                                                <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">Action</button>
                                                <ul class="dropdown-menu dropdown-menu-end">
                                                    <li><button class="dropdown-item" type="button" data-bs-toggle="modal" data-bs-target="#pendingDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-eye me-2"></i>View</button></li>
                                                    <li>
                                                        <form method="POST" action="<?php echo e(route('tenant.savings.transactions.approve', $transaction)); ?>">
                                                            <?php echo csrf_field(); ?>
                                                            <button class="dropdown-item text-success"><i class="bi bi-check2-circle me-2"></i>Approve</button>
                                                        </form>
                                                    </li>
                                                    <li><button class="dropdown-item text-danger" type="button" data-bs-toggle="modal" data-bs-target="#rejectDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-x-circle me-2"></i>Reject</button></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <?php $__currentLoopData = $pendingDeposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="modal fade" id="pendingDeposit<?php echo e($transaction->id); ?>" tabindex="-1" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h2 class="modal-title h5">Deposit details</h2>
                                        <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <dl class="row small mb-0">
                                            <dt class="col-5">Reference</dt><dd class="col-7"><?php echo e($transaction->reference); ?></dd>
                                            <dt class="col-5">Member</dt><dd class="col-7"><?php echo e($transaction->customer?->fullName()); ?></dd>
                                            <dt class="col-5">Account</dt><dd class="col-7"><?php echo e($transaction->account?->account_number); ?></dd>
                                            <dt class="col-5">Product</dt><dd class="col-7"><?php echo e($transaction->account?->product_name); ?></dd>
                                            <dt class="col-5">Amount</dt><dd class="col-7"><?php echo e($money($transaction->amount)); ?></dd>
                                            <dt class="col-5">Method</dt><dd class="col-7"><?php echo e(str($transaction->method)->headline()); ?></dd>
                                            <dt class="col-5">Initiated by</dt><dd class="col-7"><?php echo e($transaction->creator?->name ?: 'System'); ?></dd>
                                            <dt class="col-5">Narration</dt><dd class="col-7"><?php echo e($transaction->description ?: '-'); ?></dd>
                                        </dl>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal fade" id="rejectDeposit<?php echo e($transaction->id); ?>" tabindex="-1" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered">
                                <div class="modal-content">
                                    <form method="POST" action="<?php echo e(route('tenant.savings.transactions.reject', $transaction)); ?>">
                                        <?php echo csrf_field(); ?>
                                        <div class="modal-header">
                                            <h2 class="modal-title h5">Reject deposit</h2>
                                            <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body">
                                            <label class="form-label">Reason</label>
                                            <textarea name="rejected_reason" class="form-control" rows="3" required></textarea>
                                        </div>
                                        <div class="modal-footer">
                                            <button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button>
                                            <button class="btn btn-danger">Reject deposit</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="pending-empty-state">
                        <i class="bi bi-check2-circle"></i>
                        <strong>No pending deposit</strong>
                        <span>Deposits awaiting approval will appear here.</span>
                    </div>
                <?php endif; ?>
            </div>

            <div class="tab-pane fade" id="member-deposit-requests">
                <div class="finance-pane-title">
                    <div>
                        <span>Member request</span>
                        <h3>Member-initiated deposit approvals</h3>
                        <p>Online member deposits that were started from the member portal are separated from staff-entered deposits.</p>
                    </div>
                    <strong class="text-info"><?php echo e($compactMoney($depositStats['member_request_amount'] ?? 0)); ?></strong>
                </div>
                <?php if($memberDepositRequests->isNotEmpty()): ?>
                    <div class="table-responsive">
                        <table class="table align-middle mb-0">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Member</th>
                                    <th>Account</th>
                                    <th>Method</th>
                                    <th class="text-end">Amount</th>
                                    <th class="text-end">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $memberDepositRequests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e(app_datetime($transaction->transacted_at)); ?></td>
                                        <td>
                                            <div class="fw-semibold"><?php echo e($transaction->customer?->fullName()); ?></div>
                                            <div class="text-muted small"><?php echo e($transaction->customer?->account_number); ?></div>
                                        </td>
                                        <td>
                                            <div><?php echo e($transaction->account?->account_number); ?></div>
                                            <div class="text-muted small"><?php echo e($transaction->account?->product_name); ?></div>
                                        </td>
                                        <td><?php echo e(str($transaction->method)->headline()); ?></td>
                                        <td class="text-end fw-semibold"><?php echo e($money($transaction->amount)); ?></td>
                                        <td class="text-end">
                                            <div class="dropdown">
                                                <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">Action</button>
                                                <ul class="dropdown-menu dropdown-menu-end">
                                                    <li>
                                                        <form method="POST" action="<?php echo e(route('tenant.savings.transactions.approve', $transaction)); ?>">
                                                            <?php echo csrf_field(); ?>
                                                            <button class="dropdown-item text-success"><i class="bi bi-check2-circle me-2"></i>Approve</button>
                                                        </form>
                                                    </li>
                                                    <li><button class="dropdown-item text-danger" type="button" data-bs-toggle="modal" data-bs-target="#rejectMemberDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-x-circle me-2"></i>Reject</button></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <?php $__currentLoopData = $memberDepositRequests; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="modal fade" id="rejectMemberDeposit<?php echo e($transaction->id); ?>" tabindex="-1" aria-hidden="true">
                            <div class="modal-dialog modal-dialog-centered">
                                <div class="modal-content">
                                    <form method="POST" action="<?php echo e(route('tenant.savings.transactions.reject', $transaction)); ?>">
                                        <?php echo csrf_field(); ?>
                                        <div class="modal-header">
                                            <h2 class="modal-title h5">Reject member deposit</h2>
                                            <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body">
                                            <label class="form-label">Reason</label>
                                            <textarea name="rejected_reason" class="form-control" rows="3" required></textarea>
                                        </div>
                                        <div class="modal-footer">
                                            <button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button>
                                            <button class="btn btn-danger">Reject deposit</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <div class="pending-empty-state">
                        <i class="bi bi-person-check"></i>
                        <strong>No member deposit request</strong>
                        <span>Member portal deposit requests waiting for approval will appear here.</span>
                    </div>
                <?php endif; ?>
            </div>
        <?php endif; ?>

        <div class="tab-pane fade" id="deposit-accounts">
            <div class="finance-pane-title">
                <div>
                    <span>Deposit-ready accounts</span>
                    <h3>Active savings accounts</h3>
                    <p>Use this list to quickly confirm a member account before posting a deposit.</p>
                </div>
            </div>
            <div class="p-3">
                <form method="GET" class="row g-2 align-items-end finance-filter-panel mb-3">
                    <div class="col-md-8">
                        <label class="form-label">Search member or account</label>
                        <input name="q" value="<?php echo e($search); ?>" class="form-control" placeholder="Name, member account, phone, savings account">
                    </div>
                    <div class="col-md-4">
                        <button class="btn btn-outline-primary w-100"><i class="bi bi-search me-1"></i> Search</button>
                    </div>
                </form>
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>Account</th>
                                <th>Member</th>
                                <th>Product</th>
                                <th>Balance</th>
                                <th class="text-end">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td class="fw-semibold"><?php echo e($account->account_number); ?></td>
                                    <td>
                                        <div><?php echo e($account->customer?->fullName()); ?></div>
                                        <div class="text-muted small"><?php echo e($account->customer?->account_number); ?></div>
                                    </td>
                                    <td><?php echo e($account->product_name); ?></td>
                                    <td><?php echo e($compactMoney($account->balance)); ?></td>
                                    <td class="text-end">
                                        <a href="<?php echo e(route('tenant.savings.show', $account)); ?>" class="btn btn-sm btn-outline-secondary">Open</a>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr><td colspan="5" class="text-center text-muted py-4">No active account matches this filter.</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <?php echo e($accounts->links()); ?>

            </div>
        </div>

        <div class="<?php echo \Illuminate\Support\Arr::toCssClasses(['tab-pane fade', 'show active' => ! $canManageSavings && ! $canUseDepositApproval]); ?>" id="deposit-history">
            <div class="finance-pane-title">
                <div>
                    <span>Deposit history</span>
                    <h3>Posted, rejected, and canceled deposits</h3>
                    <p>Search and filter deposit records with initiator, approver, receipt, and account details.</p>
                </div>
            </div>
            <div class="p-3">
                <form method="GET" class="row g-2 align-items-end finance-filter-panel mb-3">
                    <div class="col-lg-3">
                        <label class="form-label">Search</label>
                        <input name="q" value="<?php echo e($search); ?>" class="form-control" placeholder="Reference, member, account, method">
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select">
                            <option value="">All</option>
                            <?php $__currentLoopData = ['posted' => 'Posted', 'rejected' => 'Rejected', 'canceled' => 'Canceled']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($value); ?>" <?php if($status === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">Initiated by</label>
                        <select name="initiated_by" class="form-select">
                            <option value="">All</option>
                            <?php $__currentLoopData = $usersForFilter; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filterUser): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($filterUser->id); ?>" <?php if((int) $initiatedBy === $filterUser->id): echo 'selected'; endif; ?>><?php echo e($filterUser->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">Approved by</label>
                        <select name="approved_by" class="form-select">
                            <option value="">All</option>
                            <?php $__currentLoopData = $usersForFilter; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filterUser): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($filterUser->id); ?>" <?php if((int) $approvedBy === $filterUser->id): echo 'selected'; endif; ?>><?php echo e($filterUser->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">From</label>
                        <input name="from" type="date" value="<?php echo e($from); ?>" class="form-control">
                    </div>
                    <div class="col-md-2">
                        <label class="form-label">To</label>
                        <input name="to" type="date" value="<?php echo e($to); ?>" class="form-control">
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-outline-primary w-100"><i class="bi bi-funnel me-1"></i> Filter</button>
                    </div>
                </form>
                <div class="table-responsive">
                    <table class="table align-middle">
                        <thead>
                            <tr>
                                <th>Date</th>
                                <th>Member</th>
                                <th>Account</th>
                                <th>Amount</th>
                                <th>Status</th>
                                <th>Initiated by</th>
                                <th>Approved by</th>
                                <th class="text-end">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $deposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e(app_date($transaction->transacted_at)); ?></td>
                                    <td>
                                        <div class="fw-semibold"><?php echo e($transaction->customer?->fullName()); ?></div>
                                        <div class="text-muted small"><?php echo e($transaction->customer?->account_number); ?></div>
                                    </td>
                                    <td>
                                        <div><?php echo e($transaction->account?->account_number); ?></div>
                                        <div class="text-muted small"><?php echo e($transaction->account?->product_name); ?></div>
                                    </td>
                                    <td>
                                        <div class="fw-semibold"><?php echo e($money($transaction->amount)); ?></div>
                                        <?php if((float) $transaction->processing_fee_amount > 0): ?>
                                            <div class="text-muted small">Fee <?php echo e($money($transaction->processing_fee_amount)); ?></div>
                                        <?php endif; ?>
                                    </td>
                                    <td><span class="badge text-bg-<?php echo e($statusClass($transaction->status)); ?>"><?php echo e(ucfirst($transaction->status)); ?></span></td>
                                    <td><?php echo e($transaction->creator?->name ?: 'System'); ?></td>
                                    <td><?php echo e($transaction->approver?->name ?: '-'); ?></td>
                                    <td class="text-end">
                                        <div class="dropdown">
                                            <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">Action</button>
                                            <ul class="dropdown-menu dropdown-menu-end">
                                                <li><button class="dropdown-item" type="button" data-bs-toggle="modal" data-bs-target="#depositHistory<?php echo e($transaction->id); ?>"><i class="bi bi-eye me-2"></i>View</button></li>
                                                <?php if($transaction->status === 'posted'): ?>
                                                    <li><a class="dropdown-item" href="<?php echo e(route('tenant.savings.transactions.receipt', $transaction)); ?>"><i class="bi bi-receipt me-2"></i>Receipt</a></li>
                                                <?php endif; ?>
                                                <li><a class="dropdown-item" href="<?php echo e(route('tenant.savings.show', $transaction->account)); ?>"><i class="bi bi-wallet2 me-2"></i>Open account</a></li>
                                                <?php if($canApproveSavings && $transaction->status === 'posted'): ?>
                                                    <li><button class="dropdown-item text-danger" type="button" data-bs-toggle="modal" data-bs-target="#cancelDeposit<?php echo e($transaction->id); ?>"><i class="bi bi-slash-circle me-2"></i>Cancel</button></li>
                                                <?php endif; ?>
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr><td colspan="8" class="text-center text-muted py-4">No deposit record found.</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <?php echo e($deposits->links()); ?>

            </div>
            <?php $__currentLoopData = $deposits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="modal fade" id="depositHistory<?php echo e($transaction->id); ?>" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h2 class="modal-title h5">Deposit record</h2>
                                <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <dl class="row small mb-0">
                                    <dt class="col-5">Reference</dt><dd class="col-7"><?php echo e($transaction->reference); ?></dd>
                                    <dt class="col-5">Member</dt><dd class="col-7"><?php echo e($transaction->customer?->fullName()); ?></dd>
                                    <dt class="col-5">Savings account</dt><dd class="col-7"><?php echo e($transaction->account?->account_number); ?></dd>
                                    <dt class="col-5">Amount</dt><dd class="col-7"><?php echo e($money($transaction->amount)); ?></dd>
                                    <dt class="col-5">Net saved</dt><dd class="col-7"><?php echo e($money($transaction->net_amount)); ?></dd>
                                    <dt class="col-5">Processing fee</dt><dd class="col-7"><?php echo e($money($transaction->processing_fee_amount)); ?></dd>
                                    <dt class="col-5">Method</dt><dd class="col-7"><?php echo e(str($transaction->method)->headline()); ?></dd>
                                    <dt class="col-5">Status</dt><dd class="col-7"><?php echo e(ucfirst($transaction->status)); ?></dd>
                                    <dt class="col-5">Initiated by</dt><dd class="col-7"><?php echo e($transaction->creator?->name ?: 'System'); ?></dd>
                                    <dt class="col-5">Approved by</dt><dd class="col-7"><?php echo e($transaction->approver?->name ?: '-'); ?></dd>
                                    <dt class="col-5">Canceled by</dt><dd class="col-7"><?php echo e($transaction->canceler?->name ?: '-'); ?></dd>
                                    <dt class="col-5">Narration</dt><dd class="col-7"><?php echo e($transaction->description ?: '-'); ?></dd>
                                    <dt class="col-5">Cancel reason</dt><dd class="col-7"><?php echo e($transaction->canceled_reason ?: '-'); ?></dd>
                                </dl>
                            </div>
                        </div>
                    </div>
                </div>
                <?php if($canApproveSavings && $transaction->status === 'posted'): ?>
                    <div class="modal fade" id="cancelDeposit<?php echo e($transaction->id); ?>" tabindex="-1" aria-hidden="true">
                        <div class="modal-dialog modal-dialog-centered">
                            <div class="modal-content">
                                <form method="POST" action="<?php echo e(route('tenant.savings.transactions.cancel', $transaction)); ?>">
                                    <?php echo csrf_field(); ?>
                                    <div class="modal-header">
                                        <h2 class="modal-title h5">Cancel deposit</h2>
                                        <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <p class="text-muted small">Canceling reverses this posted deposit from the member savings balance.</p>
                                        <label class="form-label">Reason</label>
                                        <textarea name="canceled_reason" class="form-control" rows="3" required></textarea>
                                    </div>
                                    <div class="modal-footer">
                                        <button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button>
                                        <button class="btn btn-danger">Cancel deposit</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views\tenant\deposits\index.blade.php ENDPATH**/ ?>