-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis2.php
298 lines (275 loc) · 12.9 KB
/
analysis2.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
session_start();
if (!isset($_SESSION["login"])) {
header("Location: index.php");
exit;
}
require 'functions.php';
$id_user = $_SESSION["id_user"];
$date_expense = query("SELECT DATE_FORMAT(date_expense,'%M %Y') AS tanggal FROM expense WHERE id_user = '$id_user' GROUP BY YEAR (date_expense), MONTH (date_expense) ORDER BY YEAR (date_expense) DESC, MONTH (date_expense) DESC");
if (count($date_expense) >= 1) {
$date = $date_expense[0]['tanggal'];
$tgl = date_create($date);
$bulan = DATE_FORMAT($tgl, 'm');
$tahun = DATE_FORMAT($tgl, 'Y');
}
if (isset($_POST["filter"])) {
$date = $_POST['date_expense'];
$tgl = date_create($date);
$bulan = DATE_FORMAT($tgl, 'm');
$tahun = DATE_FORMAT($tgl, 'Y');
}
if (count($date_expense) >= 1) {
$expenses = query("SELECT DATE_FORMAT(date_expense,'%d') AS tanggal, SUM(budget_expense) AS budget_expense FROM expense WHERE id_user = '$id_user' AND month(date_expense)='$bulan' AND year(date_expense) = '$tahun' GROUP BY (date_expense)");
$category_expense = query("SELECT icon_category_expense, name_category_expense, SUM(budget_expense) AS budget_expense FROM expense JOIN category_expense USING(code_category_expense) WHERE id_user = '$id_user' AND month(date_expense)='$bulan' AND year(date_expense) = '$tahun' GROUP BY (code_category_expense) ORDER BY( SUM(budget_expense)) DESC");
}
if (count($date_expense) >= 1) {
foreach ($expenses as $exp) {
$label[] = $exp["tanggal"];
$data[] = $exp["budget_expense"];
}
$total = array_sum($data);
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
<link href="fontawesome/css/all.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="img/logo.png">
<title>Budget Tracker</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light d-none d-md-block bg-light fixed-top">
<div class="container-md">
<a class="navbar-brand" href="home.php">
<img src="img/logo.png" alt="" width="35" height="35" class="me-2"><span class="fw-bold">FULUSS</span>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ms-auto">
<a class="nav-link" href="home.php">Home</a>
<a class="nav-link actives" href="analysis.php">Analysis</a>
<a class="nav-link" href="goal.php">Goal</a>
<a class="nav-link" href="loan.php">Loan</a>
<a class="nav-link" href="profile.php">Profile</a>
</div>
</div>
</div>
</nav>
<!-- Bottom Navbar -->
<nav class="navbar navbar-light bg-light border-top navbar-expand d-md-none d-lg-none d-xl-none fixed-bottom">
<ul class="navbar-nav nav-justified w-100">
<li class="nav-item">
<a href="home.php" class="nav-link">
<span>
<i class="fas fa-home"></i>
</span>
</a>
</li>
<li class="nav-item">
<a href="analysis.php" class="nav-link active">
<span>
<i class="fas fa-chart-area"></i>
</span>
</a>
</li>
<li class="nav-item">
<a href="goal.php" class="nav-link">
<span>
<i class="fas fa-bullseye"></i>
</span>
</a>
</li>
<li class="nav-item">
<a href="loan.php" class="nav-link">
<span>
<i class="fas fa-money-check-alt"></i>
</span>
</a>
</li>
<li class="nav-item">
<a href="profile.php" class="nav-link">
<span>
<i class="fas fa-user"></i>
</span>
</a>
</li>
</ul>
</nav>
<section id="analysis" class="analysis">
<div class="container">
<div class="row">
<div class="col-xl-12 mt-3">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col">
<div class="d-grid gap-2">
<button class="btn btn-light" type="submit" name="submit" onclick="document.location.href='analysis.php'">Income</button>
</div>
</div>
<div class="col">
<div class="d-grid gap-2">
<button class="btn btn-danger" type="submit" name="submit" onclick="document.location.href='analysis2.php'">Expense</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<?php if (count($date_expense) >= 1) : ?>
<section id="filter" class="filter">
<div class="container">
<div class="row">
<div class="col-xl-12 mt-3">
<div class="card">
<div class="card-body">
<form action="" method="POST">
<div class="row">
<div class="col-8">
<select class="form-select" id="date_expense" name="date_expense">
<?php foreach ($date_expense as $date_exp) : ?>
<option value="<?= $date_exp["tanggal"]; ?>" <?php if ($date_exp["tanggal"] == $date) {
echo 'selected';
} ?>><?= $date_exp["tanggal"]; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col">
<div class="d-grid gap-2">
<button class="btn btn-light" type="submit" name="filter">Filter</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="info-budget" class="info-budget">
<div class="container">
<div class="row">
<div class="col-xl-12 mt-3">
<div class="card">
<div class="card-body">
<p class="card-text text-center">Expense</p>
<h3 class="card-text mt-3 text-danger text-center"><b><i class="fas fa-angle-double-down"></i> IDR <?= number_format($total, 2, ',', '.'); ?></b></h3>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="chart" class="chart">
<div class="container">
<div class="row">
<div class="col-xl-12 mt-3">
<div class="card">
<div class="card-body">
<div>
<canvas id="myChart"></canvas>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="expense" class="expense mt-5 buttom">
<div class="container">
<div class="row">
<div class="col">
<h3>Expense Details</h3>
</div>
</div>
<div class="row list mt-3">
<?php foreach ($category_expense as $expense) : ?>
<div class="col-xl-6 mb-3">
<div class="card list-expense detail">
<div class="card-body">
<div class="row d-flex align-items-center">
<div class="col-2 text-center">
<span>
<i class="fas fa-<?= $expense['icon_category_expense']; ?>"></i>
</span>
</div>
<div class="col-5">
<h6 class="card-text text-start"><?= $expense['name_category_expense']; ?></h6>
<div class="progress" style="height: 5px; width: 100%">
<div class="progress-bar bg-danger" role="progressbar" style="width: <?= round($expense['budget_expense'] / $total * 100, 0); ?>%" aria-valuenow="<?= round($expense['budget_expense'] / $total * 100, 0); ?>" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<div class="col-5">
<p class="card-text text-danger text-end"><b>IDR <?= number_format($expense['budget_expense'], 2, ',', '.'); ?></b></p>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<?php else : ?>
<section id="expense" class="expense">
<div class="container">
<div class="row">
<div class="col-xl-12 mt-3">
<div class="card list-expense empty" onclick="document.location.href = 'addExpense.php';">
<div class="card-body text-center mt-3">
<span style="font-size: 50px;">
<i class="fas fa-angle-double-down"></i>
</span>
<h3 class="card-title mt-4">Expense Empty</h3>
<p class="text-secondary">Oops! Your expense data is empty. Please add your expense data.</p>
</div>
</div>
</div>
</div>
</div>
</section>
<?php endif; ?>
<script>
const labels = <?= json_encode($label); ?>;
const data = {
labels: labels,
datasets: [{
label: '<?= $date; ?>',
data: <?= json_encode($data); ?>,
backgroundColor: '#ff006f1c',
borderColor: '#FF006F',
pointBackgroundColor: '#FF006F',
pointHitRadius: '30',
fill: true,
tension: 0.3
}]
};
const config = {
type: 'line',
data: data,
options: {
responsive: true,
maintainAspectRatio: false
}
};
const myChart = new Chart(
document.getElementById('myChart'),
config
);
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</html>