-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinventory.php
More file actions
284 lines (265 loc) · 12.6 KB
/
inventory.php
File metadata and controls
284 lines (265 loc) · 12.6 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
include("includes/connection.php");
include("includes/shop_dash_header.php");
$shop_id = $_SESSION['o_id'] ?? 0;
$stock_filter = $_GET['stock_filter'] ?? 'in_stock';
if ($stock_filter === 'all') {
$inv_sql = "SELECT products.id AS product_id, products.name AS product_name,
products.price AS price, products.quantity AS quantity
FROM products
INNER JOIN shop ON shop.id = products.shop_id
WHERE products.shop_id = '$shop_id' AND products.status = 'Active'
ORDER BY products.id DESC";
} elseif ($stock_filter === 'out_stock') {
$inv_sql = "SELECT products.id AS product_id, products.name AS product_name,
products.price AS price, products.quantity AS quantity
FROM products
INNER JOIN shop ON shop.id = products.shop_id
WHERE products.shop_id = '$shop_id' AND products.quantity = 0 AND products.status = 'Active'
ORDER BY products.id DESC";
}
elseif ($stock_filter === 'deleted') {
$inv_sql = "SELECT products.id AS product_id, products.name AS product_name,
products.price AS price, products.quantity AS quantity
FROM products
INNER JOIN shop ON shop.id = products.shop_id
WHERE products.shop_id = '$shop_id' AND products.status = 'Disabled'
ORDER BY products.id DESC";
} else {
// Default filter
$inv_sql = "SELECT products.id AS product_id, products.name AS product_name,
products.price AS price, products.quantity AS quantity
FROM products
INNER JOIN shop ON shop.id = products.shop_id
WHERE products.shop_id = '$shop_id' AND products.quantity > 0 AND products.status = 'Active'
ORDER BY products.id DESC";
}
$inv_result = mysqli_query($conn, $inv_sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@300..700&family=Dosis:wght@200..800&family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Inspiration&family=Italiana&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Playwrite+IN:wght@100..400&family=Poiret+One&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
font-family:Rubik;
}
.dashboard-header {
background: rgba(202, 144, 134, 0.7);
padding: 40px 0;
text-align: center;
border-radius: 0 0 30px 30px;
margin-bottom: 30px;
}
.dashboard-header h1 {
margin-bottom: 10px;
font-weight: bold;
}
.card {
border-radius: 12px;
box-shadow: 0 0 15px rgba(0,0,0,0.05);
background: rgba(202, 144, 134, 0.7);
margin-top:50px;
}
.table thead th {
background-color: #343a40;
color: white;
}
input[type="number"]::-webkit-inner-spin-button {
opacity: 0.5;
}
.dashboard-header {
background: linear-gradient(135deg,rgba(211, 150, 150, 0.4), rgba(202, 144, 134),rgba(211, 150, 150, 0.4));
color: white;
padding: 40px 0;
text-align: center;
border-radius: 0 0 50px 50px;
margin-bottom: 30px;
width:100%;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="dashboard-header">
<h1>Inventory Details</h1>
</div>
<div class="container">
<form method="GET" class="mb-3 text-center" id="stockFilterForm" style="padding-top: 40px;">
<label>
<input type="radio" name="stock_filter" value="in_stock" <?= (!isset($_GET['stock_filter']) || $_GET['stock_filter'] === 'in_stock') ? 'checked' : '' ?>>
In Stock
</label>
<label>
<input type="radio" name="stock_filter" value="out_stock" <?= (isset($_GET['stock_filter']) && $_GET['stock_filter'] === 'out_stock') ? 'checked' : '' ?>>
Out of Stock
</label>
<label>
<input type="radio" name="stock_filter" value="all" <?= (isset($_GET['stock_filter']) && $_GET['stock_filter'] === 'all') ? 'checked' : '' ?>>
All Stock
</label>
<label>
<input type="radio" name="stock_filter" value="deleted" <?= (isset($_GET['stock_filter']) && $_GET['stock_filter'] === 'deleted') ? 'checked' : '' ?>>
Deleted
</label>
</form>
<div class="mb-3">
<input type="text" id="searchInput" class="form-control" placeholder="Search by product name">
</div>
<div class="card p-4 mb-4">
<div class="table-responsive">
<table class="table table-striped table-hover align-middle">
<thead>
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price (₹)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (mysqli_num_rows($inv_result) > 0): ?>
<?php while ($row = mysqli_fetch_assoc($inv_result)): ?>
<tr>
<td><?= htmlspecialchars($row['product_id']) ?></td>
<td>
<input type="text" value="<?= htmlspecialchars($row['product_name']) ?>"
class="form-control form-control-sm name-input"
data-product-id="<?= $row['product_id'] ?>"
style="max-width:100px;">
</td>
<td>
<input type="number" min="0" value="<?= htmlspecialchars($row['quantity']) ?>"
class="form-control form-control-sm me-2 quantity-input"
data-product-id="<?= $row['product_id'] ?>"
style="max-width:100px;">
</td>
<td>
<input type="number" step="0.01" value="<?= htmlspecialchars($row['price']) ?>"
class="form-control form-control-sm me-2 price-input"
data-product-id="<?= $row['product_id'] ?>"
style="max-width:100px;">
</td>
<td>
<?php if ($stock_filter === 'deleted'): ?>
<form method="POST" action="activate_product.php?stock_filter=<?= htmlspecialchars($stock_filter) ?>" onsubmit="return confirm('Are you sure you want to activate this product?');">
<input type="hidden" name="product_id" value="<?= $row['product_id'] ?>">
<button type="submit" class="btn btn-sm btn-success">Activate</button>
</form>
<?php else: ?>
<form method="POST" action="delete_product.php?stock_filter=<?= htmlspecialchars($stock_filter) ?>" onsubmit="return confirm('Are you sure you want to delete this product?');">
<input type="hidden" name="product_id" value="<?= $row['product_id'] ?>">
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="5" class="text-center" style="color: #111; background-color: #e9ecef;">
No inventory found
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<script>
document.querySelectorAll('input[name="stock_filter"]').forEach((radio) => {
radio.addEventListener('change', function () {
document.getElementById('stockFilterForm').submit();
});
});
</script>
<script>
document.querySelectorAll('.price-input').forEach(input => {
input.addEventListener('change', function () {
const productId = this.getAttribute('data-product-id');
const newPrice = this.value;
fetch('update_price.php?stock_filter=<?= htmlspecialchars($stock_filter) ?>', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `product_id=${productId}&new_price=${encodeURIComponent(newPrice)}`
})
.then(response => response.text())
.then(data => {
console.log("Price updated:", data);
})
.catch(error => {
console.error("Error updating price:", error);
});
});
});
</script>
<script>
$(document).ready(function () {
$('#searchInput').on('keyup', function () {
var value = $(this).val().toLowerCase();
$('table tbody tr').filter(function () {
$(this).toggle(
$(this).text().toLowerCase().indexOf(value) > -1
);
});
});
});
</script>
<script>
document.querySelectorAll('.quantity-input').forEach(input => {
input.addEventListener('change', function () {
const productId = this.getAttribute('data-product-id');
const newQuantity = this.value;
fetch('update_quantity.php?stock_filter=<?= htmlspecialchars($stock_filter) ?>', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `product_id=${productId}&new_quantity=${encodeURIComponent(newQuantity)}`
})
.then(response => response.text())
.then(data => {
console.log("Quantity updated:", data);
location.reload();
})
.catch(error => {
console.error("Error updating quantity:", error);
});
});
});
</script>
<script>
document.querySelectorAll('.name-input').forEach(input => {
input.addEventListener('change', function () {
const productId = this.getAttribute('data-product-id');
const newName = this.value;
fetch('update_name.php?stock_filter=<?= htmlspecialchars($stock_filter) ?>', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `product_id=${productId}&new_name=${encodeURIComponent(newName)}`
})
.then(response => response.text())
.then(data => {
console.log("Name updated:", data);
})
.catch(error => {
console.error("Error updating name:", error);
});
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>