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

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

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

<?php $__env->startSection('content'); ?>
<div class="col-md-12">
    <div class="card card-body mb-2">
        <form action="<?php echo e(route('dps.index')); ?>" method="GET" class="mb-3">
            <div class="row">

                <!-- Customer Filter -->
                <div class="col-md-3">
                    <select name="customer_id" class="form-control" data-provide="selectpicker" data-live-search="true">
                        <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>

                <!-- DPS ID Filter -->
                <div class="col-md-2">
                    <input type="text" name="dps_id" class="form-control" placeholder="DPS ID"
                        value="<?php echo e(request('dps_id')); ?>">
                </div>

                <!-- Status Filter -->
                <div class="col-md-2">
                    <select name="status" class="form-control">
                        <option value="">All Status</option>
                        <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                        <option value="active" <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>Active</option>
                        <option value="completed" <?php echo e(request('status') == 'completed' ? 'selected' : ''); ?>>Completed
                        </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="from_date" placeholder="Start Date" value="<?php echo e(request('from_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="to_date" placeholder="End Date" value="<?php echo e(request('to_date')); ?>">
                </div>

                <!-- Buttons -->
                <div class="col-md-1">
                    <button type="submit" class="btn btn-primary btn-block">Filter</button>
                    <a href="<?php echo e(route('dps.index')); ?>" class="btn btn-secondary btn-block mt-1">Reset</a>
                </div>

            </div>
        </form>


    </div>

    <div class="card">
        <h4 class="card-title fw-400"> DPS Accounts </h4>

        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead class="thead-light">
                        <tr>
                            <th>#</th>
                            <th>DPS No</th>
                            <th>Customer</th>
                            <th>Monthly Amount</th>
                            <th>Duration</th>
                            <th>Duration (Years)</th>
                            <th>Total Deposit</th>
                            <th>Interest</th>
                            <th>Maturity Amount</th>
                            <th>Status</th>
                            <th width="140">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $dpsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $dps): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($dpsAccounts->firstItem() + $key); ?></td>
                            <td><?php echo e($dps->id); ?></td>
                            <td>
                                <?php echo e($dps->customer->name); ?> <br>
                                <small class="text-muted"><?php echo e($dps->customer->mobile_no); ?></small>
                            </td>
                            <td><?php echo e(number_format($dps->monthly_amount, 2)); ?></td>
                            <td><?php echo e($dps->duration_months); ?> Months</td>
                            <td><?php echo e(number_format($dps->duration_months / 12, 1)); ?></td>
                            <td><?php echo e(number_format($dps->total_deposit, 2)); ?></td>
                            <td>
                                <?php echo e($dps->interest_rate); ?>%
                                <small class="text-muted d-block">
                                    (<?php echo e(ucfirst($dps->interest_type)); ?>)
                                </small>
                            </td>
                            <td><?php echo e(number_format($dps->maturity_amount, 2)); ?></td>
                            <td>
                                <?php if($dps->status == 'running'): ?>
                                <span class="badge badge-warning">Running</span>
                                <?php elseif($dps->status == 'completed'): ?>
                                <span class="badge badge-success">Completed</span>
                                <?php elseif($dps->status == 'withdrawn'): ?>
                                <span class="badge badge-primary">Withdrawn</span>
                                <?php else: ?>
                                <span class="badge badge-danger">Closed</span>
                                <?php endif; ?>
                            </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">
                                        <!-- View DPS -->
                                          <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('show-dps')): ?>
                                        <a class="dropdown-item" href="<?php echo e(route('dps.show', $dps->id)); ?>">
                                            <i class="fa fa-eye"></i> View
                                        </a>
                                        <?php endif; ?>
                                        <!-- Installments / Collection -->
                                         <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('dps_payment')): ?>
                                        <a class="dropdown-item" href="<?php echo e(route('dps.installments', $dps->id)); ?>">
                                            <i class="fa fa-list"></i> Collection
                                        </a>
                                        <?php endif; ?>

                                        <!-- Close DPS if running -->
                                          <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('dps_status')): ?>
                                        <?php if($dps->status == 'running'): ?>
                                        <form action="<?php echo e(route('dps.close', $dps->id)); ?>" method="POST" class="d-inline"
                                            onsubmit="return confirm('Are you sure you want to close this DPS?')">
                                            <?php echo csrf_field(); ?>
                                            <button class="dropdown-item text-danger" type="submit">
                                                <i class="fa fa-times"></i> Close DPS
                                            </button>
                                        </form>
                                        <?php endif; ?>
                                        <?php endif; ?>

                                        <!-- Withdraw DPS if eligible -->
                                        <!-- <?php if(in_array($dps->status, ['closed', 'completed']) ||
                                        now()->gte($dps->maturity_date)): ?>
                                        <a class="dropdown-item" href="<?php echo e(route('dps.withdraw.form', $dps->id)); ?>">
                                            <i class="fa fa-hand-holding-usd"></i> Withdraw DPS
                                        </a>
                                        <?php endif; ?> -->
                                    </div>
                                </div>
                            </td>

                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="10" class="text-center text-muted">
                                No DPS accounts found.
                            </td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

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

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

<?php $__env->startSection('styles'); ?>
<style>
    .badge {
        font-size: 90%;
    }

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

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

</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/dps/index.blade.php ENDPATH**/ ?>