<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include "../include/config.php";

// Check if staff is logged in
if (!isset($_SESSION['email'])) {
    header("location:../index.php");
    exit();
}

$staffEmail = $_SESSION['email'];

// Get staff details
$staffQuery = "SELECT * FROM staff WHERE email = '$staffEmail'";
$staffResult = mysqli_query($conn, $staffQuery);

if (!$staffResult) {
    die("Database query failed: " . mysqli_error($conn));
}

$staffData = mysqli_fetch_assoc($staffResult);

$staffName = $staffData['staffname'] ?? 'Staff Member';
$staffEmail = $staffData['email'] ?? '';

// Handle form submission
$successMessage = $errorMessage = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['add_payment'])) {
        $studentid = mysqli_real_escape_string($conn, $_POST['studentid']);
        $invoice_id = mysqli_real_escape_string($conn, $_POST['invoice_id']);
        $amount = mysqli_real_escape_string($conn, $_POST['amount']);
        $payment_method = mysqli_real_escape_string($conn, $_POST['payment_method']);
        $phone = mysqli_real_escape_string($conn, $_POST['phone']);
        $status = mysqli_real_escape_string($conn, $_POST['status']);
        $year = mysqli_real_escape_string($conn, $_POST['year']);
        $semester = mysqli_real_escape_string($conn, $_POST['semester']);
        $intake = mysqli_real_escape_string($conn, $_POST['intake']);
        $program = mysqli_real_escape_string($conn, $_POST['program']);
        
        // Get invoice details
        $invoiceQuery = "SELECT * FROM association_invoice WHERE id = '$invoice_id'";
        $invoiceResult = mysqli_query($conn, $invoiceQuery);
        $invoiceData = mysqli_fetch_assoc($invoiceResult);
        
        // Check if payment already exists
        $checkQuery = "SELECT * FROM association_payment WHERE studentid = '$studentid' AND invoice_id = '$invoice_id'";
        $checkResult = mysqli_query($conn, $checkQuery);
        
        if (mysqli_num_rows($checkResult) > 0) {
            $errorMessage = "Payment for this invoice already exists for this student!";
        } else {
            $insertQuery = "INSERT INTO association_payment 
                           (studentid, intake, program, year, semester, invoice_id, amount, payment_method, phone, status, payment_date) 
                           VALUES 
                           ('$studentid', '$intake', '$program', '$year', '$semester', '$invoice_id', '$amount', '$payment_method', '$phone', '$status', NOW())";
            
            if (mysqli_query($conn, $insertQuery)) {
                $successMessage = "Payment recorded successfully!";
            } else {
                $errorMessage = "Error: " . mysqli_error($conn);
            }
        }
    }
}

// Fetch all invoices for dropdown
$invoiceQuery = "SELECT * FROM association_invoice ORDER BY year DESC, semester DESC";
$invoiceResult = mysqli_query($conn, $invoiceQuery);

// Fetch existing payments
$paymentQuery = "SELECT p.*, i.description, i.student_type 
                FROM association_payment p 
                LEFT JOIN association_invoice i ON p.invoice_id = i.id 
                ORDER BY p.payment_date DESC";
