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

try {
    
    // Check if tables exist
    $stmt = $pdo->query("SHOW TABLES LIKE '%expense%'");
    $tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
    
    echo "Existing expense-related tables:\n";
    foreach ($tables as $table) {
        echo "- " . $table . "\n";
    }
    
    // Check if expense_categories table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'expense_categories'");
    $exists = $stmt->fetch();
    
    if ($exists) {
        echo "\nexpense_categories table exists!\n";
        // Count records
        $stmt = $pdo->query("SELECT COUNT(*) as count FROM expense_categories");
        $count = $stmt->fetch();
        echo "Total categories: " . $count['count'] . "\n";
        
        // Show sample data
        $stmt = $pdo->query("SELECT * FROM expense_categories LIMIT 5");
        $categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
        echo "\nSample categories:\n";
        foreach ($categories as $cat) {
            echo "- " . $cat['name'] . " (" . $cat['status'] . ")\n";
        }
    } else {
        echo "\nexpense_categories table does NOT exist!\n";
    }
    
    // Check if expenses table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'expenses'");
    $exists = $stmt->fetch();
    
    if ($exists) {
        echo "\nexpenses table exists!\n";
        $stmt = $pdo->query("SELECT COUNT(*) as count FROM expenses");
        $count = $stmt->fetch();
        echo "Total expenses: " . $count['count'] . "\n";
    } else {
        echo "\nexpenses table does NOT exist!\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>