<?php $__env->startSection('title', 'ফি/বিল ব্যবস্থাপনা'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <!-- Search Section - NESCO Style -->
    <div class="row">
        <div class="col-12">
            <div class="card text-center card-primary card-outline">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0"><i class="fa fa-search"></i> ফি/বিল অনুসন্ধান</h5>
                </div>
                <div class="card-body" style="background-color: #f0f9ff;">
                    <form class="form-horizontal" method="POST" action="<?php echo e(route('fees.search')); ?>">
                        <?php echo csrf_field(); ?>
                        <div class="form-group row justify-content-center">
                            <div class="col-md-3">
                                <label class="font-weight-bold">গ্রাহক/ছাত্র আইডি</label>
                                <input type="text" 
                                       class="form-control form-control-lg text-center <?php $__errorArgs = ['student_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" 
                                       name="student_id" 
                                       placeholder="যেমন: 2026001"
                                       value="<?php echo e(old('student_id')); ?>"
                                       required>
                                <?php $__errorArgs = ['student_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <span class="invalid-feedback"><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                        
                        <div class="form-group row justify-content-center mt-3">
                            <div class="col-md-8">
                                <button type="submit" name="action" value="due" class="btn btn-danger btn-lg">
                                    <i class="fa fa-exclamation-triangle"></i> বকেয়া ফি
                                </button>
                                <button type="submit" name="action" value="all" class="btn btn-info btn-lg">
                                    <i class="fa fa-list"></i> সকল ফি
                                </button>
                                <button type="submit" name="action" value="summary" class="btn btn-success btn-lg">
                                    <i class="fa fa-chart-pie"></i> ফি সামারি রিপোর্ট
                                </button>
                                <button type="button" id="reset_button" class="btn btn-secondary btn-lg">
                                    <i class="fa fa-undo"></i> রিসেট
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row mt-3">
        <div class="col-md-6">
            <div class="card card-success">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fa fa-bolt"></i> দ্রুত অ্যাকশন</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <button type="button" class="btn btn-outline-primary btn-block mb-2" data-toggle="modal" data-target="#bulkFeeModal">
                                <i class="fa fa-layer-group"></i> মাসিক ফি জেনারেট
                            </button>
                        </div>
                        <div class="col-md-6">
                            <a href="<?php echo e(route('fees.due-report')); ?>" class="btn btn-outline-danger btn-block mb-2">
                                <i class="fa fa-file-invoice"></i> বকেয়া রিপোর্ট
                            </a>
                        </div>
                        <div class="col-md-6">
                            <a href="<?php echo e(route('fees.collection-report', ['from_date' => date('Y-m-01'), 'to_date' => date('Y-m-d')])); ?>" 
                               class="btn btn-outline-success btn-block mb-2">
                                <i class="fa fa-chart-line"></i> কালেকশন রিপোর্ট
                            </a>
                        </div>
                        <div class="col-md-6">
                            <button type="button" class="btn btn-outline-info btn-block mb-2" onclick="window.print()">
                                <i class="fa fa-print"></i> প্রিন্ট
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Today's Collection -->
        <div class="col-md-6">
            <div class="card card-warning">
                <div class="card-header">
                    <h5 class="mb-0"><i class="fa fa-clock"></i> আজকের কালেকশন</h5>
                </div>
                <div class="card-body">
                    <?php
                        $todayCollection = App\Models\Payment::whereDate('payment_date', today())->sum('amount');
                        $todayCount = App\Models\Payment::whereDate('payment_date', today())->count();
                    ?>
                    <h3 class="text-success"><?php echo e(number_format($todayCollection, 2)); ?> টাকা</h3>
                    <p>মোট <?php echo e($todayCount); ?> টি লেনদেন</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Payments -->
    <?php if(isset($recentPayments) && $recentPayments->count() > 0): ?>
    <div class="row mt-3">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h5 class="mb-0"><i class="fa fa-history"></i> সাম্প্রতিক পেমেন্ট</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead class="bg-secondary text-white">
                                <tr>
                                    <th>ছাত্র আইডি</th>
                                    <th>নাম</th>
                                    <th>পরিমাণ</th>
                                    <th>পদ্ধতি</th>
                                    <th>তারিখ</th>
                                    <th>রশিদ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $recentPayments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($fee->student->student_id); ?></td>
                                    <td><?php echo e($fee->student->name_bn); ?></td>
                                    <td class="text-success font-weight-bold"><?php echo e(number_format($fee->paid_amount, 2)); ?></td>
                                    <td><?php echo e($fee->payment_method); ?></td>
                                    <td><?php echo e($fee->updated_at->format('d-m-Y h:i A')); ?></td>
                                    <td>
                                        <a href="<?php echo e(route('fees.receipt', $fee->id)); ?>" class="btn btn-sm btn-info" target="_blank">
                                            <i class="fa fa-download"></i> রশিদ
                                        </a>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <!-- Bulk Fee Generation Modal -->
    <div class="modal fade" id="bulkFeeModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title">মাসিক ফি জেনারেট</h5>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <form action="<?php echo e(route('fees.bulk-generate')); ?>" method="POST">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>শ্রেণি <span class="text-danger">*</span></label>
                            <select name="class_id" class="form-control" required>
                                <option value="">শ্রেণি নির্বাচন করুন</option>
                                <?php $__currentLoopData = $classes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $class): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($class->id); ?>">
                                    <?php echo e($class->class_name_bn); ?> <?php if($class->section): ?>(<?php echo e($class->section); ?>)<?php endif; ?>
                                </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>মাস <span class="text-danger">*</span></label>
                            <select name="month" class="form-control" required>
                                <option value="">মাস নির্বাচন করুন</option>
                                <?php $__currentLoopData = range(1, 12); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $m): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($m); ?>" <?php echo e($m == date('n') ? 'selected' : ''); ?>>
                                    <?php echo e(DateTime::createFromFormat('!m', $m)->format('F')); ?>

                                </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>বছর <span class="text-danger">*</span></label>
                            <select name="year" class="form-control" required>
                                <?php $__currentLoopData = range(date('Y')-1, date('Y')+1); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $y): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($y); ?>" <?php echo e($y == date('Y') ? 'selected' : ''); ?>><?php echo e($y); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">বাতিল</button>
                        <button type="submit" class="btn btn-primary">জেনারেট করুন</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function() {
        $('#reset_button').click(function() {
            $('input[name="student_id"]').val('');
        });
        
        // Form target based on action
        $('form').submit(function(e) {
            var action = $(document.activeElement).val();
            if (action === 'summary') {
                $(this).attr('target', '_blank');
            } else {
                $(this).attr('target', '_self');
            }
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/naowarin/school.naowarinternational.my.id/resources/views/fees/index.blade.php ENDPATH**/ ?>