<?php $__env->startSection('title', 'Defaulters'); ?>
<?php $__env->startSection('page_title', 'Fee Defaulters'); ?>
<?php $__env->startSection('breadcrumbs'); ?>
    <li class="breadcrumb-item"><a href="<?php echo e(route('dashboard')); ?>">Home</a></li><li class="breadcrumb-item active">Defaulters</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="row g-3 mb-3">
        <div class="col-sm-6 col-xl-3">
            <div class="card stat-card"><div class="card-body d-flex align-items-center gap-3">
                <div class="icon bg-soft-danger"><i class="bi bi-exclamation-triangle"></i></div>
                <div><div class="value"><?php echo e($challans->count()); ?></div><div class="label">Overdue Challans</div></div>
            </div></div>
        </div>
        <div class="col-sm-6 col-xl-3">
            <div class="card stat-card"><div class="card-body d-flex align-items-center gap-3">
                <div class="icon bg-soft-warning"><i class="bi bi-cash-stack"></i></div>
                <div><div class="value"><?php echo e(number_format($totalOutstanding)); ?></div><div class="label">Total Outstanding</div></div>
            </div></div>
        </div>
    </div>

    
    <div class="card mb-3"><div class="card-body">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-3">
                <label class="form-label small mb-1">Search</label>
                <div class="input-group input-group-sm">
                    <span class="input-group-text bg-white"><i class="bi bi-search text-muted"></i></span>
                    <input type="text" name="search" value="<?php echo e($filters['search'] ?? ''); ?>" class="form-control" placeholder="Challan #, family code, name, mobile…">
                </div>
            </div>
            <div class="col-md-2">
                <label class="form-label small mb-1">Class</label>
                <select name="class_id" class="form-select form-select-sm">
                    <option value="">All Classes</option>
                    <?php $__currentLoopData = $classes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $class): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($class->id); ?>" <?php if(($filters['class_id'] ?? '') == $class->id): echo 'selected'; endif; ?>><?php echo e($class->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <label class="form-label small mb-1">Section</label>
                <select name="section_id" class="form-select form-select-sm">
                    <option value="">All Sections</option>
                    <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($section->id); ?>" <?php if(($filters['section_id'] ?? '') == $section->id): echo 'selected'; endif; ?>><?php echo e($section->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <label class="form-label small mb-1">Due From</label>
                <input type="date" name="from" value="<?php echo e($filters['from'] ?? ''); ?>" class="form-control form-control-sm">
            </div>
            <div class="col-md-2">
                <label class="form-label small mb-1">Due To</label>
                <input type="date" name="to" value="<?php echo e($filters['to'] ?? ''); ?>" class="form-control form-control-sm">
            </div>
            <div class="col-md-1">
                <div class="form-check small mb-1" title="Include challans not yet overdue">
                    <input type="checkbox" class="form-check-input" id="scopeAll" name="scope" value="all" <?php if(($filters['scope'] ?? 'overdue') === 'all'): echo 'checked'; endif; ?>>
                    <label class="form-check-label" for="scopeAll">All unpaid</label>
                </div>
            </div>
            <div class="col-12 d-flex gap-2 mt-1">
                <button class="btn btn-sm btn-primary"><i class="bi bi-funnel me-1"></i>Filter</button>
                <a href="<?php echo e(route('fees.defaulters')); ?>" class="btn btn-sm btn-light border">Reset</a>
                <?php $exp = array_merge(request()->except('export'), []); ?>
                <a href="<?php echo e(route('fees.defaulters', array_merge($exp, ['export' => 'pdf']))); ?>" class="btn btn-sm btn-light border ms-auto"><i class="bi bi-file-earmark-pdf text-danger me-1"></i>PDF</a>
                <a href="<?php echo e(route('fees.defaulters', array_merge($exp, ['export' => 'csv']))); ?>" class="btn btn-sm btn-light border"><i class="bi bi-file-earmark-excel text-success me-1"></i>Excel</a>
                <button type="button" onclick="window.print()" class="btn btn-sm btn-light border"><i class="bi bi-printer me-1"></i>Print</button>
            </div>
        </form>
    </div></div>

    <div class="card"><div class="card-body">
        <?php if(($filters['search'] ?? false) || ($filters['class_id'] ?? false) || ($filters['section_id'] ?? false) || ($filters['from'] ?? false) || ($filters['to'] ?? false)): ?>
            <div class="small text-muted mb-2"><?php echo e($challans->count()); ?> result(s) match your filters.</div>
        <?php endif; ?>
        <table class="table table-hover align-middle js-datatable">
            <thead><tr>
                <th>Challan No.</th><th>Student Name</th><th>Student Contact</th><th>Father Name</th>
                <th>Father Contact</th><th>Class</th><th>Fee Month</th><th class="text-end">Outstanding</th><th class="text-end"></th>
            </tr></thead>
            <tbody>
                <?php $__currentLoopData = $challans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $stuNames = $ch->items->map(fn ($i) => $i->student?->name)->filter()->unique()->implode(', ');
                        $clsNames = $ch->items->map(fn ($i) => $i->student?->schoolClass?->name)->filter()->unique()->implode(', ');
                    ?>
                    <tr>
                        <td class="small"><a href="<?php echo e(route('challans.show', $ch)); ?>" class="text-decoration-none"><?php echo e($ch->challan_number); ?></a></td>
                        <td class="small fw-semibold"><?php echo e($stuNames ?: '—'); ?></td>
                        <td class="small"><?php echo e($ch->family?->primary_mobile ?: '—'); ?></td>
                        <td class="small"><?php echo e($ch->family?->father_name ?: '—'); ?></td>
                        <td class="small"><?php echo e($ch->family?->father_mobile ?: '—'); ?></td>
                        <td class="small"><?php echo e($clsNames ?: '—'); ?></td>
                        <td class="small"><?php echo e($ch->title); ?></td>
                        <td class="text-end fw-semibold text-danger"><?php echo e(number_format($ch->balance)); ?></td>
                        <td class="text-end"><a href="<?php echo e(route('challans.show', $ch)); ?>" class="btn btn-sm btn-light border">Collect</a></td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div></div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/u385418287/domains/itartificer.com/public_html/sms-erp/resources/views/fees/defaulters.blade.php ENDPATH**/ ?>