-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaff_dashboard.php
More file actions
163 lines (151 loc) Β· 5.37 KB
/
staff_dashboard.php
File metadata and controls
163 lines (151 loc) Β· 5.37 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
<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'staff') {
header("Location: login.php");
exit();
}
// Fetch daily sales data
include 'db.php';
$sales_sql = "SELECT DATE(order_date) as order_date, SUM(total_price) as total_revenue
FROM orders WHERE status = 'Completed'
GROUP BY DATE(order_date)";
$sales_result = $conn->query($sales_sql);
$dates = [];
$sales = [];
while ($row = $sales_result->fetch_assoc()) {
$dates[] = $row['order_date'];
$sales[] = $row['total_revenue'];
}
// Fetch stock levels
$stock_sql = "SELECT name, quantity FROM products";
$stock_result = $conn->query($stock_sql);
$product_names = [];
$stock_levels = [];
while ($row = $stock_result->fetch_assoc()) {
$product_names[] = $row['name'];
$stock_levels[] = $row['quantity'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Staff Dashboard</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
background-color: #f8f9fa;
}
.sidebar {
background-color: #343a40;
height: 100vh;
padding-top: 20px;
position: fixed;
width: 250px;
}
.sidebar a {
color: #fff;
font-size: 18px;
padding: 12px;
display: block;
text-decoration: none;
}
.sidebar a:hover {
background-color: #495057;
}
.main-content {
margin-left: 250px;
padding: 20px;
}
.card-body {
padding: 1.5rem;
}
.card {
margin-bottom: 20px;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar position-fixed">
<h3 class="text-center text-white">Staff Panel</h3>
<a href="products.php">π¦ View Products</a>
<a href="stock.php">π Update Stock</a>
<a href="orders.php">π Place Orders</a>
<a href="logout.php" class="text-danger">πͺ Logout</a>
</div>
<!-- Main Content -->
<div class="main-content">
<div class="container mt-4">
<div class="card shadow-lg">
<div class="card-header text-center bg-primary text-white">
<h3>Staff Dashboard</h3>
<p>Welcome, <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong>!</p>
</div>
<div class="card-body">
<!-- Sales Trend Chart -->
<div class="row mb-4">
<div class="col-md-6">
<div class="card shadow-sm p-3">
<h5 class="text-secondary">Sales Trend</h5>
<canvas id="salesChart"></canvas>
</div>
</div>
</div>
<!-- Stock Levels Chart -->
<div class="row mb-4">
<div class="col-md-12">
<div class="card shadow-sm p-3">
<h5 class="text-secondary">Stock Levels</h5>
<canvas id="stockChart"></canvas>
</div>
</div>
</div>
<!-- Staff Operations Section -->
<div class="row mb-4">
<div class="col-md-12">
<h4 class="text-secondary">βοΈ Operations</h4>
<ul class="list-group mb-3">
<li class="list-group-item"><a href="products.php" class="text-decoration-none">π¦ View Products</a></li>
<li class="list-group-item"><a href="stock.php" class="text-decoration-none">π Update Stock</a></li>
<li class="list-group-item"><a href="orders.php" class="text-decoration-none">π Place Orders</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Sales Trend Chart
var ctx1 = document.getElementById('salesChart').getContext('2d');
var salesChart = new Chart(ctx1, {
type: 'line',
data: {
labels: <?php echo json_encode($dates); ?>,
datasets: [{
label: 'Daily Sales (βΉ)',
data: <?php echo json_encode($sales); ?>,
borderColor: 'blue',
fill: false
}]
}
});
// Stock Levels Chart
var ctx2 = document.getElementById('stockChart').getContext('2d');
var stockChart = new Chart(ctx2, {
type: 'bar',
data: {
labels: <?php echo json_encode($product_names); ?>,
datasets: [{
label: 'Stock Quantity',
data: <?php echo json_encode($stock_levels); ?>,
backgroundColor: 'green'
}]
}
});
</script>
</body>
</html>