-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_stat.php
214 lines (172 loc) · 5.46 KB
/
admin_stat.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
<?php
require_once './connection/config.php';
$error = "";
//for fetching the count of the books
$result = $mysqli->query("SELECT COUNT(id) AS total_rows FROM books");
if ($result) {
$row = $result->fetch_assoc();
$book_count = $row['total_rows'];
echo "Total rows: " . $book_count;
} else {
$book_count = 0;
}
// fetching the completed order which represents the total sales
$result = $mysqli->query("SELECT sum(total_price) AS total_sales FROM orders WHERE status = 'Completed'");
if ($result) {
$row = $result->fetch_assoc();
$total_sales = $row['total_sales'];
} else {
$total_sales = 0;
}
// count the books quantity
$result = $mysqli->query("SELECT sum(stock) AS total_quantity FROM books");
if ($result) {
$row = $result->fetch_assoc();
$book_quantities = $row['total_quantity'];
} else {
$book_quantities = 0;
}
// select the order status
$result = $mysqli->query("SELECT status, COUNT(*) AS count FROM orders WHERE status IN ('Pending', 'Completed', 'Cancelled') GROUP BY status");
if ($result) {
// Initialize counts
$counts = [
'Pending' => 0,
'Completed' => 0,
'Cancelled' => 0
];
// Fetch results
while ($row = $result->fetch_assoc()) {
if ($row['status'] === 'Pending') {
$counts['Pending'] = $row['count'];
} elseif ($row['status'] === 'Completed') {
$counts['Completed'] = $row['count'];
} elseif ($row['status'] === 'Cancelled') {
$counts['Cancelled'] = $row['count'];
}
}
// Assign to variables for easier usage
$order_pending = $counts['Pending'];
$order_completed = $counts['Completed'];
$order_cancelled = $counts['Cancelled'];
} else {
echo "Error: " . $mysqli->error;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Boxicons -->
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<!-- My CSS -->
<link rel="stylesheet" href="./css/admindashboard.css">
<title>Dashboard Admin: <?php echo $username ?> </title>
<!-- fro erro handling -->
<style>
:root {
--main-color: #4b49AC;
--second-color: #98BDFF;
--light-blue: #7DA0FA;
--light-purple: #7978E9;
--light-red: #F3797E;
}
.error {
background: #4b49ac;
color: white;
margin: 8px;
padding: 7px;
border-radius: 10px;
}
.sales,
.order {
display: flex;
flex-direction: column;
}
.sales .boxes, .order .boxes{
display: flex;
flex-direction: row;
justify-content: space-around;
}
.box {
width: 15rem;
height: 10rem;
border: 3px solid var(--main-color);
border-radius: 20px;
background: var(--second-color);
padding: 20px;
gap: 20px;
font-size: xx-large;
display: flex;
flex-direction: column;
align-items: center;
}
</style>
</head>
<body>
<!-- SIDEBAR -->
<?php include 'admin_sidebar.php' ?>;
<!-- SIDEBAR -->
<!-- CONTENT -->
<section id="content">
<!-- NAVBAR -->
<nav>
<a href="admin_dashboard.php" class="nav-link">Admin Dashboard</a>
<div class="nav-link-2">
<a href="admin_profilecard.php" class="profile">
<img src="img/people.png">
</a>
</div>
</nav>
<!-- NAVBAR -->
<div id="main-content">
<h2>
<?php
if ($error) {
echo "<div class='error'> $error </div>";
}
?>
</h2>
<h2> Overview</h2>
<div class="overview">
<div class="sales">
<h2>Sales</h2>
<div class="boxes">
<div class="box">
<h4>Total sales</h4>
<p><?php echo $total_sales; ?></p>
</div>
<div class="box">
<h4>Books </h4>
<p> <?php echo $book_count; ?></p>
</div>
<div class="box">
<h4>Books Quantity</h4>
<p><?php echo $book_quantities ?></p>
</div>
</div>
</div>
<div class="order">
<h2>Orders</h2>
<div class="boxes">
<div class="box">
<h4>Pending</h4>
<p><?php echo $order_pending ?> </p>
</div>
<div class="box">
<h4>Completed</h4>
<p><?php echo $order_completed ?> </p>
</div>
<div class="box">
<h4>Cancelled</h4>
<p><?php echo $order_cancelled ?> </p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- CONTENT -->
</body>
</html>