<?php
session_start();
header('Content-Type: application/json');
include("../conex.php");

$id_usuario = $_SESSION['idusuario'] ?? 0;

$sql = "
    SELECT DISTINCT d.iddatadai, d.id_estado, d.marca, d.modelo, d.chasis, d.motor, d.color
    FROM tb_datadai AS d
    INNER JOIN tb_solicitudprevia AS sp ON sp.idsolicitudprevia = d.id_solicitudprevia
    WHERE 
    d.condicion = 1 
    AND sp.condicion = 1
    AND d.dai = 'Simple'
    AND d.id_estado > 1 AND d.id_estado < 22
    and d.id_bodega = 3
";

$result = mysqli_query($conn, $sql);

$data = [];
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = [        
        'marca'   => $row['marca'],
        'modelo'  => $row['modelo'],
        'chasis'  => $row['chasis'],
        'motor'   => $row['motor'],
        'color'   => $row['color']
    ];
}

echo json_encode(['data' => $data]);
