105 lines
4.5 KiB
PHP
105 lines
4.5 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch users
|
|
$stmt_usuarios = $pdo->query('SELECT id, nombre FROM usuarios ORDER BY nombre');
|
|
$usuarios = $stmt_usuarios->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch cities
|
|
$stmt_ciudades = $pdo->query('SELECT id, nombre FROM ciudades ORDER BY nombre');
|
|
$ciudades = $stmt_ciudades->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch confirmations
|
|
$sql = "
|
|
SELECT
|
|
sc.fecha_hora,
|
|
sc.fecha_actualizacion,
|
|
u.nombre AS usuario_nombre,
|
|
GROUP_CONCAT(c.nombre SEPARATOR ', ') AS ciudades
|
|
FROM stock_confirmaciones sc
|
|
JOIN usuarios u ON sc.usuario_id = u.id
|
|
LEFT JOIN stock_confirmacion_ciudades scc ON sc.id = scc.confirmacion_id
|
|
LEFT JOIN ciudades c ON scc.ciudad_id = c.id
|
|
GROUP BY sc.id
|
|
ORDER BY sc.fecha_actualizacion DESC, sc.fecha_hora DESC
|
|
";
|
|
$stmt_confirmaciones = $pdo->prepare($sql);
|
|
$stmt_confirmaciones->execute();
|
|
$confirmaciones = $stmt_confirmaciones->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="container mt-4">
|
|
<h1>Reporte de Entregas</h1>
|
|
<p>Seleccione su usuario, la fecha de entrega, las ciudades y presione confirmar para registrar la entrega.</p>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Registrar Entrega</h5>
|
|
<form action="handle_confirmacion_stock.php" method="POST">
|
|
<div class="form-group">
|
|
<label for="usuario_id">Usuario</label>
|
|
<select class="form-control" id="usuario_id" name="usuario_id" required>
|
|
<option value="">Seleccione un usuario</option>
|
|
<?php foreach ($usuarios as $usuario) : ?>
|
|
<option value="<?php echo htmlspecialchars($usuario['id']); ?>"><?php echo htmlspecialchars($usuario['nombre']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group mt-3">
|
|
<label for="fecha_actualizacion">Fecha de Entrega</label>
|
|
<input type="date" class="form-control" id="fecha_actualizacion" name="fecha_actualizacion" value="<?php echo date('Y-m-d'); ?>" required>
|
|
</div>
|
|
<div class="form-group mt-3">
|
|
<label for="ciudad_id">Ciudad</label>
|
|
<select class="form-control" id="ciudad_id" name="ciudad_id" required>
|
|
<option value="">Seleccione una ciudad</option>
|
|
<?php foreach ($ciudades as $ciudad) : ?>
|
|
<option value="<?php echo htmlspecialchars($ciudad['id']); ?>"><?php echo htmlspecialchars($ciudad['nombre']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary mt-3">Confirmar</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Historial de Entregas</h5>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Fecha de Entrega</th>
|
|
<th>Fecha y Hora de Registro</th>
|
|
<th>Usuario</th>
|
|
<th>Ciudades</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($confirmaciones)) : ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No hay entregas registradas.</td>
|
|
</tr>
|
|
<?php else : ?>
|
|
<?php foreach ($confirmaciones as $confirmacion) : ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($confirmacion['fecha_actualizacion'] ? date('d/m/Y', strtotime($confirmacion['fecha_actualizacion'])) : 'No especificada'); ?></td>
|
|
<td><?php echo htmlspecialchars(date('d/m/Y H:i:s', strtotime($confirmacion['fecha_hora']))); ?></td>
|
|
<td><?php echo htmlspecialchars($confirmacion['usuario_nombre']); ?></td>
|
|
<td><?php echo htmlspecialchars($confirmacion['ciudades'] ?? 'N/A'); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'includes/footer.php';
|
|
?>
|