File "detalleEquipo.php"

Full Path: C:/wamp64/www/RegistroEquipos2/backend/detalleEquipo.php
File size: 1.84 KB
MIME-type: text/x-php
Charset: utf-8

<?php
require __DIR__ . '/../bd/conexion.php';
header('Content-Type: application/json; charset=utf-8');

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$cedula = $_GET['cedula'] ?? '';

if (!$id || !$cedula) {
    echo json_encode(['error' => 'Faltan parámetros id/cedula']);
    exit;
}

try {
    // 🔍 Primero buscar en registrocomputers
    $sql = "SELECT id, marca, referencia, tipo, serial, ram, tipoDD, procesador,
                   fecha,areaTrabajo, nombreRecibe AS nombre, cedula, observaciones,estado,regional,telefono,cargo,windows,idproducto,office,usuario1,contrasena,software,red,
                   'Computer' AS origen
            FROM registrocomputers
            WHERE id = ? AND cedula = ?";
    $stmt = $conexion->prepare($sql);
    $stmt->bind_param("is", $id, $cedula);
    $stmt->execute();
    $res = $stmt->get_result();

    if ($res->num_rows > 0) {
        $row = $res->fetch_assoc();
        echo json_encode(['datos' => $row], JSON_UNESCAPED_UNICODE);
        exit;
    }

    // 🔍 Si no está en computers, buscar en smartphones
    $sql = "SELECT id, marca, referencia, color, imei, numeroLinea,
               fecha ,planDatos, nombreRecibe AS nombre, cedula, observaciones,estado,
               'Smartphone' AS origen
        FROM registrosmartphones
        WHERE id = ? AND cedula = ?";
    $stmt = $conexion->prepare($sql);
    $stmt->bind_param("is", $id, $cedula);
    $stmt->execute();
    $res = $stmt->get_result();

    if ($res->num_rows > 0) {
        $row = $res->fetch_assoc();
        echo json_encode(['datos' => $row], JSON_UNESCAPED_UNICODE);
        exit;
    }


    // ❌ Si no se encontró en ninguna tabla
    echo json_encode(['error' => 'No se encontró el equipo.']);

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