$paymentResult = mysqli_query($conn, $paymentQuery);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Association Payments</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@400;600&family=Signika+Negative:wght@500&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4cc9f0;
            --warning-color: #f72585;
            --dark-color: #2c3e50;
            --light-color: #f8f9fa;
            --text-color: #333;
            --border-radius: 8px;
            --shadow: 0 4px 12px rgba(0,0,0,0.08);
            --transition: all 0.3s ease;
        }
        
        body {
            background: #f5f7fb;
            font-family: "Josefin Sans", sans-serif;
            color: var(--text-color);
            padding-top: 70px;
        }
        
        .main-navbar {
            background: var(--primary-color);
            color: white;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 60px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            z-index: 1000;
        }
        
        .card {
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            border: none;
            margin-bottom: 20px;
        }
        
        .card-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
            padding: 15px 20px;
        }
        
        .btn-primary {
            background: var(--primary-color);
            border: none;
            padding: 8px 20px;
            border-radius: 6px;
            transition: var(--transition);
        }
        
        .btn-primary:hover {
            background: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(67, 97, 238, 0.3);
        }
        
        .payment-status {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 600;
        }
        
        .status-paid {
            background: #d4edda;
            color: #155724;
        }
        
        .status-pending {
            background: #fff3cd;
            color: #856404;
        }
        
        .status-failed {
            background: #f8d7da;
            color: #721c24;
        }
        
        .invoice-card {
            border-left: 4px solid var(--primary-color);
            transition: var(--transition);
            cursor: pointer;
        }
        
        .invoice-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 15px rgba(0,0,0,0.1);
        }
        
        .invoice-card.selected {
            border-left-color: #4cc9f0;
            background: #f0f8ff;
        }
        
        .payment-method {
            display: inline-flex;
            align-items: center;
            padding: 4px 10px;
            background: #e9ecef;
            border-radius: 4px;
            font-size: 0.8rem;
        }
        
        .payment-method i {
            margin-right: 5px;
        }
        
        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(67, 97, 238, 0.25);
        }
        
        .stats-card {
            text-align: center;
            padding: 20px;
            border-radius: var(--border-radius);
            color: white;
            margin-bottom: 20px;
        }
        
        .stats-card.total {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .stats-card.paid {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
        }
        
        .stats-card.pending {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        }
        
        .stats-card h3 {
            font-size: 2rem;
            margin-bottom: 0;
            font-weight: 600;
        }
        
        .stats-card p {
            margin-bottom: 0;
            opacity: 0.9;
        }
        
        .modal-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
        }
        
        .badge-invoice {
            background: var(--primary-color);
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 0.8rem;
        }
        
        @media (max-width: 768px) {
            .stats-card {
                margin-bottom: 15px;
            }
            
            .card-body {
                padding: 15px;
            }
        }
    </style>
</head>
<body>

