<?php
include_once '../conexion.php';

header("Content-Type: application/json; charset=utf-8");

try {
    $sql = "SELECT * FROM informe_kardex(
        '(K.empresa_id = 1) AND (K.fecha_traslado < ''2025-03-21'') AND (K.sucursal_id = 1)',
        '(K.empresa_id = 1) AND (K.fecha_traslado >= ''2025-03-21'' AND K.fecha_traslado <= ''2025-03-29'') AND (K.sucursal_id = 1)',
        'PROMEDIO'
    )";
    
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($rows, JSON_UNESCAPED_UNICODE);

} catch (Exception $e) {
    echo json_encode(['error' => $e->getMessage()]);
    http_response_code(500);
}
?>
