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

<?php $__env->startSection('content'); ?>

    
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css"/>

    <style>
        :root{
            --primary:#e53935;
            --primary-soft:#fee2e2;
            --bg:#f5f5f5;
        }
        body{
            background:var(--bg);
            font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
        }
        .page-wrap{
            padding:10px 12px 40px;
        }
        .page-head{
            display:flex;
            flex-wrap:wrap;
            align-items:center;
            justify-content:space-between;
            gap:10px;
            margin-bottom:14px;
        }
        .page-title{
            font-size:20px;
            font-weight:600;
            display:flex;
            align-items:center;
            gap:8px;
        }
        .page-title i{
            color:var(--primary);
        }

        .filter-pills{
            display:flex;
            flex-wrap:wrap;
            gap:6px;
        }
        .pill-btn{
            border-radius:999px;
            border:1px solid #e5e7eb;
            padding:6px 12px;
            font-size:13px;
            background:#fff;
            cursor:pointer;
            display:inline-flex;
            align-items:center;
            gap:6px;
            text-decoration:none;
            color:#374151;
            transition:all .16s ease;
        }
        .pill-btn i{
            font-size:14px;
        }
        .pill-btn:hover{
            background:#f3f4f6;
        }
        .pill-btn.active{
            background:var(--primary);
            color:#fff;
            border-color:var(--primary);
            box-shadow:0 8px 18px rgba(220,38,38,.35);
        }

        .card{
            background:#fff;
            border-radius:14px;
            padding:14px 14px 18px;
            box-shadow:0 4px 12px rgba(0,0,0,.06);
        }

        .table thead th{
            font-size:12px;
            text-transform:uppercase;
            letter-spacing:.04em;
            background:#fafafa;
        }
        .table tbody td{
            font-size:13px;
            vertical-align:middle;
        }

        .badge-status{
            border-radius:999px;
            padding:3px 8px;
            font-size:11px;
            font-weight:500;
        }
        .badge-completed{ background:#e8f5e9; color:#2e7d32; }
        .badge-running{ background:#e3f2fd; color:#1565c0; }
        .badge-nopay{ background:#fff7ed; color:#c05621; }
        .badge-mixed{ background:#ede9fe; color:#5b21b6; }

        .stat-pill{
            display:inline-flex;
            align-items:center;
            gap:4px;
            font-size:11px;
            padding:2px 8px;
            border-radius:999px;
            background:#f3f4f6;
            margin-right:4px;
        }
        .stat-pill i{ font-size:12px; color:#9ca3af; }

        @media (max-width:768px){
            .table-responsive{
                font-size:12px;
            }
        }
    </style>

    <div class="page-wrap container-fluid">

        <div class="page-head">
            <div class="page-title">
                <i class="bi bi-people-fill"></i>
                <span>Installment Report (per user)</span>
            </div>

            
            <div class="filter-pills">
                <a href="<?php echo e(route('admin.installments.report', ['filter' => 'all'])); ?>"
                   class="pill-btn <?php echo e($filter==='all' ? 'active' : ''); ?>">
                    <i class="bi bi-ui-checks-grid"></i>
                    <span>All</span>
                </a>

                <a href="<?php echo e(route('admin.installments.report', ['filter' => 'completed'])); ?>"
                   class="pill-btn <?php echo e($filter==='completed' ? 'active' : ''); ?>">
                    <i class="bi bi-award-fill"></i>
                    <span>Completed loans</span>
                </a>

                <a href="<?php echo e(route('admin.installments.report', ['filter' => 'no_payment'])); ?>"
                   class="pill-btn <?php echo e($filter==='no_payment' ? 'active' : ''); ?>">
                    <i class="bi bi-exclamation-triangle-fill"></i>
                    <span>No installment paid</span>
                </a>

                <a href="<?php echo e(route('admin.installments.report', ['filter' => 'running'])); ?>"
                   class="pill-btn <?php echo e($filter==='running' ? 'active' : ''); ?>">
                    <i class="bi bi-play-circle-fill"></i>
                    <span>Running loans</span>
                </a>
            </div>
        </div>

        <?php if(session('success')): ?>
            <div class="alert alert-success py-2"><?php echo e(session('success')); ?></div>
        <?php endif; ?>

        <div class="card">
            <div class="table-responsive">
                <table class="table table-sm align-middle">
                    <thead>
                    <tr>
                        <th>User</th>
                        <th>Loans</th>
                        <th>Installments</th>
                        <th>Status summary</th>
                        <th style="width:110px;">Actions</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $totalLoans   = $user->total_loans;
                            $runningLoans = $user->running_loans;
                            $completed    = $user->completed_loans;

                            $totalIns = $user->total_installments;
                            $paidIns  = $user->paid_installments;
                            $unpaid   = max($totalIns - $paidIns, 0);

                            // badge select
                            if ($completed > 0 && $runningLoans === 0) {
                                $badgeClass = 'badge-completed';
                                $badgeText  = 'All completed';
                            } elseif ($runningLoans > 0 && $paidIns > 0) {
                                $badgeClass = 'badge-running';
                                $badgeText  = 'Running & paying';
                            } elseif ($totalLoans > 0 && $paidIns === 0) {
                                $badgeClass = 'badge-nopay';
                                $badgeText  = 'No installment paid';
                            } else {
                                $badgeClass = 'badge-mixed';
                                $badgeText  = 'Mixed status';
                            }
                        ?>
                        <tr>
                            
                            <td>
                                <div style="font-weight:600;">
                                    <?php echo e($user->name ?? 'N/A'); ?>

                                </div>
                                <div class="text-muted" style="font-size:12px;">
                                    <i class="bi bi-telephone"></i>
                                    <?php echo e($user->phone ?? '-'); ?>

                                    <?php if($user->email): ?>
                                        · <i class="bi bi-envelope"></i> <?php echo e($user->email); ?>

                                    <?php endif; ?>
                                </div>
                            </td>

                            
                            <td>
                                <div class="stat-pill">
                                    <i class="bi bi-credit-card-2-front"></i>
                                    <span>Total: <?php echo e($totalLoans); ?></span>
                                </div>
                                <div class="stat-pill">
                                    <i class="bi bi-play-circle"></i>
                                    <span>Running: <?php echo e($runningLoans); ?></span>
                                </div>
                                <div class="stat-pill">
                                    <i class="bi bi-trophy-fill"></i>
                                    <span>Completed: <?php echo e($completed); ?></span>
                                </div>
                            </td>

                            
                            <td>
                                <div class="stat-pill">
                                    <i class="bi bi-list-check"></i>
                                    <span>Total: <?php echo e($totalIns); ?></span>
                                </div>
                                <div class="stat-pill">
                                    <i class="bi bi-check-circle-fill"></i>
                                    <span>Paid: <?php echo e($paidIns); ?></span>
                                </div>
                                <div class="stat-pill">
                                    <i class="bi bi-clock-history"></i>
                                    <span>Unpaid: <?php echo e($unpaid); ?></span>
                                </div>
                            </td>

                            
                            <td>
                                <span class="badge-status <?php echo e($badgeClass); ?>">
                                    <?php echo e($badgeText); ?>

                                </span>
                            </td>

                            
                            <td>
                                
                                <a href="<?php echo e(url('/admin/loans?user='.$user->id)); ?>"
                                   class="btn btn-sm btn-outline-primary w-100 mb-1">
                                    <i class="bi bi-credit-card"></i>
                                    Loans
                                </a>
                                
                                <a href="<?php echo e(url('/admin/users/'.$user->id)); ?>"
                                   class="btn btn-sm btn-outline-secondary w-100">
                                    <i class="bi bi-person-lines-fill"></i>
                                    Profile
                                </a>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted">
                                No users found for this filter.
                            </td>
                        </tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>

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

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

<?php echo $__env->make('backend.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/ecareba2/loan.rkmotorsbike.top/resources/views/backend/loans/installments_report.blade.php ENDPATH**/ ?>