-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.php
450 lines (432 loc) · 24.4 KB
/
dashboard.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
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?php
require_once './includes/db_conn.php';
require_once './includes/restriction.php';
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
$check_user_query = "SELECT user_type FROM users WHERE user_id = ?";
$result = query($conn, $check_user_query, [$user_id]);
if (count($result) > 0) {
$user_type = $result[0]['user_type'];
if ($user_type === "cashier") {
if (isset($_SESSION['last_visited_url'])) {
header("Location: " . $_SESSION['last_visited_url']);
} else {
header("Location: pos.php");
}
exit();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<?php include_once './includes/head.php'; ?>
</head>
<body class="bg-light pad">
<?php include_once './includes/side_navbar.php'; ?>
<div class="container-fluid" style="padding-left: 85px;">
<div class="row pt-4">
<div class="col-xl-4 col-md-4">
<?php
$rtc = date('Y-m-d');
$sql_today = "SELECT
DATE(s.sale_date) as date_order,
SUM(s.total_amt) AS total_sale,
SUM(s.product_profit) AS semi_gross_profit,
(SELECT SUM(a.salary) FROM attendance a WHERE DATE(a.date) = ?) AS total_salary
FROM sales s
WHERE DATE(s.sale_date) = ?
GROUP BY date_order
ORDER BY date_order DESC";
$res_today = query($conn, $sql_today, array($rtc, $rtc));
if (!empty($res_today)) {
$today = $res_today[0];
$targettoday = 10000;
$today_perc = ($today['total_sale'] / $targettoday) * 100;
$profit = $today['semi_gross_profit'] - $today['total_salary'];
} else {
$today = array(
'total_sale' => 0,
'total_salary' => 0,
'semi_gross_profit' => 0,
);
$today_perc = 0;
$profit = 0;
}
?>
<div class="card shadow-sm py-3">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-primary text-uppercase mb-1" style="font-size: small;">
Revenue(TODAY)</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo CURRENCY . number_format($today['total_sale'], 2); ?></div>
</div>
<div class="col-auto">
<i class='bx bxs-coin bx-lg' style='color:#0b50f5' ></i>
</div>
<!-- <div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar <?php if ($today_perc < 25) { echo "text-bg-danger"; } else if ($today_perc < 65) { echo "text-bg-warning"; } else if ($today_perc < 95) { echo "text-bg-info"; } else { echo "text-bg-success"; } ?>" style="width: <?php echo $today_perc; ?>%">
<?php echo $today_perc; ?>%
</div>
</div> -->
</div>
</div>
</div>
</div>
<?php
$currentYear = date('Y');
$currentMonth = date('m');
$startOfMonth = "{$currentYear}-{$currentMonth}-01";
$endOfMonth = date('Y-m-t', strtotime($startOfMonth));
$revenueSQL = "SELECT
DATE_FORMAT(s.sale_date, '%Y-%m') AS month_year,
SUM(s.total_amt) AS total_sale,
SUM(s.product_profit) AS semi_gross_profit,
(SELECT SUM(a.salary) FROM attendance a WHERE DATE(a.date) BETWEEN '$startOfMonth' AND '$endOfMonth') AS total_salary
FROM sales s
WHERE s.sale_date BETWEEN '$startOfMonth' AND '$endOfMonth'
GROUP BY month_year
ORDER BY month_year DESC";
$revenuemonth = query($conn, $revenueSQL);
$salesMONTH = 0;
foreach ($revenuemonth as $month) {
$salesMONTH = $month['total_sale'];
}
?>
<div class="col-xl-4 col-md-4">
<div class="card shadow-sm py-3">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-success text-uppercase mb-1" style="font-size: small;">
REVENUE(MONTHLY)</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo CURRENCY . number_format($salesMONTH, 2)?></div>
</div>
<div class="col-auto">
<i class='bx bx-money bx-lg' style='color:#00FF14' ></i>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-md-4">
<div class="card shadow-sm py-3">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="font-weight-bold text-warning text-uppercase mb-1" style="font-size: small;">
PROFIT(TODAY)</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" style="font-size: x-large;"><?php echo CURRENCY . number_format($profit, 2); ?></div>
</div>
<div class="col-auto">
<i class='bx bxs-report bx-lg' style='color:#FFE200' ></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mb-5 mt-3">
<div class="col-xl-8 bg-white shadow-sm card pt-3">
<form action="" method="POST">
<div class="input-group mb-3">
<span class="input-group-text">Between </span>
<input type="date" name="start_date" class="form-control">
<span class="input-group-text"> and </span>
<input type="date" name="end_date" class="form-control">
<input type="submit" name="filter_range" value="filter" class="btn btn-primary">
</div>
</form>
<form action="" method="POST">
<div class="row">
<div class="input-group mb-3">
<span class="input-group-text">For These Date</span>
<input type="date" name="this_date" class="form-control">
<input type="submit" name="filter_date" value="Filter" class="btn btn-primary">
</div>
</div>
<div class="row dash-scroll row-cols-2 row-cols-md-5 g-4">
<?php
if (isset($_POST['filter_date'])) {
// Filter by date
$salesSQL = "SELECT
DATE(s.sale_date) as date_order,
SUM(s.total_amt) AS total_sale,
SUM(s.product_profit) AS semi_gross_profit
FROM sales s
WHERE DATE(s.sale_date) = ?
GROUP BY date_order
ORDER BY date_order DESC";
$resultsales = query($conn, $salesSQL, array($_POST['this_date']));
} elseif (isset($_POST['filter_range'])) {
// Filter by date range
$salesSQL = "SELECT
DATE(s.sale_date) as date_order,
SUM(s.total_amt) AS total_sale,
SUM(s.product_profit) AS semi_gross_profit
FROM sales s
WHERE s.sale_date BETWEEN ? AND ?
GROUP BY DATE(s.sale_date)
ORDER BY date_order ASC";
$resultsales = query($conn, $salesSQL, array($_POST['start_date'], $_POST['end_date']));
} else {
// Default code if none of the filters are selected
$salesSQL = "SELECT
s.sales_transaction_code as transactioncode,
COUNT(DISTINCT DATE(s.sale_date)) AS salexdate,
DATE(s.sale_date) as date_order,
SUM(s.total_amt) as total_sale,
SUM(s.product_profit) as semi_gross_profit,
(SELECT SUM(base_salary) FROM employee_management) as total_base_salary
FROM sales s
GROUP BY date_order
ORDER BY date_order DESC";
$resultsales = query($conn, $salesSQL);
}
foreach ($resultsales as $res) {
$target = 1000;
$order_perc = ($res['salexdate'] / $target) * 100;
?>
<div class="col-xl-4 col-md-3">
<div class="card mt-2 p-2">
<b class="ms-2"><?php echo $res['date_order']; ?></b>
<table class="table table-responsive table-hover">
<tr>
<td>Total Sales</td>
<td><?php echo CURRENCY . number_format($res['total_sale'], 2); ?></td>
</tr>
</table>
<?php
$rep_detail_sql = "SELECT p.item_name, s.product_qty, s.total_amt
FROM sales s
INNER JOIN products p ON s.product_id = p.product_id
WHERE DATE(s.sale_date) = ?";
$rep_detail = query($conn, $rep_detail_sql, array($res['date_order']));
?>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse"
data-bs-target="#<?php echo $res['date_order']; ?>" aria-expanded="false"
aria-controls="<?php echo $res['date_order']; ?>">
Item Sold
</button>
<div class="collapse multicollapse" id="<?php echo $res['date_order']; ?>">
<table class="table table-responsive table-striped">
<tr>
<th>Item Name</th>
<th>Orders</th>
<th>Sales Amt</th>
</tr>
<?php
foreach ($rep_detail as $item) {
?>
<tr>
<td><?php echo $item['item_name']; ?></td>
<td><?php echo $item['product_qty']; ?></td>
<td><?php echo CURRENCY . number_format($item['total_amt'], 2); ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<div class="col-xl-4 col-lg-4">
<div class="card shadow-sm">
<div class="card-body">
<h4 class="text-center" style="background-color: #1C387C; color: white;">PRODUCTS</h4>
<div class="table table-responsive-sm text-center">
<table class="table caption-top table-striped">
<caption>RESTOCK NEEDED</caption>
<thead class="table-primary">
<tr>
<td>NAME</td>
<td>STOCK</td>
<td></td>
</tr>
</thead>
<tbody>
<?php
$restock = "SELECT * FROM products WHERE product_stock <= warning_stock";
$restockprod = mysqli_query($conn, $restock);
while($resultprod = mysqli_fetch_assoc($restockprod)){
?>
<tr>
<td><?php echo $resultprod['item_name'] ?></td>
<td><?php echo $resultprod['product_stock'] ?></td>
<td>
<form action="inventory.php" method="POST">
<input type="hidden" name="product_id" value="<?php echo $resultprod['product_id'] ?>">
<button class="btn" type="submit" name="navigate"><ion-icon name="create-outline"></ion-icon></button>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="card mt-3 bg-white shadow-sm">
<div class="card-body">
<h3 class="text-center" style="background-color: #1C387C; color: white;">GENERATE DOCUMENTS</h3>
<h5 style="color: #1C387C; padding-top: 1em;">GENERATE SALES REPORT</h5>
<form action="" method="POST">
<div class="input-group mb-3">
<span class="input-group-text">Between</span>
<input type="date" name="start_date" class="form-control" required>
<span class="input-group-text"> and </span>
<input type="date" name="end_date" class="form-control" required>
<button type="submit" class="text-center btn btn-secondary1" name="generaterep">GENERATE</button>
</div>
</form>
<?php
if(isset($_POST['generaterep'])){
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$showViewButton = true;
} else {
$showViewButton = false;
}
?>
<form action="./extension/generate_sales_rep.php" method="POST" target="_blank">
<?php if($showViewButton): ?>
<div class="input-group mb-3 text-center">
<input type="text" name="start_date" class="form-control" value="<?php echo $start_date; ?>" aria-label="Username">
<span class="input-group-text">BETWEEN</span>
<input type="text" name="end_date" class="form-control" value="<?php echo $end_date; ?>" aria-label="Server">
</div>
<div class="text-center">
<button type="submit" id="invoiceRep" class="text-center btn btn-secondary1" name="viewrep"><i class='bx bxs-printer'></i> VIEW</button>
<script>
document.getElementById('invoiceRep').addEventListener('submit', function (e) {
});
</script>
</div>
<?php endif; ?>
</form>
<h5 style="color: #1C387C;">FINANCIAL REPORT</h5>
<form action="" method="POST">
<div class="input-group mb-3">
<span class="input-group-text">Between</span>
<input type="date" name="start_date" class="form-control" required>
<span class="input-group-text"> and </span>
<input type="date" name="end_date" class="form-control" required>
<button type="submit" class="text-center btn btn-secondary1" name="generatefi">GENERATE</button>
</div>
</form>
<?php
if(isset($_POST['generatefi'])){
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$showViewButton2 = true;
} else {
$showViewButton2 = false;
}
?>
<form action="./extension/generate_financial_rep.php" method="POST" target="_blank">
<?php if($showViewButton2): ?>
<div class="input-group mb-3 text-center">
<input type="text" name="start_date" class="form-control" value="<?php echo $start_date; ?>" aria-label="Username">
<span class="input-group-text">BETWEEN</span>
<input type="text" name="end_date" class="form-control" value="<?php echo $end_date; ?>" aria-label="Server">
</div>
<div class="text-center">
<button type="submit" id="invoiceRep" class="text-center btn btn-secondary1" name="viewrep"><i class='bx bxs-printer'></i> VIEW</button>
<script>
document.getElementById('invoiceRep').addEventListener('submit', function (e) {
});
</script>
</div>
<?php endif; ?>
</form>
<h5 style="color: #1C387C; padding-top: .5em;">GENERATE LOG BOOK</h5>
<form action="" method="POST">
<div class="input-group mb-3">
<span class="input-group-text">Between</span>
<input type="date" name="start_date" class="form-control" required>
<span class="input-group-text"> and </span>
<input type="date" name="end_date" class="form-control" required>
<button type="submit" class="text-center btn btn-secondary1" name="generatelog">GENERATE</button>
</div>
</form>
<?php
if(isset($_POST['generatelog'])){
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
$showViewButton1 = true;
} else {
$showViewButton1 = false;
}
?>
<form action="./extension/generate_log.php" method="POST" target="_target">
<?php if($showViewButton1): ?>
<div class="input-group mb-3 text-center">
<input type="text" name="start_date" class="form-control" value="<?php echo $start_date; ?>" aria-label="Username" >
<span class="input-group-text">BETWEEN</span>
<input type="text" name="end_date" class="form-control" value="<?php echo $end_date; ?>" aria-label="Server">
</div>
<div class="text-center">
<button type="submit" id="invoiceLog" class="text-center btn btn-secondary1" name="viewlog"><i class='bx bxs-printer'></i> VIEW</button>
</div>
<script>
document.getElementById('invoiceLog').addEventListener('submit', function (e) {
});
</script>
<?php endif; ?>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
// Enable Bootstrap dropdown for the my-dropdown
var myDropdown = document.querySelector('.my-dropdown');
myDropdown.addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
var parent = myDropdown.parentElement;
var menu = parent.querySelector('.dropdown-menu');
var isOpen = menu.classList.contains('show');
// Close all other open dropdowns
var otherDropdowns = document.querySelectorAll('.dropdown-centered');
otherDropdowns.forEach(function(otherDropdown) {
var otherParent = otherDropdown;
var otherMenu = otherParent.querySelector('.dropdown-menu');
if (otherParent !== parent && otherMenu.classList.contains('show')) {
otherMenu.classList.remove('show');
}
});
// Toggle the 'show' class for the my-dropdown
if (isOpen) {
menu.classList.remove('show');
} else {
menu.classList.add('show');
}
});
// Close dropdowns when clicking outside (for all dropdowns)
document.addEventListener('click', function(event) {
var dropdowns = document.querySelectorAll('.dropdown-menu');
dropdowns.forEach(function(menu) {
if (menu.classList.contains('show') && !menu.contains(event.target)) {
menu.classList.remove('show');
}
});
});
</script>
<footer>
<?php require_once './includes/footer.php'; ?>
</footer>
</html>