<?
header('Content-Type: application/json');
$r="../../";
require_once($r."inc/funciones.php");
$mysqli = connectDB($r);
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $id = isset($_POST['id']) ? trim($_POST['id']) : '';
   
    $sql = "SELECT c.*, b.barrio AS barrio, l.localidad AS localidad FROM z_clientes c LEFT JOIN z_barrios b ON c.barrio = b.id LEFT JOIN z_localidades l ON c.localidad = l.id WHERE c.id = ? LIMIT 1";
    $stmt = $mysqli->prepare($sql);
    $stmt->bind_param("s", $id);
   

    $stmt->execute();
    $result = $stmt->get_result();

    if ($row = $result->fetch_assoc()) {
        echo json_encode([
            "status" => "success",
            "cotizacion" => $row
        ]);
    } else {
        echo json_encode([
            "status" => "not_found",
            "message" => "No se encontraron cotizaciones"
        ]);
    }

    $stmt->close();
    $mysqli->close();

} else {
    echo json_encode([
        "status" => "error",
        "message" => "Método no permitido"
    ]);
}