-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.php
283 lines (242 loc) · 7.42 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
<?php
include('db.php');
session_start();
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: index.html');
exit();
}
// Get the logged-in user's ID
$user_id = $_SESSION['user_id'];
// Fetch the user's name for greeting
$user_name_query = "SELECT name FROM users WHERE id = $user_id";
$user_name_result = $conn->query($user_name_query);
$user_name = $user_name_result->fetch_assoc()['name'];
// Query to fetch bills and perform calculations
$bills_sql = "SELECT * FROM bills WHERE user_id = $user_id";
$bills_result = $conn->query($bills_sql);
// Initialize counters and totals
$total_bills = 0;
$unpaid_bills =0;
$total_amount_due = 0;
$upcoming_bills = 0;
while ($bill = $bills_result->fetch_assoc()) {
$unpaid_bills++;
if ($bill['status'] == 'Pending') {
$total_bills++;
$total_amount_due += $bill['amount'];
}
if ($bill['due_date'] >= date('Y-m-d') && $bill['due_date'] <= date('Y-m-d', strtotime('+3 days'))) {
$upcoming_bills++;
}
}
// Fetch the list of all bills for the table
$result = $conn->query($bills_sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Your Bills</title>
<link rel="stylesheet" href="style.css">
<style>
/* Global Styles */
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
color: #333;
margin: 0;
padding: 0;
}
/* Header Section */
.header {
background-color: #007bff;
padding: 20px;
text-align: center;
color: white;
font-size: 24px;
}
.header .greeting {
font-size: 20px;
margin-top: 10px;
color: #f7f7f7;
}
/* Dashboard Container */
.dashboard-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.summary-section {
display: flex;
justify-content: space-between;
margin-bottom: 30px;
}
.summary-card {
flex: 1;
margin: 10px;
padding: 20px;
background: white;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.summary-card h3 {
font-size: 18px;
color: #555;
}
.summary-card p {
font-size: 22px;
font-weight: bold;
color: #333;
}
/* Table Styles */
table {
width: 100%;
border-collapse: collapse;
background-color: #fff;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #007BFF;
color: white;
text-transform: uppercase;
font-weight: bold;
}
tr:hover {
background-color: #e6f7ff;
cursor: pointer;
}
/* Form Styles */
form {
margin-top: 20px;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
form input, form button {
margin: 10px 0;
width: 100%;
padding: 12px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
form input:focus {
border-color: #007BFF;
outline: none;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
form button {
background-color: #28a745;
color: white;
border: none;
cursor: pointer;
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
form button:hover {
background-color: #218838;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.1);
}
/* Responsive Design */
@media (max-width: 768px) {
.summary-section {
flex-direction: column;
}
th, td {
padding: 10px;
}
form {
padding: 15px;
}
}
@media (max-width: 480px) {
th, td {
padding: 8px;
}
form input, form button {
padding: 10px;
}
}
</style>
</head>
<body>
<!-- Header Section -->
<div class="header">
<h1>Bill Payment Dashboard</h1>
<div class="greeting">
<?php echo "Hey! " . htmlspecialchars($user_name); ?>
</div>
</div>
<div class="dashboard-container">
<!-- Bill Summary Section -->
<div class="summary-section">
<div class="summary-card">
<h3>Total Bills</h3>
<p><?php echo $total_bills; ?></p>
</div>
<div class="summary-card">
<h3>Total Amount Due</h3>
<p>$<?php echo number_format($total_amount_due, 2); ?></p>
</div>
<div class="summary-card">
<h3>Upcoming Bills</h3>
<p><?php echo $upcoming_bills; ?></p>
</div>
</div>
<!-- Table of Bills -->
<h2>Your Bills</h2>
<table>
<thead>
<tr>
<th>Bill Name</th>
<th>Amount</th>
<th>Due Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . htmlspecialchars($row['bill_name']) . "</td>
<td>$" . number_format($row['amount'], 2) . "</td>
<td>" . htmlspecialchars($row['due_date']) . "</td>
<td>" . htmlspecialchars($row['status']) . "</td>
</tr>";
}
} else {
echo "<tr><td colspan='4'>No bills found</td></tr>";
}
?>
</tbody>
</table>
<!-- Add New Bill Form -->
<h2>Add a New Bill</h2>
<form action="add_bill.php" method="POST">
<label for="bill_name">Bill Name:</label>
<input type="text" name="bill_name" id="bill_name" required>
<label for="amount">Amount:</label>
<input type="number" step="0.01" name="amount" id="amount" required>
<label for="due_date">Due Date:</label>
<input type="date" name="due_date" id="due_date" required>
<button type="submit">Add Bill</button>
</form>
<!-- Send Reminder Email -->
<form action="send_reminder.php" method="POST">
<button type="submit" class="send-reminder-btn">Send Reminder Email for Upcoming Bills</button>
</form>
</div>
</body>
</html>