34628-vm/inventory.php
2025-10-03 14:17:07 +00:00

87 lines
2.4 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
include 'includes/header.php';
include 'includes/sidebar.php';
// Fetch products from the database
try {
$pdo = db();
$stmt = $pdo->query('SELECT * FROM products ORDER BY name');
$products = $stmt->fetchAll();
} catch (PDOException $e) {
$products = [];
$error = "Erro ao buscar produtos: " . $e->getMessage();
}
?>
<header class="top-bar">
<h1>Estoque</h1>
</header>
<main class="content">
<div class="card">
<div class="card-header">
<span>Produtos em Estoque</span>
<a href="add_product.php" class="btn" style="float: right; background-color: #3498db; color: white; text-decoration: none; padding: 5px 10px; border-radius: 4px;">Adicionar Produto</a>
</div>
<?php if (isset($error)): ?>
<p class="error"><?php echo $error; ?></p>
<?php endif; ?>
<table>
<thead>
<tr>
<th>Produto</th>
<th>Unidade</th>
<th>Quantidade</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php if (empty($products)): ?>
<tr>
<td colspan="4">Nenhum produto encontrado.</td>
</tr>
<?php else: ?>
<?php foreach ($products as $product): ?>
<tr>
<td><?php echo htmlspecialchars($product['name']); ?></td>
<td><?php echo htmlspecialchars($product['unit']); ?></td>
<td><?php echo htmlspecialchars($product['quantity']); ?></td>
<td>
<a href="stock.php?product_id=<?php echo $product['id']; ?>">Movimentar</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</main>
<style>
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
<?php include 'includes/footer.php'; ?>