<?php
include 'includes/db.php';

try {
    // Check if column exists
    $stmt = $pdo->query("SHOW COLUMNS FROM gastos LIKE 'numero_factura'");
    if ($stmt->fetch()) {
        echo "Column 'numero_factura' already exists.";
    } else {
        $pdo->exec("ALTER TABLE gastos ADD COLUMN numero_factura VARCHAR(50) DEFAULT NULL AFTER categoria");
        echo "Column 'numero_factura' added successfully.";
    }
} catch (PDOException $e) {
    echo "Error updating table: " . $e->getMessage();
}
?>