<?php include "../include/nav.php";?>

    <!-- Main Content Area -->
    <div id="main-content" class="content">
        <div class="container-fluid">
            <!-- Page Header -->
            <div class="row mb-4">
                <div class="col-12">
                    <h1 class="h3 mb-0"><i class="fa fa-credit-card me-2"></i>Student Association Payments</h1>
                    <p class="text-muted">Manage student association fee payments</p>
                </div>
            </div>

            <!-- Statistics Cards -->
            <div class="row mb-4">
                <div class="col-md-4">
                    <div class="stats-card total">
                        <i class="fa fa-money fa-3x mb-3"></i>
                        <h3>
                            <?php
                            $totalQuery = "SELECT SUM(amount) as total FROM association_payment WHERE status = 'paid'";
                            $totalResult = mysqli_query($conn, $totalQuery);
                            $totalData = mysqli_fetch_assoc($totalResult);
                            echo 'K ' . number_format($totalData['total'] ?? 0, 2);
                            ?>
                        </h3>
                        <p>Total Collected</p>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="stats-card paid">
                        <i class="fa fa-check-circle fa-3x mb-3"></i>
                        <h3>
                            <?php
                            $paidQuery = "SELECT COUNT(*) as total FROM association_payment WHERE status = 'paid'";
                            $paidResult = mysqli_query($conn, $paidQuery);
                            $paidData = mysqli_fetch_assoc($paidResult);
                            echo number_format($paidData['total'] ?? 0);
                            ?>
                        </h3>
                        <p>Paid Invoices</p>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="stats-card pending">
                        <i class="fa fa-clock-o fa-3x mb-3"></i>
                        <h3>
                            <?php
                            $pendingQuery = "SELECT COUNT(*) as total FROM association_payment WHERE status = 'pending'";
                            $pendingResult = mysqli_query($conn, $pendingQuery);
                            $pendingData = mysqli_fetch_assoc($pendingResult);
                            echo number_format($pendingData['total'] ?? 0);
                            ?>
                        </h3>
                        <p>Pending Payments</p>
                    </div>
                </div>
            </div>

            <!-- Messages -->
            <?php if ($successMessage): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fa fa-check-circle me-2"></i> <?php echo $successMessage; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
            <?php endif; ?>
            
            <?php if ($errorMessage): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fa fa-exclamation-circle me-2"></i> <?php echo $errorMessage; ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
            <?php endif; ?>

            <div class="row">
            




                <!-- Payments List -->
                <div class="col">
                    <div class="card">
                        <div class="card-header d-flex justify-content-between align-items-center">
                            <h5 class="mb-0"><i class="fa fa-list me-2"></i>Recent Payments</h5>
                            <button class="btn btn-sm btn-light"  class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModalPAY">
                                <i class="fa fa-refresh"></i> New Payment
                            </button>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover" id="paymentsTable">
                                    <thead>
                                        <tr>
                                            <th>Student ID</th>
                                            <th>Invoice</th>
                                            <th>Amount</th>
                                            <th>Method</th>
                                            <th>Status</th>
                                            <th>Date</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php while($payment = mysqli_fetch_assoc($paymentResult)): 
                                            $statusClass = '';
                                            switch($payment['status']) {
                                                case 'Paid': $statusClass = 'status-paid'; break;
                                                case 'pending': $statusClass = 'status-pending'; break;
                                                case 'failed': $statusClass = 'status-failed'; break;
                                            }
                                        ?>
                                        <tr>
                                            <td>
                                                <strong><?php echo htmlspecialchars($payment['studentid']); ?></strong>
                                                <?php if($payment['intake']): ?>
                                                <br><small class="text-muted"><?php echo htmlspecialchars($payment['intake']); ?></small>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <?php echo htmlspecialchars($payment['description'] ?? 'N/A'); ?>
                                                <br><small class="text-muted"><?php echo $payment['year'] . ' S' . $payment['semester']; ?></small>
                                            </td>
                                            <td>
                                                <strong>K <?php echo number_format($payment['amount'], 2); ?></strong>
                                            </td>
                                            <td>
                                                <span class="payment-method">
                                                    <i class="fa fa-<?php 
                                                        switch($payment['payment_method']) {
                                                            case 'mpesa': echo 'mobile'; break;
                                                            case 'cash': echo 'money'; break;
                                                            case 'card': echo 'credit-card'; break;
                                                            default: echo 'university';
                                                        }
                                                    ?>"></i>
                                                    <?php echo ucfirst($payment['payment_method']); ?>
                                                </span>
                                            </td>
                                            <td>
                                                <span class="payment-status <?php echo $statusClass; ?>">
                                                    <?php echo ucfirst($payment['status']); ?>
                                                </span>
                                            </td>
                                            <td>
                                                <?php echo date('d/m/Y', strtotime($payment['payment_date'])); ?>
                                                <br><small class="text-muted"><?php echo date('h:i A', strtotime($payment['payment_date'])); ?></small>
                                            </td>
                                            <td>
                                                <button class="btn btn-sm btn-outline-primary" 
                                                        onclick="viewPayment(<?php echo $payment['id']; ?>)"
                                                        data-bs-toggle="tooltip" title="View Details">
                                                    <i class="fa fa-eye"></i>
                                                </button>
                                                <button class="btn btn-sm btn-outline-success" 
                                                        onclick="editPayment(<?php echo $payment['id']; ?>)"
                                                        data-bs-toggle="tooltip" title="Edit">
                                                    <i class="fa fa-edit"></i>
                                                </button>
                                                <button class="btn btn-sm btn-outline-danger" 
                                                        onclick="deletePayment(<?php echo $payment['id']; ?>)"
                                                        data-bs-toggle="tooltip" title="Delete">
                                                    <i class="fa fa-trash"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        <?php endwhile; ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- View Payment Modal -->
    <div class="modal fade" id="viewPaymentModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><i class="fa fa-credit-card me-2"></i>Payment Details</h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body" id="paymentDetails">
                    <!-- Details will be loaded here via AJAX -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="printReceipt()">
                        <i class="fa fa-print me-1"></i> Print Receipt
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- JavaScript Libraries -->
    <script src="https://code.jquery.com/jquery-3.7.0.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
    
    <script>
    $(document).ready(function() {
        // Initialize DataTable
        $('#paymentsTable').DataTable({
            "pageLength": 10,
            "order": [[5, 'desc']]
        });
        
        // Initialize tooltips
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl)
        });
        
        // Auto-fill form when invoice is selected
        $('#invoice_select').change(function() {
            var selectedOption = $(this).find('option:selected');
            var amount = selectedOption.data('amount');
            var year = selectedOption.data('year');
            var semester = selectedOption.data('semester');
            var studentType = selectedOption.data('type');
            
            if (amount) {
                $('#amount').val(amount);
            }
            if (year) {
                $('#year').val(year);
            }
            if (semester) {
                $('#semester').val(semester);
            }
            if (studentType) {
                $('#student_type').val(studentType);
            }
        });
    });
    
    // View payment details
    function viewPayment(paymentId) {
        $.ajax({
            url: 'get_payment_details.php',
            type: 'GET',
            data: { id: paymentId },
            success: function(response) {
                $('#paymentDetails').html(response);
                $('#viewPaymentModal').modal('show');
            },
            error: function() {
                alert('Error loading payment details');
            }
        });
    }
    
    // Edit payment
    function editPayment(paymentId) {
        // Redirect to edit page or show edit modal
        window.location.href = 'assopay.php?id=' + paymentId;
    }
    
   function deletePayment(paymentId) {
    if (confirm('Are you sure you want to delete this payment record?')) {
        $.ajax({
            url: 'delete_payment.php',
            type: 'POST',
            data: { id: paymentId },
            dataType: 'json', // ✅ IMPORTANT
            success: function(response) {
                if (response.success) {
                    alert(response.message);
                    location.reload();
                } else {
                    alert('Error deleting payment: ' + response.message);
                }
            },
            error: function(xhr) {
                console.error(xhr.responseText);
                alert('AJAX request failed');
            }
        });
    }
}

    
    // Print receipt
    function printReceipt() {
        var printContent = document.getElementById('paymentDetails').innerHTML;
        var originalContent = document.body.innerHTML;
        
        document.body.innerHTML = printContent;
        window.print();
        document.body.innerHTML = originalContent;
        location.reload();
    }
    
    // Search student function (you can implement this with AJAX)
    function searchStudent() {
        var studentId = $('#studentid').val();
        if (studentId.length > 2) {
            $.ajax({
                url: 'search_student.php',
                type: 'GET',
                data: { student_id: studentId },
                success: function(data) {
                    if (data.exists) {
                        $('#program').val(data.program);
                        $('#intake').val(data.intake);
                    }
                }
            });
        }
    }
    
    // Form validation
    function validateForm() {
        var amount = $('#amount').val();
        var studentId = $('#studentid').val();
        
        if (studentId.trim() === '') {
            alert('Please enter Student ID');
            return false;
        }
        
        if (amount <= 0) {
            alert('Please enter a valid amount');
            return false;
        }
        
        return true;
    }
    </script>
