146 lines
6.3 KiB
PHP
146 lines
6.3 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
require_once 'db/config.php';
|
|
require_once 'layout_header.php';
|
|
|
|
$codigo_unico_buscado = isset($_GET['codigo_unico']) ? trim($_GET['codigo_unico']) : '';
|
|
$unidad_info = null;
|
|
$error_message = '';
|
|
|
|
if (!empty($codigo_unico_buscado)) {
|
|
try {
|
|
$db = db();
|
|
$stmt = $db->prepare(
|
|
"\n SELECT
|
|
ui.codigo_unico,
|
|
ui.estado,
|
|
ui.fecha_creacion,
|
|
ui.fecha_ingreso,
|
|
ui.fecha_salida,
|
|
ui.pedido_id,
|
|
p.nombre AS producto_nombre,
|
|
p.sku AS producto_sku
|
|
FROM unidades_inventario ui
|
|
JOIN products p ON ui.producto_id = p.id
|
|
WHERE ui.codigo_unico = :codigo_unico
|
|
");
|
|
$stmt->bindParam(':codigo_unico', $codigo_unico_buscado, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
$unidad_info = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$unidad_info) {
|
|
$error_message = "No se encontró ninguna unidad de inventario con el código \"" . htmlspecialchars($codigo_unico_buscado) . "\".";
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error_message = "Error en la base de datos: " . $e->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container mt-4">
|
|
<h1 class="mb-4">Buscador de Unidades de Inventario</h1>
|
|
<p>Ingresa o escanea el código de barras de una unidad individual para ver su historial y estado actual.</p>
|
|
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<form action="buscador_inventario.php" method="GET" class="mb-3">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control form-control-lg" id="codigo_unico" name="codigo_unico" placeholder="Ej: AFS-0035" value="<?php echo htmlspecialchars($codigo_unico_buscado); ?>" required autofocus>
|
|
<button class="btn btn-primary" type="submit">
|
|
<i class="fas fa-search"></i> Buscar
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-warning">
|
|
<?php echo $error_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($unidad_info): ?>
|
|
<div class="card shadow-sm">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">Resultados para: <?php echo htmlspecialchars($unidad_info['codigo_unico']); ?></h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h4>Información del Producto</h4>
|
|
<table class="table table-bordered">
|
|
<tr>
|
|
<th style="width: 30%;">Nombre</th>
|
|
<td><?php echo htmlspecialchars($unidad_info['producto_nombre']); ?></td>
|
|
</tr>
|
|
<tr>
|
|
<th>SKU</th>
|
|
<td><?php echo htmlspecialchars($unidad_info['producto_sku']); ?></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h4>Trazabilidad de la Unidad</h4>
|
|
<table class="table table-bordered">
|
|
<tr>
|
|
<th style="width: 30%;">Estado Actual</th>
|
|
<td>
|
|
<?php
|
|
$estado = htmlspecialchars($unidad_info['estado']);
|
|
$badge_class = 'secondary';
|
|
if ($estado == 'En Almacén') $badge_class = 'success';
|
|
if ($estado == 'Vendido') $badge_class = 'danger';
|
|
if ($estado == 'Generado') $badge_class = 'info';
|
|
echo "<span class=\"badge bg-$badge_class\">$estado</span>";
|
|
?>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th>Pedido ID</th>
|
|
<td>
|
|
<?php if ($unidad_info['pedido_id']): ?>
|
|
<a href="info_producto.php?id=<?php echo $unidad_info['pedido_id']; // Asumiendo que esta es la página de detalle de pedido ?>">
|
|
<?php echo $unidad_info['pedido_id']; ?>
|
|
</a>
|
|
<?php else: ?>
|
|
N/A
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<h4>Historial de Fechas</h4>
|
|
<table class="table table-sm table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>Creación (Etiqueta)</th>
|
|
<th>Ingreso a Almacén</th>
|
|
<th>Salida (Venta)</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><?php echo $unidad_info['fecha_creacion'] ? date('d/m/Y H:i:s', strtotime($unidad_info['fecha_creacion'])) : 'N/A'; ?></td>
|
|
<td><?php echo $unidad_info['fecha_ingreso'] ? date('d/m/Y H:i:s', strtotime($unidad_info['fecha_ingreso'])) : 'N/A'; ?></td>
|
|
<td><?php echo $unidad_info['fecha_salida'] ? date('d/m/Y H:i:s', strtotime($unidad_info['fecha_salida'])) : 'N/A'; ?></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<?php require_once 'layout_footer.php'; ?>
|