<?php
// Test database structure for fee selection system
require_once 'config/database.php';

echo "Fee Selection System Database Test\n";
echo "=================================\n";

try {
    // Test if fees table exists
    $stmt = $pdo->prepare("SHOW TABLES LIKE 'fees'");
    $stmt->execute();
    $result = $stmt->fetchAll();
    
    if (count($result) > 0) {
        echo "✓ fees table exists\n";
    } else {
        echo "✗ fees table NOT FOUND\n";
    }
    
    // Test if fee_payments table exists
    $stmt = $pdo->prepare("SHOW TABLES LIKE 'fee_payments'");
    $stmt->execute();
    $result = $stmt->fetchAll();
    
    if (count($result) > 0) {
        echo "✓ fee_payments table exists\n";
    } else {
        echo "✗ fee_payments table NOT FOUND\n";
    }
    
    // Test fees table structure
    $stmt = $pdo->prepare("DESCRIBE fees");
    $stmt->execute();
    $columns = $stmt->fetchAll();
    
    $required_columns = ['id', 'student_id', 'fee_type', 'amount', 'due_date', 'paid_amount'];
    $found_columns = [];
    
    foreach ($columns as $column) {
        $found_columns[] = $column['Field'];
    }
    
    foreach ($required_columns as $required) {
        if (in_array($required, $found_columns)) {
            echo "✓ fees table has column: $required\n";
        } else {
            echo "✗ fees table missing column: $required\n";
        }
    }
    
    // Test fee_payments table structure
    $stmt = $pdo->prepare("DESCRIBE fee_payments");
    $stmt->execute();
    $columns = $stmt->fetchAll();
    
    $required_columns = ['id', 'fee_id', 'amount', 'payment_date', 'payment_method', 'transaction_id'];
    $found_columns = [];
    
    foreach ($columns as $column) {
        $found_columns[] = $column['Field'];
    }
    
    foreach ($required_columns as $required) {
        if (in_array($required, $found_columns)) {
            echo "✓ fee_payments table has column: $required\n";
        } else {
            echo "✗ fee_payments table missing column: $required\n";
        }
    }
    
    echo "\nDatabase test completed successfully!\n";
    
} catch (Exception $e) {
    echo "Database test failed: " . $e->getMessage() . "\n";
}
?>