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

echo "<h2>ডাটাবেস চেক</h2>";

try {
    // Check if fee_payments table exists
    $result = $pdo->query("SHOW TABLES LIKE 'fee_payments'");
    if ($result->rowCount() > 0) {
        echo "<p>✅ fee_payments টেবিল আছে</p>";
        
        // Check table structure
        $columns = $pdo->query("DESCRIBE fee_payments")->fetchAll();
        echo "<h3>টেবিল স্ট্রাকচার:</h3>";
        echo "<table border='1' style='border-collapse: collapse;'>";
        echo "<tr><th>Column</th><th>Type</th><th>Null</th><th>Key</th><th>Default</th></tr>";
        foreach ($columns as $col) {
            echo "<tr>";
            echo "<td>" . $col['Field'] . "</td>";
            echo "<td>" . $col['Type'] . "</td>";
            echo "<td>" . $col['Null'] . "</td>";
            echo "<td>" . $col['Key'] . "</td>";
            echo "<td>" . $col['Default'] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
        
        // Check data count
        $count = $pdo->query("SELECT COUNT(*) FROM fee_payments")->fetchColumn();
        echo "<p>রেকর্ড সংখ্যা: $count</p>";
        
    } else {
        echo "<p>❌ fee_payments টেবিল নেই</p>";
        echo "<p><a href='setup_invoice_system.php'>সেটআপ করুন</a></p>";
    }
    
    // Check fees table
    $fees_count = $pdo->query("SELECT COUNT(*) FROM fees")->fetchColumn();
    echo "<p>fees টেবিলে রেকর্ড: $fees_count</p>";
    
    // Check students table
    $students_count = $pdo->query("SELECT COUNT(*) FROM students")->fetchColumn();
    echo "<p>students টেবিলে রেকর্ড: $students_count</p>";
    
} catch (Exception $e) {
    echo "<p style='color: red;'>ত্রুটি: " . $e->getMessage() . "</p>";
}
?>