34849-vm/productos.php
2026-02-12 03:55:52 +00:00

133 lines
6.7 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';
// Fetch all products
$stmt = db()->query("SELECT * FROM products ORDER BY nombre ASC");
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="content-wrapper">
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1>Lista de Productos</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
<li class="breadcrumb-item active">Productos</li>
</ol>
</div>
</div>
</div>
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Todos los productos</h3>
<div class="card-tools">
<a href="edit_product.php" class="btn btn-primary">Nuevo Producto</a>
</div>
</div>
<div class="card-body">
<form action="imprimir_etiquetas.php" method="post" target="_blank">
<div class="mb-3">
<button type="submit" class="btn btn-success">Imprimir Etiquetas Seleccionadas</button>
</div>
<div class="table-responsive">
<table id="products-table" class="table table-bordered table-striped">
<thead>
<tr>
<th><input type="checkbox" id="select-all"></th>
<th>ID</th>
<th>Código de Barras</th>
<th>Nombre</th>
<th>SKU</th>
<th>Costo</th>
<th>Precio Venta</th>
<th>Unidades Vendidas</th>
<th>Ganancia/Unidad</th>
<th>Ingreso Total</th>
<th>Ganancia Total</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php foreach ($products as $product): ?>
<tr>
<td><input type="checkbox" name="product_ids[]" value="<?php echo $product['id']; ?>"></td>
<td><?php echo $product['id']; ?></td>
<td>
<?php if (!empty($product['id'])): ?>
<img src="https://barcode.tec-it.com/barcode.ashx?data=<?php echo $product['id']; ?>&code=Code128" alt="Barcode for product ID <?php echo $product['id']; ?>" style="max-height: 40px;">
<?php endif; ?>
</td>
<td><?php echo htmlspecialchars($product['nombre']); ?></td>
<td><?php echo htmlspecialchars($product['sku']); ?></td>
<td><?php echo htmlspecialchars($product['costo']); ?></td>
<td><?php echo htmlspecialchars($product['precio_venta']); ?></td>
<td><?php echo htmlspecialchars($product['unidades_vendidas']); ?></td>
<td><?php echo htmlspecialchars($product['ganancia_unidad']); ?></td>
<td><?php echo htmlspecialchars($product['ingreso_total']); ?></td>
<td><?php echo htmlspecialchars($product['ganancia_total']); ?></td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Acciones
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="edit_product.php?id=<?php echo $product['id']; ?>">Editar</a>
<a class="dropdown-item" href="delete_product.php?id=<?php echo $product['id']; ?>" onclick="return confirm('¿Estás seguro de que quieres eliminar este producto?');">Eliminar</a>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php require_once 'layout_footer.php'; ?>
<script>
document.getElementById('select-all').addEventListener('click', function(event) {
var checkboxes = document.getElementsByName('product_ids[]');
for (var checkbox of checkboxes) {
checkbox.checked = event.target.checked;
}
});
</script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap4.min.js"></script>
<script>
$(function () {
$("#products-table").DataTable({
"responsive": true,
"lengthChange": false,
"autoWidth": false,
});
});
</script>