-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin-db.php
176 lines (150 loc) · 8.33 KB
/
admin-db.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
<link rel="styleSheet" href="css/admin-db.css" />
<link rel="styleSheet" href="css/sidebar.css" />
<?php
$title = 'Admin Dashboard';
include 'header.php';
include_once ('./includes/admin-config.inc.php');
?>
<?php
require 'includes/database.inc.php';
$result = mysqli_query($conn, "SELECT COUNT(memberID) FROM Member");
$totalMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COUNT(memberID) FROM Member WHERE TID = 2");
$freeMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COUNT(memberID) FROM Member WHERE TID = 1");
$premiumMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN NOW() - INTERVAL 30 DAY AND NOW()");
$totalIncome = mysqli_fetch_array($result);
echo '<script>
document.addEventListener("DOMContentLoaded", () => {
dbCounter("c1", 0, '.$totalMembers[0].', 2500);
dbCounter("c2", 0, '.$premiumMembers[0].', 2500);
dbCounter("c3", 0, '.$freeMembers[0].', 2500);
dbCounter("c4", 0, '.$totalIncome[0].', 2500);
});
</script>';
$result = mysqli_query($conn, "SELECT COUNT(memberID) FROM Membership WHERE m_status = 'Expired'");
$overdueMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COUNT(memberID) FROM Membership WHERE start_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()");
$newMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COUNT(MID)FROM Member AS M INNER JOIN Membership AS MM ON MM.memberID = M.memberID WHERE M.TID = 2 AND MM.start_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW();");
$newFreeMembers = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COUNT(MID)FROM Member AS M INNER JOIN Membership AS MM ON MM.memberID = M.memberID WHERE M.TID = 1 AND MM.start_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW();");
$newPremiumMembers = mysqli_fetch_array($result);
?>
<div class="a-container">
<?php include 'admin-sidebar.php'; ?>
<div class="db-container">
<div class="db-counter">
<div class="counter-coulmn">
<span id="c1" class="counter-item"></span>
<h4>Total members</h4>
</div>
<div class="counter-coulmn">
<span id="c2" class="counter-item"></span>
<h4>Premium members</h4>
</div>
<div class="counter-coulmn">
<span id="c3" class="counter-item"></span>
<h4>Free members</h4>
</div>
<div class="counter-coulmn">
<span id="c4" class="counter-item"></span>
<h4>Total Income (Last 30 days)</h4>
</div>
</div>
<div class="in-numbers">
<?php
echo '<div>
<div class="in-numbers-item">
<h3>Total Overdue Members:</h3>
<p>'.$overdueMembers[0].'</p>
</div>
<div class="in-numbers-item">
<h3>New Members Registerd in last 30 days:</h3>
<p>'.$newMembers[0].'</p>
</div>
<div class="in-numbers-item">
<h3>New Free Members Registerd in last 30 days:</h3>
<p>'.$newPremiumMembers[0].'</p>
</div>
<div class="in-numbers-item">
<h3>New Premium Members Registerd in last 30 days:</h3>
<p>'.$newFreeMembers[0].'</p>
</div>
</div>'
?>
</div>
<div class="graph">
<h3>Monthly Income (Past 12 Months)</h3>
<canvas class="line-graph">
</canvas>
</div>
</div>
</div>
<script src="./js/admin-db.js"></script>
<?php
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 2 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 1 month)");
$income1 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 3 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 2 month)");
$income2 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 4 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 3 month)");
$income3 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 5 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 4 month)");
$income4 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 6 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 5 month)");
$income5 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 7 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 6 month)");
$income6 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 8 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 7 month)");
$income7 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 9 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 8 month)");
$income8 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 10 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 9 month)");
$income9 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 11 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 10 month)");
$income10 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 12 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 11 month)");
$income11 = mysqli_fetch_array($result);
$result = mysqli_query($conn, "SELECT COALESCE(SUM(amount),0) FROM Payment WHERE p_datetime BETWEEN last_day(curdate() - interval 13 month) + INTERVAL 1 DAY AND last_day(curdate() - interval 12 month)");
$income12 = mysqli_fetch_array($result);
$dateMonth = 'Month';
echo "<script>
let graphData = {
'".date('Y-m', strtotime(date('Y-m').' -12 month'))."': ".$income12[0].",
'".date('Y-m', strtotime(date('Y-m').' -11 month'))."': ".$income11[0].",
'".date('Y-m', strtotime(date('Y-m').' -10 month'))."': ".$income10[0].",
'".date('Y-m', strtotime(date('Y-m').' -9 month'))."': ".$income9[0].",
'".date('Y-m', strtotime(date('Y-m').' -8 month'))."': ".$income8[0].",
'".date('Y-m', strtotime(date('Y-m').' -7 month'))."': ".$income7[0].",
'".date('Y-m', strtotime(date('Y-m').' -6 month'))."': ".$income6[0].",
'".date('Y-m', strtotime(date('Y-m').' -5 month'))."': ".$income5[0].",
'".date('Y-m', strtotime(date('Y-m').' -4 month'))."': ".$income4[0].",
'".date('Y-m', strtotime(date('Y-m').' -3 month'))."': ".$income3[0].",
'".date('Y-m', strtotime(date('Y-m').' -2 month'))."': ".$income2[0].",
'".date('Y-m', strtotime(date('Y-m').' -1 month'))."': ".$income1[0].",
};
const entries = Object.entries(graphData);
drawChart(entries);
</script>";
mysqli_close($conn);
?>
<!-- <script>
let graphData = {
'01-21': 220,
'02-21': 320,
'03-21': 700,
'04-21': 480,
'05-21': 500,
'06-21': 820,
'07-21': 345,
'08-21': 480,
'09-21': 540,
'10-21': 1000,
'11-21': 790,
'12-21': 1220,
};
const entries = Object.entries(graphData);
drawChart(entries);
</script> -->
<?php include('./footer.php'); ?>