-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathview-product.php
More file actions
344 lines (284 loc) · 12.2 KB
/
view-product.php
File metadata and controls
344 lines (284 loc) · 12.2 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
include("includes/header.php");
if(!isset($_SESSION['admin_username']))
{
echo "<script>document.location='login.php'</script>";
}
else
{
?>
<!-- Main Content-->
<div class="main-content pt-0">
<div class="container">
<div class="inner-body">
<!-- Page Header -->
<div class="page-header">
<div>
<h2 class="main-content-title tx-24 mg-b-5">Product</h2>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">View Products</li>
</ol>
</div>
</div>
<!-- End Page Header -->
<!-- Row -->
<div class="row sidemenu-height">
<div class="col-lg-12">
<div class="card custom-card">
<div class="card-body">
<div class="table-responsive">
<table class="table" id="example2">
<thead>
<tr>
<th class="wd-20p">Product Name</th>
<th class="wd-15p">Quantity</th>
<th class="wd-20p">Selling Price</th>
<th class="wd-20p">Cost Price</th>
<th class="wd-20p">Profit</th>
<th class="wd-20p">Total Profit</th>
<th class="wd-20p">Expiry Date</th>
<th class="wd-20p">Expiry Status</th>
<th class="wd-20p">Reorder</th>
<th class="wd-15p">Stock Status</th>
<th class="wd-15p">Action</th>
</tr>
</thead>
<tbody>
<?php
$get_prod = "SELECT * FROM product_tbl ORDER BY prod_name";
$run_prod = mysqli_query($db, $get_prod);
while($row_prod = mysqli_fetch_array($run_prod))
{
$prod_id = $row_prod['prod_id'];
$prod_name = $row_prod['prod_name'];
$cat_id = $row_prod['cat_id'];
$sup_id = $row_prod['supplier_id'];
$brand_id = $row_prod['brand_id'];
$price = $row_prod['prod_price'];
$qty = $row_prod['prod_qty'];
$reorder = $row_prod['reorder'];
$status = $row_prod['prod_status'];
$expiry_date = $row_prod['expiry_date'];
// Get Stock
$get_stock = "SELECT * FROM tbl_stockin WHERE prod_id = '$prod_id'";
$run_stock = mysqli_query($db, $get_stock);
$row_stk = mysqli_fetch_array($run_stock);
$cost_price = $row_stk['cost_price'] ?? null;
// Calculations
$profit = $price - $cost_price;
$total_profit = $profit * $qty;
// Get Category
$get_cat = "SELECT * FROM categories WHERE cat_id = '$cat_id'";
$run_cat = mysqli_query($db, $get_cat);
$row_cat = mysqli_fetch_array($run_cat);
$cat_name = $row_cat['cat_name'];
// Get Supplier
$get_sup = "SELECT * FROM tbl_suppliers WHERE sup_id = '$sup_id'";
$run_sup = mysqli_query($db, $get_sup);
$row_sup = mysqli_fetch_array($run_sup);
$sup_name = $row_sup['sup_name'];
// Get Brand
$get_brand = "SELECT * FROM tbl_brand WHERE brand_id = '$brand_id'";
$run_brand = mysqli_query($db, $get_brand);
$row_brand = mysqli_fetch_array($run_brand);
$brand_name = $row_brand['brand_name'];
?>
<tr>
<td><?php echo $prod_name; ?></td>
<td><?php echo $qty; ?></td>
<td><?php echo number_format($price,2); ?></td>
<td><?php echo number_format($cost_price,2); ?></td>
<td><?php echo number_format($profit,2); ?></td>
<td><?php echo number_format($total_profit ,2); ?></td>
<td><?php echo date("M d, Y",strtotime($expiry_date)); ?></td>
<td>
<?php
$expiration = $expiry_date; //fetch the expiration on the database in
$today = date('Y/m/d');
//convert to strtotime;
$convertExp = strtotime($expiration);
$convertDay = strtotime($today);
$timeleft = $convertExp - $convertDay;
$daysleft = round((($timeleft/24)/60)/60);
if($daysleft <= 60)
{
echo "<span class='badge badge-danger'>Closer to expiry</span>";
}
else if($daysleft == 60)
{
echo "<span class='badge badge-success'>Product Expired</span>";
}
else {
echo "<span class='badge badge-success'>Product Valid</span>";
}
?>
</td>
<td><?php echo $reorder; ?></td>
<td>
<?php
if($qty == $reorder)
{
echo "<span class='badge badge-danger'>Low Stock</span>";
}
elseif($qty <= 0)
{
echo "<span class='badge badge-danger'>Stock Out</span>";
}
else
{
echo "<span class='badge badge-success'>In Stock</span>";
}
?>
</td>
<td>
<a class="btn ripple btn-primary" data-target="#update<?php echo $prod_id; ?>" data-toggle="modal" href="#update<?php echo $prod_id; ?>"><i class="fa fa-eye"></i></a>
<a class="btn ripple btn-danger" data-target="#delete<?php echo $prod_id; ?>" data-toggle="modal" href="#delete<?php echo $prod_id; ?>"><i class="fa fa-trash"></i></a>
</td>
</tr>
<!-- Large Modal -->
<div class="modal" id="update<?php echo $prod_id; ?>">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content modal-content-demo">
<div class="modal-header">
<h6 class="modal-title">Update Product Details</h6>
<button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<form method="post" action="update-product.php" enctype="multipart/form-data">
<div class="row row-sm">
<div class="col-md-12 col-lg-12 col-xl-12">
<div class="">
<div class="form-group col-md-9">
<label class=""> Product Name </label>
<input class="form-control" value="<?php echo $prod_id; ?>" required="" name="prod_id" type="hidden">
<input class="form-control" value="<?php echo $prod_name; ?>" required="" name="prod_name" type="text">
</div>
<div class="form-group col-md-9">
<div class="row row-sm">
<div class="col-sm-4">
<label class="">Product Category</label>
<input class="form-control" value="<?php echo $prod_id; ?>" required="" name="prod_id" type="hidden">
<select name="prod_cat" class="form-control select select2">
<option value="<?php echo $cat_id; ?>">
<?php echo $cat_name; ?>
</option>
<?php
$get_cat = "SELECT * FROM categories";
$run_cat = mysqli_query($db, $get_cat);
while($row_cat = mysqli_fetch_array($run_cat))
{
$cat_id = $row_cat['cat_id'];
$cat_name = $row_cat['cat_name'];
echo "<option value='$cat_id'>$cat_name</option>";
}
?>
</select>
</div>
<div class="col-sm-4 mg-t-20 mg-sm-t-0">
<label class="">Product Supplier</label>
<select name="prod_sup" class="form-control select select2">
<option value="<?php echo $sup_id; ?>">
<?php echo $sup_name; ?>
</option>
<?php
$get_sup = "SELECT * FROM tbl_suppliers";
$run_sup = mysqli_query($db, $get_sup);
while($row_sup = mysqli_fetch_array($run_sup))
{
$sup_id = $row_sup['sup_id'];
$sup_name = $row_sup['sup_name'];
echo "<option value='$sup_id'>$sup_name</option>";
}
?>
</select>
</div>
<div class="col-sm-4 mg-t-20 mg-sm-t-0">
<label class="">Product Brand</label>
<select name="prod_brand" class="form-control select select2">
<option value="<?php echo $brand_id; ?>">
<?php echo $brand_name; ?>
</option>
<?php
$get_brand = "SELECT * FROM tbl_brand";
$run_brand = mysqli_query($db, $get_brand);
while($row_brand = mysqli_fetch_array($run_brand))
{
$brand_id = $row_brand['brand_id'];
$brand_name = $row_brand['brand_name'];
echo "<option value='$brand_id'>$brand_name</option>";
}
?>
</select>
</div>
</div>
</div>
<div class="form-group col-md-9">
<label class="">Expiry Date</label>
<input class="form-control" required="" value="<?php echo $expiry_date; ?>" name="expiry_date" type="date">
</div>
<div class="form-group col-md-9">
<label class="">Product Price</label>
<input class="form-control" required="" value="<?php echo $price; ?>" name="prod_price" type="text">
</div>
<div class="form-group col-md-9">
<label class=""> Reorder Point </label>
<input class="form-control" value="<?php echo $reorder; ?>" required="" name="reorder" type="text">
</div>
<div class="form-group col-md-9">
<label class="">Product Status</label>
<select name="prod_status" class="form-control select select2">
<option value="<?php echo $status; ?>"><?php echo $status; ?></option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn ripple btn-primary" type="submit">Update Product</button>
<button class="btn ripple btn-secondary" data-dismiss="modal" type="button">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--End Large Modal -->
<!-- Delete Modal -->
<div class="modal" id="delete<?php echo $prod_id;?>">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content modal-content-demo">
<div class="modal-header">
<h6 class="modal-title">Delete Product Details</h6><button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<form action="product-del.php" method="post">
<input type="hidden" class="form-control" name="prod_id" value="<?php echo $prod_id; ?>" required>
<p>Are you sure you want to <b>Delete</b> this Product?</p>
</div>
<div class="modal-footer">
<button class="btn ripple btn-primary" name="delete" type="submit">Yes</button>
<button class="btn ripple btn-danger" data-dismiss="modal" type="button">No</button>
</div>
</form>
</div>
</div>
</div>
<!--End Delete Modal -->
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- End Row -->
</div>
</div>
</div>
<!-- End Main Content-->
<?php include("includes/footer.php"); ?>
<?php } ?>