-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbudgets.php
More file actions
294 lines (266 loc) · 9.62 KB
/
Copy pathbudgets.php
File metadata and controls
294 lines (266 loc) · 9.62 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
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
284
285
286
287
288
289
290
291
292
293
294
<?php
require_once 'config.php';
if (!isLoggedIn()) header('Location: login.php');
$user_id = getUserId();
if ($_POST) {
$stmt = $pdo->prepare("REPLACE INTO budgets (user_id, category, amount, month) VALUES (?, ?, ?, YEAR(CURDATE()))");
$stmt->execute([$user_id, $_POST['category'], $_POST['amount']]);
$success = "Budget updated!";
}
$stmt = $pdo->prepare("
SELECT b.category, b.amount as budget, COALESCE(SUM(e.amount), 0) as spent
FROM budgets b
LEFT JOIN expenses e ON b.category = e.category AND e.user_id = ? AND YEAR(e.date) = YEAR(CURDATE()) AND MONTH(e.date) = MONTH(CURDATE())
WHERE b.user_id = ? AND b.month = YEAR(CURDATE())
GROUP BY b.category, b.amount
");
$stmt->execute([$user_id, $user_id]);
$budgets = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Budgets • Financial Tracker</title>
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="logo.png" type="image/png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
/* Perfect responsive background */
body.budgets-page {
background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),
url('dashboard.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
min-height: 100vh;
margin: 0;
padding: 0;
position: relative;
overflow-x: hidden;
font-family: 'Inter', sans-serif;
}
/* Perfect content overlay */
.container {
position: relative;
z-index: 2;
background: rgba(255, 255, 255, 0.97);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
min-height: 100vh;
max-width: 1400px;
margin: 0 auto;
box-shadow: 0 0 60px rgba(0,0,0,0.15);
padding: 20px;
}
/* Mobile responsiveness */
@media (max-width: 768px) {
body.budgets-page {
background-attachment: scroll;
}
.container {
background: rgba(255, 255, 255, 0.98);
margin: 0;
padding: 15px;
backdrop-filter: blur(8px);
}
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
.container {
background: rgba(15, 23, 42, 0.98);
color: #e2e8f0;
}
}
/* Reset for full coverage */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
/* Enhanced budget styling */
header {
display: flex;
align-items: center;
gap: 20px;
margin-bottom: 30px;
}
.back-btn {
display: flex;
align-items: center;
gap: 8px;
color: #6366f1;
text-decoration: none;
font-weight: 500;
padding: 12px 20px;
border-radius: 12px;
transition: all 0.3s ease;
background: rgba(99, 102, 241, 0.1);
backdrop-filter: blur(10px);
}
.back-btn:hover {
background: rgba(99, 102, 241, 0.2);
transform: translateY(-2px);
}
h1 {
margin: 0;
flex: 1;
}
.success {
background: rgba(34, 197, 94, 0.2);
border: 1px solid rgba(34, 197, 94, 0.3);
border-radius: 12px;
padding: 16px 20px;
margin-bottom: 24px;
color: #16a34a;
backdrop-filter: blur(10px);
}
.form-group {
background: rgba(255, 255, 255, 0.8);
border-radius: 16px;
padding: 24px;
margin-bottom: 32px;
backdrop-filter: blur(10px);
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.form-group select,
.form-group input {
width: 100%;
padding: 14px 16px;
border: 2px solid rgba(0,0,0,0.1);
border-radius: 12px;
font-size: 16px;
margin-bottom: 16px;
transition: all 0.3s ease;
background: rgba(255,255,255,0.9);
}
.form-group select:focus,
.form-group input:focus {
outline: none;
border-color: #6366f1;
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.btn-warning {
background: linear-gradient(135deg, #f59e0b, #d97706);
color: white;
border: none;
padding: 16px 32px;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
width: 100%;
transition: all 0.3s ease;
}
.btn-warning:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(245, 158, 11, 0.4);
}
.list-group {
display: flex;
flex-direction: column;
gap: 16px;
}
.list-item.budget {
background: rgba(255, 255, 255, 0.9);
border-radius: 16px;
padding: 20px;
border-left: 4px solid #10b981;
backdrop-filter: blur(10px);
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
transition: all 0.3s ease;
}
.list-item.budget:hover {
transform: translateY(-4px);
box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}
.budget-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
font-weight: 600;
}
.progress-bar {
width: 100%;
height: 10px;
background: rgba(0,0,0,0.1);
border-radius: 10px;
overflow: hidden;
margin-bottom: 8px;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #10b981, #34d399);
border-radius: 10px;
transition: width 0.5s ease;
}
.progress-text {
font-size: 14px;
font-weight: 500;
color: #6b7280;
}
</style>
</head>
<body class="budgets-page">
<div class="container">
<header>
<a href="dashboard.php" class="back-btn">← Dashboard</a>
<h1 style="color:purple"><i>💰 Budgets</i></h1>
</header>
<?php if (isset($success)): ?>
<div class="success"><?= $success ?></div>
<?php endif; ?>
<form method="POST" class="form-group">
<h3 style="margin-top: 0;">Set Monthly Budget</h3>
<select name="category" required>
<option value="">Select Category</option>
<option value="groceries">🛒 Groceries</option>
<option value="utilities">⚡ Utilities</option>
<option value="entertainment">🎬 Entertainment</option>
<option value="transportation">🚗 Transportation</option>
<option value="dining">🍽️ Dining Out</option>
<option value="Medical Expenses">🩺 Medical Expenses</option>
<option value="Sationary">🧾 Sationary</option>
<option value="others">📦 Others</option>
</select>
<input type="number" name="amount" placeholder="Budget Amount (₹)" step="0.01" required>
<button type="submit" class="btn btn-warning">Set Budget</button>
</form>
<h3 style="margin-bottom: 20px;">Budget Progress</h3>
<div class="list-group">
<?php foreach ($budgets as $budget):
$percentage = $budget['budget'] > 0 ? min(100, ($budget['spent'] / $budget['budget']) * 100) : 0;
?>
<div class="list-item budget">
<div class="budget-header">
<span><?= ucfirst($budget['category']) ?></span>
<span>₹<?= number_format($budget['spent'], 2) ?> / ₹<?= number_format($budget['budget'], 2) ?></span>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: <?= $percentage ?>%"></div>
</div>
<div class="progress-text"><?= round($percentage) ?>% used</div>
</div>
<?php endforeach; ?>
<?php if (empty($budgets)): ?>
<div class="list-item budget" style="text-align: center; opacity: 0.7;">
<p>No budgets set yet. Create your first budget above!</p>
</div>
<?php endif; ?>
</div>
</div>
<script>
// Auto-hide success message
setTimeout(() => {
const success = document.querySelector('.success');
if (success) {
success.style.opacity = '0';
setTimeout(() => success.remove(), 500);
}
}, 4000);
</script>
</body>
</html>