35607-vm/products.php
Flatlogic Bot 9b5a06451f SInarKasih
2025-11-10 04:11:47 +00:00

71 lines
2.6 KiB
PHP

<?php
require_once __DIR__ . '/includes/auth.php';
require_login();
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/header.php';
$low_stock_threshold = 5;
$filter_low_stock = isset($_GET['filter_low_stock']);
$page_title = "Products";
$query = 'SELECT * FROM products ORDER BY created_at DESC';
if ($filter_low_stock) {
$page_title = "Low Stock Products (<= {$low_stock_threshold} items)";
$query = "SELECT * FROM products WHERE stock <= {$low_stock_threshold} ORDER BY stock ASC";
}
$stmt = db()->query($query);
$products = $stmt->fetchAll();
?>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2"><?php echo $page_title; ?></h1>
<div class="btn-toolbar mb-2 mb-md-0">
<a href="product_add.php" class="btn btn-sm btn-primary">
<i class="bi bi-plus-lg"></i>
Add New Product
</a>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>SKU</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Stock</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($products)): ?>
<tr>
<td colspan="6" class="text-center">No products found. <a href="product_add.php">Add one!</a></td>
</tr>
<?php else: ?>
<?php foreach ($products as $product): ?>
<tr>
<td><?php echo htmlspecialchars($product['sku']); ?></td>
<td><?php echo htmlspecialchars($product['name']); ?></td>
<td><?php echo htmlspecialchars($product['category']); ?></td>
<td>Rp <?php echo number_format($product['price'], 2); ?></td>
<td><?php echo htmlspecialchars($product['stock']); ?></td>
<td>
<a href="product_edit.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-square"></i></a>
<a href="_handle_delete_product.php?id=<?php echo $product['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this product?');"><i class="bi bi-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>