-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin_stat.php
More file actions
180 lines (140 loc) · 4.65 KB
/
Copy pathadmin_stat.php
File metadata and controls
180 lines (140 loc) · 4.65 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
<?php
require_once './connection/config.php';
session_start();
if (!isset($_SESSION['username']) && !$_SESSION['login_success']) {
header(" Location: admin_login.php");
exit();
}
$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'];
if($total_sales < 0 ){
$total_sales = 0;
}
} 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/boxicons@2.0.9/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 -->
</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 class="container">
<!-- Error Message -->
<?php if (!empty($error)) { ?>
<div class="error-box"><?php echo $error; ?></div>
<?php } ?>
<h2 class="dashboard-title">📊 Report Overview</h2>
<div class="dashboard">
<!-- Sales Overview -->
<div class="card sales">
<h3>💰 Sales Overview</h3>
<div class="stats">
<div class="stat">
<h4>Total Sales</h4>
<p>Rs.<?php echo number_format((float)$total_sales, 2); ?></p>
</div>
<div class="stat">
<h4>Total Books</h4>
<p><?php echo $book_count; ?></p>
</div>
<div class="stat">
<h4>Books Quantity</h4>
<p><?php echo $book_quantities; ?></p>
</div>
</div>
</div>
<!-- Orders Overview -->
<div class="card orders">
<h3>📦 Orders Overview</h3>
<div class="stats">
<div class="stat">
<h4>Pending Orders</h4>
<p><?php echo $order_pending; ?></p>
</div>
<div class="stat">
<h4>Completed Orders</h4>
<p><?php echo $order_completed; ?></p>
</div>
<div class="stat">
<h4>Cancelled Orders</h4>
<p><?php echo $order_cancelled; ?></p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- CONTENT -->
</body>
</html>