</body>
</html>



<!-- Button trigger modal -->



<div class="modal fade" id="exampleModalPAY" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="exampleModalLabel">
             <div class="card-header">
                            <h5 class="mb-0"><i class="fa fa-plus-circle me-2"></i>Record New Payment</h5>
                        </div>
        </h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
    <!-- Payment Form -->
                <div class="col">
                    <div class="card">
                       
                        <div class="card-body">
                            <form method="POST" action="">
    <div class="row">
        <div class="col-md-6 mb-3">
            <label class="form-label">Student ID</label>
            <input type="text" class="form-control" name="studentid" required 
                   placeholder="e.g., S001">
        </div>
        <div class="col-md-6 mb-3">
            <label class="form-label">Invoice</label>
            <select class="form-control" name="invoice_id" id="invoice_select" required>
                <option value="">Select Invoice</option>
                <?php 
                // Reset pointer before looping
                mysqli_data_seek($invoiceResult, 0);
                while($invoice = mysqli_fetch_assoc($invoiceResult)): ?>
                <option value="<?php echo $invoice['id']; ?>" 
                        data-amount="<?php echo $invoice['amount']; ?>"
                        data-year="<?php echo $invoice['year']; ?>"
                        data-semester="<?php echo $invoice['semester']; ?>"
                        data-type="<?php echo $invoice['student_type']; ?>">
                    <?php echo $invoice['description'] . ' - K ' . number_format($invoice['amount'], 2) . 
                           ' (' . $invoice['year'] . ' S' . $invoice['semester'] . ')'; ?>
                </option>
                <?php endwhile; ?>
            </select>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6 mb-3">
            <label class="form-label">Amount (K)</label>
            <input type="number" class="form-control" name="amount" id="amount" 
                   step="0.01" required placeholder="0.00">
        </div>
        <div class="col-md-6 mb-3">
            <label class="form-label">Payment Method</label>
            <select class="form-control" name="payment_method" required>
                <option value="">Select Method</option>
                <option value="cash">Cash</option>
                <option value="bank">Bank</option>
            </select>
        </div>
    </div>

    <div class="row" hidden>
        <div class="col-md-6 mb-3">
            <label class="form-label">Phone Number</label>
            <input type="text" class="form-control" name="phone" value="0000">
        </div>
        <div class="col-md-6 mb-3">
            <label class="form-label">Payment Status</label>
            <select class="form-control" name="status" required>
                <option value="Paid">Paid</option>
            </select>
        </div>
    </div>
