<?php
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../includes/helpers.php';

require_post();
$data = json_input();
require_fields($data, ['id']);

$pdo = getConnection();

try {
    $id = (int)$data['id'];
    $stmt = $pdo->prepare("DELETE FROM gastos_operativos WHERE id = ?");
    $stmt->execute([$id]);

    if ($stmt->rowCount() === 0) {
        json_error("Gasto no encontrado");
    } else {
        json_success([], 'Gasto eliminado');
    }
} catch (Exception $e) {
    json_error("Error al eliminar: " . $e->getMessage());
}
