<?php
/**
 * SAC 2026 - COMMISSIONS REPORT ENGINE v1.0
 */
require_once 'config.php';

if (!isset($_SESSION['user_id'])) response(["error" => "No autorizado"], 401);

$month = isset($_GET['month']) ? (int)$_GET['month'] : null;
$year = isset($_GET['year']) ? (int)$_GET['year'] : null;

try {
    $stmt = $pdo->prepare("SELECT id, date, description, amount_usd as amount, amount_bs as amountBs, reference, category 
                          FROM bank_transactions 
                          WHERE category = 'Comisiones' 
                          AND MONTH(date) = ? 
                          AND YEAR(date) = ? 
                          ORDER BY date ASC");
    $stmt->execute([$month + 1, $year]);
    response($stmt->fetchAll());
} catch (PDOException $e) {
    response(["error" => $e->getMessage()], 500);
}
?>