<?php $__env->startSection('title', 'ছাত্রের ফি/বিল তালিকা'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <!-- Back Button -->
    <div class="row mb-3">
        <div class="col-12">
            <a href="<?php echo e(route('fees.index')); ?>" class="btn btn-secondary">
                <i class="fa fa-arrow-left"></i> অনুসন্ধানে ফিরে যান
            </a>
        </div>
    </div>

    <!-- Due Notice (if any) -->
    <?php if($summary['total_due'] > 0): ?>
    <div class="row">
        <div class="col-12">
            <div class="card" style="border-color: #dc3545; border-width: 2px;">
                <div class="card-header bg-danger text-white">
                    <h5 class="mb-0"><i class="fa fa-exclamation-circle"></i> বকেয়া নোটিশ</h5>
                </div>
                <div class="card-body">
                    <div class="alert alert-danger m-0">
                        <h5>
                            চলতি মাস ব্যাতিত আপনার মোট বকেয়ার পরিমাণ 
                            <strong><?php echo e(number_format($summary['total_due'], 2)); ?> টাকা</strong>।
                        </h5>
                        <p class="mb-0">যেকোনো সময় নাম কর্তন এড়াতে এখনই সকল বকেয়া ফি পরিশোধ করুন।</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <!-- Student Info Card -->
    <div class="row mt-3">
        <div class="col-12">
            <div class="card card-primary">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0"><i class="fa fa-user-graduate"></i> ছাত্র/ছাত্রীর তথ্য</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3">
                            <label class="text-muted">ছাত্র আইডি</label>
                            <p class="font-weight-bold h5"><?php echo e($student->student_id); ?></p>
                        </div>
                        <div class="col-md-3">
                            <label class="text-muted">নাম</label>
                            <p class="font-weight-bold"><?php echo e($student->name_bn); ?></p>
                        </div>
                        <div class="col-md-2">
                            <label class="text-muted">শ্রেণি/শাখা</label>
                            <p class="font-weight-bold"><?php echo e($student->class->class_name_bn ?? ''); ?> <?php echo e($student->section); ?></p>
                        </div>
                        <div class="col-md-2">
                            <label class="text-muted">রোল নম্বর</label>
                            <p class="font-weight-bold"><?php echo e($student->roll_number); ?></p>
                        </div>
                        <div class="col-md-2">
                            <label class="text-muted">মোবাইল</label>
                            <p class="font-weight-bold"><?php echo e($student->phone); ?></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Fee Summary Cards -->
    <div class="row mt-3">
        <div class="col-md-3">
            <div class="small-box bg-info">
                <div class="inner">
                    <h3><?php echo e(number_format($summary['total_fees'], 2)); ?></h3>
                    <p>মোট ফি (টাকা)</p>
                </div>
                <div class="icon">
                    <i class="fa fa-calculator"></i>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="small-box bg-success">
                <div class="inner">
                    <h3><?php echo e(number_format($summary['total_paid'], 2)); ?></h3>
                    <p>পরিশোধিত (টাকা)</p>
                </div>
                <div class="icon">
                    <i class="fa fa-check-circle"></i>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="small-box bg-warning">
                <div class="inner">
                    <h3><?php echo e(number_format($summary['total_discount'], 2)); ?></h3>
                    <p>ছাড় (টাকা)</p>
                </div>
                <div class="icon">
                    <i class="fa fa-percent"></i>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="small-box bg-danger">
                <div class="inner">
                    <h3><?php echo e(number_format($summary['total_due'], 2)); ?></h3>
                    <p>বকেয়া (টাকা)</p>
                </div>
                <div class="icon">
                    <i class="fa fa-exclamation-triangle"></i>
                </div>
            </div>
        </div>
    </div>

    <!-- Fees Table -->
    <div class="row mt-3">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-secondary text-white">
                    <h5 class="mb-0"><i class="fa fa-list"></i> সকল ফি/বিল</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-striped table-hover" id="feeTable">
                            <thead class="bg-primary text-white text-center">
                                <tr>
                                    <th>ফি নম্বর</th>
                                    <th>মাস/বছর</th>
                                    <th>মোট ফি</th>
                                    <th>বিলম্ব ফি</th>
                                    <th>ছাড়</th>
                                    <th>পরিশোধযোগ্য</th>
                                    <th>পরিশোধিত</th>
                                    <th>বকেয়া</th>
                                    <th>পরিশোধের তারিখ</th>
                                    <th>স্ট্যাটাস</th>
                                    <th width="150">একশন</th>
                                </tr>
                            </thead>
                            <tbody class="text-center">
                                <?php $__currentLoopData = $fees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $dueDate = $fee->month_year->copy()->addDays(30);
                                    $isLate = now() > $dueDate && $fee->payment_status != 'paid';
                                ?>
                                <tr class="<?php echo e($isLate ? 'bg-light-danger' : ''); ?>">
                                    <td class="font-weight-bold">
                                        <a href="<?php echo e(route('fees.pay', $fee->id)); ?>" class="text-primary">
                                            <?php echo e($fee->fee_no); ?>

                                        </a>
                                    </td>
                                    <td><?php echo e($fee->month_year->format('F Y')); ?></td>
                                    <td><?php echo e(number_format($fee->total_amount, 2)); ?></td>
                                    <td class="<?php echo e($fee->late_fee > 0 ? 'text-danger font-weight-bold' : ''); ?>">
                                        <?php echo e(number_format($fee->late_fee, 2)); ?>

                                    </td>
                                    <td class="<?php echo e($fee->discount > 0 ? 'text-success' : ''); ?>">
                                        <?php echo e(number_format($fee->discount, 2)); ?>

                                    </td>
                                    <td><?php echo e(number_format($fee->payable_amount, 2)); ?></td>
                                    <td class="text-success"><?php echo e(number_format($fee->paid_amount, 2)); ?></td>
                                    <td class="<?php echo e($fee->due_amount > 0 ? 'text-danger font-weight-bold' : 'text-success'); ?>">
                                        <?php echo e(number_format($fee->due_amount, 2)); ?>

                                    </td>
                                    <td>
                                        <?php if($fee->last_payment_date): ?>
                                            <?php echo e($fee->last_payment_date->format('d-m-Y')); ?>

                                        <?php else: ?>
                                            --
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if($fee->payment_status == 'paid'): ?>
                                            <span class="badge badge-success p-2">পরিশোধিত</span>
                                        <?php elseif($fee->payment_status == 'partial'): ?>
                                            <span class="badge badge-warning p-2">আংশিক</span>
                                        <?php else: ?>
                                            <span class="badge badge-danger p-2">বকেয়া</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if($fee->due_amount > 0): ?>
                                            <a href="<?php echo e(route('fees.pay', $fee->id)); ?>" 
                                               class="btn btn-sm btn-success" title="পেমেন্ট">
                                                <i class="fa fa-credit-card"></i> পে
                                            </a>
                                        <?php endif; ?>
                                        
                                        <?php if($fee->payment_status == 'paid'): ?>
                                            <a href="<?php echo e(route('fees.download-certificate', $fee->id)); ?>" 
                                               class="btn btn-sm btn-info" target="_blank" title="সার্টিফিকেট">
                                                <i class="fa fa-download"></i>
                                            </a>
                                        <?php endif; ?>
                                        
                                        <?php if($fee->paid_amount > 0): ?>
                                            <a href="#" class="btn btn-sm btn-secondary" title="রশিদ">
                                                <i class="fa fa-receipt"></i>
                                            </a>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Payment History -->
    <?php
        $payments = App\Models\Payment::whereHas('fee', function($q) use ($student) {
            $q->where('student_id', $student->id);
        })->orderBy('payment_date', 'desc')->get();
    ?>

    <?php if($payments->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-sm table-bordered">
                            <thead class="bg-secondary text-white">
                                <tr>
                                    <th>রশিদ নং</th>
                                    <th>তারিখ</th>
                                    <th>পরিমাণ</th>
                                    <th>পদ্ধতি</th>
                                    <th>লেনদেন আইডি</th>
                                    <th>কালেক্টর</th>
                                    <th>রশিদ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($payment->receipt_no); ?></td>
                                    <td><?php echo e($payment->payment_date->format('d-m-Y')); ?></td>
                                    <td class="text-success font-weight-bold"><?php echo e(number_format($payment->amount, 2)); ?></td>
                                    <td><?php echo e($payment->payment_method); ?></td>
                                    <td><?php echo e($payment->transaction_id ?? 'N/A'); ?></td>
                                    <td><?php echo e($payment->collector->name ?? 'N/A'); ?></td>
                                    <td>
                                        <a href="<?php echo e(route('fees.receipt', $payment->id)); ?>" class="btn btn-sm btn-info" target="_blank">
                                            <i class="fa fa-print"></i>
                                        </a>
                                    </td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function() {
        $('#feeTable').DataTable({
            "language": {
                "search": "খুঁজুন:",
                "lengthMenu": "_MENU_ টি রেকর্ড দেখুন",
                "info": "মোট _TOTAL_ টির মধ্যে _START_ থেকে _END_ দেখানো হচ্ছে",
                "paginate": {
                    "first": "প্রথম",
                    "last": "শেষ",
                    "next": "পরবর্তী",
                    "previous": "পূর্ববর্তী"
                }
            },
            "order": [[1, 'desc']]
        });
    });
</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/show.blade.php ENDPATH**/ ?>