-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinventory.php
193 lines (166 loc) · 7.17 KB
/
inventory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
include "redisconnect.php";
$me = $_COOKIE['PHPSESSID'];
$logged = $redis->hgetall("user:$me");
// Start session
session_start();
// Close Redis connection (Predis automatically handles connections, so no explicit close is needed)
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory</title>
<link rel="stylesheet" href="home.css">
<link rel="stylesheet" href="listItems.css">
<script src="title.js"></script>
<script src="https://kit.fontawesome.com/f7e75704ad.js" crossorigin="anonymous"></script>
</head>
<style>
#icons {
display: flex;
justify-content: space-between;
}
</style>
<body>
<header>
<h1>
<?php
if (isset($logged['merchantname'])) {
echo "{$logged['merchantname']} Inventory";
}
?>
</h1>
<div class="head">
<div class="menu">
<a onclick="toggleMenu()"><i class="fa-solid fa-bars"></i></a>
<div id="hide" class="navbar-toggle">
<a class="bar" href="index.php">Home</a>
<a class="bar" href="makeSale.php">Make Sale</a>
<a class="bar" href="inventory.php">Inventory</a>
<a class="bar" href="transactions.php">Transactions</a>
<a class="bar" href="about.html">About</a>
<a class="bar" href="services.html">Services</a>
<a class="bar" href="logout.php">Log out</a>
</div>
</div>
<nav class="nav" id="navbarLinks">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="makeSale.php">Make Sale</a></li>
<li><a href="inventory.php">Inventory</a></li>
<li><a href="transactions.php">Transactions</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="logout.php"><i class="fa-regular fa-user" style="color: #ffffff;"></i> log out</a></li>
</ul>
</nav>
</div>
</header>
<div class="inventorydiv">
<div>
<div class="actionsBar">
<div>
<button class="button" onclick="toAdd()">Add items</button>
</div>
<div>
<div class="searchBar">
<input type="text" id="searchInput" class="searchInput" placeholder="Search...">
<button class="searchButton" onclick="searchItems()">Search</button>
</div>
</div>
</div>
<div class="inventorydiv1">
<!-- <button>::</button> -->
<?php
// Connect to your database
include 'dbconfig.php';
// Fetch data from the database
$sql = "SELECT `product_id`, `name`, `description`, `price`, `quantity`, `img_url`,
`user_id`, `merchant_id` FROM `product` WHERE `merchant_id` = ?";
$stmt = $conn->prepare($sql);
// Bind the parameter to the statement
$stmt->bind_param("i", $logged['merchantid']);
// Execute the query
$stmt->execute();
// Get the result
$result = $stmt->get_result();
// Check if the query returned any rows
if ($result->num_rows > 0) {
// Output data of each row
while ($row = $result->fetch_assoc()) {
$prod = strval($row["product_id"]);
echo "<div class='card' style='color:white;'>";
echo "<img src='" . $row["img_url"] . "' alt='Product Image'>";
echo "<div class='card-content'>";
echo "<h4>" . $row["name"] . "</h4>";
echo "<p>" . $row["description"] . "</p>";
echo "<p>Ksh. " . $row["price"] . "</p>";
$quantity = $row["quantity"];
// Check if quantity is less than zero
if ($quantity <= 0) {
// If quantity is negative, echo "Out of stock" in red
echo '<p style="color: red;">Out of stock</p>';
} else {
// Otherwise, echo the quantity as normal
echo "<p>stock: $quantity</p>";
}
echo '<div id="icons"><div class="edit" onclick = toDelete(' . $prod . ') ><i class="fa fa-trash" aria-hidden="true" style="color: #ffffff;"></i></div>';
echo '<div class="edit"><a href="editInventory.php?product_id=' . $prod . '"><i class="fa-regular fa-pen-to-square" style="color: #ffffff;"></i></a></div></div>';
echo '</div>';
echo '</div>';
}
} else {
echo '<div id="maindiv">';
echo '<div class="main-content" id="div2">';
echo 'You have no prducts in your inventory';
echo '<button class="button" onclick="toAdd()">Add new products</button>';
echo '</div>';
echo '</div>';
}
$conn->close();
?>
</div>
</div>
<footer>
<p style="font-size: 10px;color:white;">
© 2024 posperity,all rights reserved</p>
</footer>
</div>
</body>
<script>
function toggleMenu() {
var navbarLinks = document.getElementById("hide");
if (navbarLinks.style.display === "flex") {
navbarLinks.style.display = "none";
} else {
navbarLinks.style.display = "flex";
}
}
function searchItems() {
var input = document.getElementById('searchInput').value.trim().toLowerCase();
var cards = document.getElementsByClassName('card');
for (var i = 0; i < cards.length; i++) {
var name = cards[i].querySelector('h4').textContent.toLowerCase();
var description = cards[i].querySelector('p').textContent.toLowerCase();
if (name.includes(input) || description.includes(input)) {
cards[i].style.display = 'block';
} else {
cards[i].style.display = 'none';
}
}
}
function toAdd() {
// Redirect to another page (replace 'page-url' with the actual URL)
window.location.href = 'add_product.php';
}
function toDelete(pid) {
// Redirect to another page (replace 'page-url' with the actual URL)
if (confirm('Deleting This product will automatically delete all transactions related to it.\n Are you sre you want to delete this product from inventory?')) {
window.location.href = 'delete.php?product_id=' + pid;
} else {
}
}
</script>
</html>