65 lines
3.0 KiB
PHP
65 lines
3.0 KiB
PHP
<?php
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT p.id, p.name, p.barcode, i.quantity
|
|
FROM products p
|
|
JOIN inventory i ON p.id = i.product_id
|
|
ORDER BY p.name");
|
|
$inventory_items = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
echo "<div class='alert alert-danger'>Database error: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
$inventory_items = [];
|
|
}
|
|
?>
|
|
|
|
<h1 class="h3 mb-4">Inventory Management</h1>
|
|
|
|
<?php
|
|
if (isset($_SESSION['success_message'])) {
|
|
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">' . htmlspecialchars($_SESSION['success_message']) . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
|
unset($_SESSION['success_message']);
|
|
}
|
|
if (isset($_SESSION['error_message'])) {
|
|
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">' . htmlspecialchars($_SESSION['error_message']) . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
|
unset($_SESSION['error_message']);
|
|
}
|
|
?>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Product Name</th>
|
|
<th>Barcode</th>
|
|
<th class="text-center">Current Stock</th>
|
|
<th style="width: 250px;">Update Stock</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($inventory_items)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No products found in inventory.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($inventory_items as $item): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($item['name']) ?></td>
|
|
<td><?= htmlspecialchars($item['barcode'] ?? 'N/A') ?></td>
|
|
<td class="text-center fs-5"><?= htmlspecialchars($item['quantity']) ?></td>
|
|
<td>
|
|
<form action="/api/update_stock.php" method="post" class="d-flex">
|
|
<input type="hidden" name="product_id" value="<?= $item['id'] ?>">
|
|
<input type="number" name="quantity" class="form-control me-2" value="<?= htmlspecialchars($item['quantity']) ?>" required min="0">
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|