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

echo "Fixing fee_payments table structure...\n";

try {
    // First, let's see what columns we have
    $stmt = $pdo->query('DESCRIBE fee_payments');
    $columns = $stmt->fetchAll();
    
    echo "Current columns:\n";
    foreach ($columns as $column) {
        echo "- " . $column['Field'] . " (" . $column['Type'] . ")\n";
    }
    
    // Modify the payment_date column to be DATE instead of DATETIME
    $pdo->exec("ALTER TABLE fee_payments MODIFY COLUMN payment_date DATE NOT NULL");
    
    // Modify the payment_method column to be ENUM type
    $pdo->exec("ALTER TABLE fee_payments MODIFY COLUMN payment_method ENUM('cash', 'bank', 'online', 'cheque') DEFAULT 'cash'");
    
    echo "\nTable structure fixed successfully.\n";
    
    // Check the updated structure
    $stmt = $pdo->query('DESCRIBE fee_payments');
    $columns = $stmt->fetchAll();
    
    echo "\nUpdated columns:\n";
    foreach ($columns as $column) {
        echo "- " . $column['Field'] . " (" . $column['Type'] . ")\n";
    }
    
} catch (PDOException $e) {
    echo "Error updating database: " . $e->getMessage() . "\n";
}
?>