<?php
// Fetch intakes from intake table
$intakeQuery = "SELECT * FROM intake ORDER BY intake DESC";
$intakeResult = mysqli_query($conn, $intakeQuery);

// Fetch programs from programs table
$programQuery = "SELECT * FROM programs ORDER BY program"; 
$programResult = mysqli_query($conn, $programQuery);

// Fetch years from year table
$yearQuery = "SELECT * FROM year ORDER BY year DESC";
$yearResult = mysqli_query($conn, $yearQuery);

// Fetch invoices (from your original code)
$invoiceQuery = "SELECT * FROM association_invoice ORDER BY year DESC, semester DESC";
$invoiceResult = mysqli_query($conn, $invoiceQuery);
?>
    <div class="row">
        <div class="col-md-4 mb-3">
            <label class="form-label">Year</label>
            <select class="form-control" name="year" id="year" required>
                <option value="">Select Year</option>
                <?php 
                while($year = mysqli_fetch_assoc($yearResult)): ?>
                <option value="<?php echo $year['year']; ?>">
                    <?php echo $year['year']; ?>
                </option>
                <?php endwhile; ?>
            </select>
        </div>
        <div class="col-md-4 mb-3">
            <label class="form-label">Semester</label>
            <select class="form-control" name="semester" id="semester" required>
                <option value="">Select Semester</option>
                <option value="1">Semester 1</option>
                <option value="2">Semester 2</option>
            </select>
        </div>
        <div class="col-md-4 mb-3">
            <label class="form-label">Intake</label>
            <select class="form-control" name="intake" id="intake" required>
                <option value="">Select Intake</option>
                <?php 
                while($intake = mysqli_fetch_assoc($intakeResult)): ?>
                <option value="<?php echo $intake['intake']; ?>">
                    <?php echo $intake['intake']; ?>
                </option>
                <?php endwhile; ?>
            </select>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6 mb-3">
            <label class="form-label">Program</label>
            <select class="form-control" name="program" id="program" required>
                <option value="">Select Program</option>
                <?php 
                while($program = mysqli_fetch_assoc($programResult)): ?>
                <option value="<?php echo $program['program']; ?>">
                    <?php echo $program['program']; ?>
                </option>
                <?php endwhile; ?>
            </select>
        </div>
        <div class="col-md-6 mb-3">
            <label class="form-label">Student Type</label>
            <input type="text" class="form-control" name="student_type" id="student_type" readonly>
        </div>
    </div>

    <div class="d-grid">
        <button type="submit" name="add_payment" class="btn btn-primary btn-lg">
            <i class="fa fa-save me-2"></i>Record Payment
        </button>
    </div>
</form>

<script>
$(document).ready(function() {
    // Auto-fill form when invoice is selected
    $('#invoice_select').change(function() {
        var selectedOption = $(this).find('option:selected');
        var amount = selectedOption.data('amount');
        var year = selectedOption.data('year');
        var semester = selectedOption.data('semester');
        var studentType = selectedOption.data('type');
        
        if (amount) {
            $('#amount').val(amount);
        }
        if (year) {
            $('#year').val(year);
        }
        if (semester) {
            $('#semester').val(semester);
        }
        if (studentType) {
            $('#student_type').val(studentType);
        }
    });
});
</script>
                        </div>
                    </div>
                </div>
      </div>
      
    </div>
  </div>
</div>