<?php
require_once 'config/database.php';

// Check if student has any fees records
$stmt = $pdo->prepare("SELECT * FROM fees WHERE student_id = 5642 LIMIT 1");
$stmt->execute();
$fees = $stmt->fetchAll();

if (empty($fees)) {
    echo "No fees records found for student ID 5642\n";
    
    // Let's create a sample fee record for testing
    // Check if fee already exists for this student and fee type
    $check_stmt = $pdo->prepare(
        "SELECT id FROM fees WHERE student_id = ? AND fee_type = ? AND status != 'cancelled' LIMIT 1"
    );
    $check_stmt->execute([5642, 'Monthly Fee']);
    $existing_fee = $check_stmt->fetch();
        
    if (!$existing_fee) {
        $stmt = $pdo->prepare(
            "INSERT INTO fees (student_id, fee_type, amount, due_date, status) 
            VALUES (?, 'Monthly Fee', 500.00, CURDATE(), 'pending')"
        );
        $stmt->execute([5642]);
        echo "Created a sample fee record for testing\n";
    } else {
        echo "Fee record already exists for student ID 5642 with type 'Monthly Fee'\n";
    }
} else {
    echo "Found " . count($fees) . " fees records for student ID 5642\n";
    print_r($fees[0]);
}
?>