159 lines
6.5 KiB
PHP
159 lines
6.5 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
start_secure_session();
|
|
require_login();
|
|
|
|
$message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['add_item'])) {
|
|
$item_name = $_POST['item_name'];
|
|
$quantity = $_POST['quantity'];
|
|
$price = $_POST['price'];
|
|
if (add_inventory_item($item_name, $quantity, $price)) {
|
|
$message = "Item added successfully.";
|
|
} else {
|
|
$message = "Failed to add item.";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) {
|
|
if (delete_inventory_item($_GET['id'])) {
|
|
$message = "Item deleted successfully.";
|
|
} else {
|
|
$message = "Failed to delete item.";
|
|
}
|
|
}
|
|
|
|
$inventory_items = get_inventory_items();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Inventory - Flatlogic</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
|
|
</head>
|
|
<body class="d-flex">
|
|
|
|
<div class="sidebar d-flex flex-column p-3">
|
|
<a href="index.php" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
|
|
<i class="bi bi-buildings me-2"></i>
|
|
<span class="fs-4">Flatlogic</span>
|
|
</a>
|
|
<hr>
|
|
<ul class="nav nav-pills flex-column mb-auto">
|
|
<li class="nav-item">
|
|
<a href="index.php" class="nav-link text-white" aria-current="page">
|
|
<i class="bi bi-speedometer2 me-2"></i>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="reports.php" class="nav-link text-white">
|
|
<i class="bi bi-bar-chart-line me-2"></i>
|
|
Reports
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="inventory.php" class="nav-link text-white active">
|
|
<i class="bi bi-box-seam me-2"></i>
|
|
Inventory
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
<hr>
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<i class="bi bi-person-circle me-2"></i>
|
|
<strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-dark text-small shadow" aria-labelledby="dropdownUser1">
|
|
<li><a class="dropdown-item" href="logout.php">Sign out</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<main class="main-content flex-grow-1 p-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0">Inventory</h1>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-info"><?php echo $message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header">
|
|
Add New Item
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="inventory.php" method="POST">
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<input type="text" name="item_name" class="form-control" placeholder="Item Name" required>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<input type="number" name="quantity" class="form-control" placeholder="Quantity" required>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<input type="text" name="price" class="form-control" placeholder="Price" required>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" name="add_item" class="btn btn-primary w-100">Add Item</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
Inventory Items
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Item Name</th>
|
|
<th>Quantity</th>
|
|
<th>Price</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($inventory_items)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No inventory items found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($inventory_items as $item): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($item['item_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($item['quantity']); ?></td>
|
|
<td>$<?php echo htmlspecialchars($item['price']); ?></td>
|
|
<td>
|
|
<a href="edit_inventory_item.php?id=<?php echo $item['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
<a href="inventory.php?action=delete&id=<?php echo $item['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|