192 lines
7.4 KiB
PHP
192 lines
7.4 KiB
PHP
<?php require __DIR__ . '/../../includes/navBar.php'; ?>
|
|
|
|
<div class="container my-5">
|
|
|
|
<div class="card card-rounded card-shadow border-0">
|
|
|
|
<!-- HEADER -->
|
|
|
|
<div class="card-header header-dark px-4 py-3">
|
|
|
|
<div class="d-flex justify-content-between align-items-center flex-wrap gap-3">
|
|
|
|
<h4 class="mb-0 title-shadow">
|
|
<i class="fas fa-box-open icon-xl me-2"></i>
|
|
Selección de Productos
|
|
</h4>
|
|
|
|
<div class="d-flex gap-2">
|
|
|
|
<!-- BOTÓN FANTASMA (mantiene el layout) -->
|
|
|
|
<a href="?opt=crear_producto" class="btn btn-success">
|
|
<i class="fas fa-plus me-1"></i>
|
|
Nuevo Producto
|
|
</a>
|
|
|
|
<a href="?opt=crear_pedido" class="btn btn-soft-secondary text-white">
|
|
<i class="fas fa-arrow-left me-1"></i>
|
|
Volver
|
|
</a>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- BODY -->
|
|
|
|
<div class="card-body px-4 py-4">
|
|
|
|
<?php if (empty($productos)): ?>
|
|
<div class="text-center text-muted py-5">
|
|
No hay productos registrados.
|
|
</div>
|
|
<?php else: ?>
|
|
|
|
<!-- FILTRO POR COLUMNA + BUSCADOR -->
|
|
|
|
<!-- Input de búsqueda añadido automáticamente por DataTables -->
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
|
|
<div id="filtrosIzquierda" class="d-flex align-items-center gap-2">
|
|
|
|
<select id="columnFilter"
|
|
class="form-select form-select-sm"
|
|
style="width:auto;">
|
|
<option value="">Todas las columnas</option>
|
|
<option value="0">ID</option>
|
|
<option value="1">Productos</option>
|
|
<option value="5">Stock Actual</option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<form method="POST" action="index.php?opt=agregar_producto_pedido_caja" novalidate>
|
|
|
|
<!-- CAMPO OCULTO (para verificación de token) -->
|
|
|
|
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
|
|
|
<div class="table-responsive">
|
|
<table id="tablaProductos" class="table table-hover align-middle mb-0">
|
|
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Productos</th>
|
|
<th>Costo Unit.</th>
|
|
<th>Cantidad</th>
|
|
<th>Stock Actual</th>
|
|
<th>Seleccionar</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<?php foreach ($productos as $p): ?>
|
|
<tr>
|
|
|
|
<!-- ID PRODUCTO -->
|
|
|
|
<td><?= $p['id'] ?></td>
|
|
|
|
<!-- MARCA Y MODELO -->
|
|
|
|
<td><?= htmlspecialchars($p['marca'] . ' ' . $p['modelo']) ?></td>
|
|
|
|
<!-- INPUT DE COSTO -->
|
|
|
|
<td class="text-center">
|
|
<div class="input-group input-group-sm input-precio" style="width: 150px;">
|
|
<span class="input-group-text">$</span>
|
|
<input
|
|
type="number"
|
|
name="costos[<?= $p['id'] ?>]"
|
|
value="0.00"
|
|
min="5"
|
|
step="0.01"
|
|
class="form-control text-append"
|
|
>
|
|
</div>
|
|
</td>
|
|
|
|
<!-- INPUT DE CANTIDAD -->
|
|
|
|
<td class="text-center">
|
|
<input type="number"
|
|
name="cantidades[<?= $p['id'] ?>]"
|
|
value="1"
|
|
min="1"
|
|
class="form-control form-control-sm"
|
|
style="width: 60px;">
|
|
</td>
|
|
|
|
<!-- STOCK ACTUAL -->
|
|
|
|
<td><?= htmlspecialchars($p['stock']) ?></td>
|
|
|
|
<!-- CHECKBOX PARA SELECCIONAR PRODUCTO -->
|
|
|
|
<td class="text-left">
|
|
<input type="checkbox"
|
|
name="ids[]"
|
|
value="<?= $p['id'] ?>"
|
|
class="form-check-input">
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- BOTÓN FINALIZAR SELECCIÓN -->
|
|
|
|
<div class="mt-3 text-end">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-check me-1"></i> Finalizar Selección
|
|
</button>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
|
|
<!-- Errores provenientes de pedidoController -->
|
|
|
|
<!-- ERROR -->
|
|
|
|
<script>
|
|
const serverErrors = <?php
|
|
if (!empty($_SESSION['flash_error'])) {
|
|
$errorsArray = explode('<br>', $_SESSION['flash_error']);
|
|
unset($_SESSION['flash_error']);
|
|
echo json_encode($errorsArray);
|
|
} else {
|
|
echo '[]';
|
|
}
|
|
?>;
|
|
</script>
|
|
|
|
<!-- SUCCES -->
|
|
|
|
<script>
|
|
const serverSuccess = <?php
|
|
if (!empty($_SESSION['flash_success'])) {
|
|
$successArray = explode('<br>', $_SESSION['flash_success']);
|
|
unset($_SESSION['flash_success']);
|
|
echo json_encode($successArray);
|
|
} else {
|
|
echo '[]';
|
|
}
|
|
?>;
|
|
</script>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Validar mediante js -->
|
|
|
|
<script src="js/pedidos/pedidoValidator.js"></script>
|
|
|
|
<!-- Tabla, búsqueda y filtro por columnas -->
|
|
|
|
<script src="js/pedidos/pedidoTableProducto.js"></script>
|