
<?php $__env->startSection('title', 'Loans'); ?>

<?php $__env->startSection('page-header'); ?>
<header class="header bg-ui-general">
    <div class="header-info">
        <h1 class="header-title">
            <strong>Loans</strong>
        </h1>
    </div>

    <div class="header-action">
        <nav class="nav">
            <a class="nav-link active" href="<?php echo e(route('loans.index')); ?>">
                Loan List
            </a>
            <a class="nav-link" href="<?php echo e(route('loans.create')); ?>">
                <i class="fa fa-plus"></i>
                New Loan
            </a>
        </nav>
    </div>
</header>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="col-md-12">

    <div class="card card-body mb-2">
        <form method="GET" action="<?php echo e(route('loans.index')); ?>" class="mb-4">
            <div class="form-row">
                <!-- Customer -->
                <div class="form-group col-md-3">
                    <select name="customer_id" class="form-control" data-provide="selectpicker" data-live-search="true" data-size="10">
                        <option value="">Select Customer</option>
                        <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($customer->id); ?>"
                            <?php echo e(old(key: 'customer_id') == $customer->id ? 'selected' : ''); ?>>
                            <?php echo e($customer->name); ?> (<?php echo e($customer->mobile_no); ?>) (<?php echo e($customer->account_no); ?>)
                        </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <!-- Status -->
                <div class="form-group col-md-3">
                    <select name="status" class="form-control">
                        <option value="">Select Status</option>
                        <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                        <option value="accept" <?php echo e(request('status') == 'accept' ? 'selected' : ''); ?>>Accept</option>
                        <option value="completed" <?php echo e(request('status') == 'completed' ? 'selected' : ''); ?>>Completed
                        </option>
                        <option value="overdue" <?php echo e(request('status') == 'overdue' ? 'selected' : ''); ?>>Overdue</option>
                    </select>
                </div>

                <!-- Start Date -->
                <div class="form-group col-md-2">
                    <input type="text" class="form-control" data-provide="datepicker" data-date-format="yyyy-mm-dd"
                        name="start_date" placeholder="Start Date" value="<?php echo e(request('start_date')); ?>">
                </div>

                <!-- End Date -->
                <div class="form-group col-md-2">
                    <input type="text" class="form-control" data-provide="datepicker" data-date-format="yyyy-mm-dd"
                        name="end_date" placeholder="End Date" value="<?php echo e(request('end_date')); ?>">
                </div>

                <!-- Buttons -->
                <div class="form-group col-md-2">
                    <button type="submit" class="btn btn-primary">Filter</button>
                    <a href="<?php echo e(route('loans.index')); ?>" class="btn btn-info">Reset</a>
                </div>
            </div>
        </form>
    </div>

    <div class="card">
        <div class="card-header">
            <h4 class="card-title fw-400">All Loans</h4>
        </div>

        <div class="card-body table-responsive">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Customer</th>
                        <th>Loan Amount</th>
                        <th>Total Interest (Rate%)</th>
                        <th>Total Payable</th>
                        <th>Installments</th>
                        <th>Status</th>
                        <!-- <th>Issued On</th> -->
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $loans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $loan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e($loop->iteration); ?></td>
                        <td><?php echo e($loan->customer->name ?? 'N/A'); ?> - <?php echo e($loan->customer->account_no ?? 'N/A'); ?></td>
                        <td><?php echo e(number_format($loan->loan_amount, 2)); ?></td>
                        <td><?php echo e(number_format($loan->total_interest, 2)); ?> (<?php echo e($loan->interest_rate); ?>%)</td>
                        <td><?php echo e(number_format($loan->total_payable, 2)); ?></td>
                        <td><?php echo e($loan->installment_count); ?></td>
                        <td>
                            <span class="<?php echo e($loan->status_badge_class); ?>">
                                <?php echo e(ucfirst($loan->status ?? $loan->computed_status)); ?>

                            </span>
                        </td>
                        <!-- <td><?php echo e(\Carbon\Carbon::parse($loan->issue_date)->format('d M, Y')); ?></td> -->
                        <td>
                            <div class="btn-group">
                                <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"
                                    aria-expanded="false">
                                    <i class="fa fa-cogs"></i>
                                </button>
                                <div class="dropdown-menu">
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('show-loan')): ?>
                                    <a class="dropdown-item" href="<?php echo e(route('loans.show', $loan->id)); ?>">
                                        <i class="fa fa-eye"></i> View
                                    </a>
                                     <?php endif; ?>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit-loan')): ?>
                                    <a class="dropdown-item" href="<?php echo e(route('loans.edit', $loan->id)); ?>">
                                        <i class="fa fa-edit"></i> Edit
                                    </a>
                                    <?php endif; ?>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('loan_payment')): ?>
                                    <a class="dropdown-item" href="<?php echo e(route('loans.installments', $loan->id)); ?>">
                                        <i class="fa fa-list"></i> Collection
                                    </a>
                                    <?php endif; ?>
                                    <a class="dropdown-item" href="<?php echo e(route('loans.payments', $loan->id)); ?>">
                                        <i class="fa fa-history"></i> Payments
                                    </a>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('withdraw-loan-savings')): ?>
                                    <a class="dropdown-item" href="<?php echo e(route('loan.savings.withdraw.form')); ?>?loan_id=<?php echo e($loan->id); ?>">
                                        <i class="fa fa-money"></i> Withdraw Savings
                                    </a>
                                    <?php endif; ?>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete-loan')): ?>
                                    <form action="<?php echo e(route('loans.destroy', $loan->id)); ?>" method="POST"
                                        class="d-inline" onsubmit="return confirm('Are you sure?');">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button class="dropdown-item text-danger" type="submit">
                                            <i class="fa fa-trash"></i> Delete
                                        </button>
                                    </form> 
                                    <?php endif; ?>
                                </div>
                            </div>
                        </td>


                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>

            <div class="mt-3">
                <?php echo e($loans->links()); ?>

            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
<style>
    /* Custom styles if needed */

</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    /* Optional scripts if needed */

</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/demosoftghor/sm.demo.softghor.com/resources/views/pages/loans/index.blade.php ENDPATH**/ ?>