-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmileage.php
More file actions
219 lines (183 loc) · 4.73 KB
/
mileage.php
File metadata and controls
219 lines (183 loc) · 4.73 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
<?php
//get session data
session_start();
$login_email = $_SESSION['email'];
if(!isset($_SESSION['email'])){
header("Location: /login.php");
exit();
}
include 'dbms.php';
$mileage_list = array();
$sql = "select expense.id,point,date,type,price from expense,mileage where expense.id = mileage.id and email='" . $login_email ."'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$point = $row['point'];
$date = getDate(strtotime($row['date']));
$type = $row['type'];
$price = $row['price'];
$data = array(
"point" => $point,
"date" => $date,
"type" => $type,
"price" => $price,
);
array_push($mileage_list,$data);
}
$fixed_sum_list = array();
$flexible_sum_list = array();
$waste_sum_list = array();
foreach($mileage_list as $data){
$date = $data["date"];
$key = $date['year'] . "-" . $date['mon'] ; #"0000-00"
if(!strcmp($data['type'],"Fixed")){
if(!isset($fixed_sum_list[$key])){
$fixed_sum_list[$key] = intval($data["price"]);
}else{
$fixed_sum_list[$key] += $data["price"];
}
}
if(!strcmp($data['type'],"Flexible")){
if(!isset($flexible_sum_list[$key])){
$flexible_sum_list[$key] = intval($data["price"]);
}else{
$flexible_sum_list[$key] += $data["price"];
}
}
if(!strcmp($data['type'],"Waste")){
if(!isset($waste_sum_list[$key])){
$waste_sum_list[$key] = intval($data["price"]);
}else{
$waste_sum_list[$key] += $data["price"];
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Theme Made By www.w3schools.com - No Copyright -->
<title>TEAM3'S MONEYBOOK</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<!-- chart js -->
</head>
<body>
<div class="container">
<div class="profile">
<div class="bg-1">
<div class="container text-center">
<?php
echo '<h1>' . $login_email . '</h1>';
?>
<img src="user.png" class="img-circle" alt="Bird" width="50" height="50">
</div>
</div>
</div>
<div class="graph">
<h1>Point Graph</h1>
<canvas id="myChart"></canvas>
</div>
<div class="point-history">
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Price</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<?php
foreach ($mileage_list as $data){
echo "<tr>";
echo "<th>".$data["date"]["year"]."-".$data["date"]["mon"]."-".$data["date"]["mday"]."</th>";
echo "<th>".$data["point"]."</th>";
echo "<th>".$data["type"]."</th>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</body>
<script>
<?php
$year = "2017";
$fixed_month_array = array();
$flexible_month_array = array();
$waste_month_array = array();
for($i = 1; $i < 13; $i++){
$year_month_str = $year."-".$i;
$fixed_month_sum = $fixed_sum_list[$year_month_str];
$flexible_month_sum = $flexible_sum_list[$year_month_str];
$waste_month_sum = $waste_sum_list[$year_month_str];
array_push($fixed_month_array,$fixed_month_sum);
array_push($flexible_month_array,$flexible_month_sum);
array_push($waste_month_array,$waste_month_sum);
}
?>
<?php
echo "var fixed_list = [";
for($i=0;$i < 12;$i++){
echo '"' . $fixed_month_array[$i] . '"';
if($i != 11){
echo ",";
}
}
echo "];";
echo "var flexible_list = [";
for($i=0;$i < 12;$i++){
echo '"' . $flexible_month_array[$i] . '"';
if($i != 11){
echo ",";
}
}
echo "];";
echo "var waste_list = [";
for($i=0;$i < 12;$i++){
echo '"' . $waste_month_array[$i] . '"';
if($i != 11){
echo ",";
}
}
echo "];";
?>
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx,{
type :'line',
data:{
labels: ["January", "February", "March", "April", "May", "June", "July","August","September","October","November","December"],
datasets: [
{
label: "Fixed",
fill: false,
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(139, 0, 0)',
data: fixed_list,
},
{
label: "Flexible",
fill: false,
backgroundColor: 'rgb(10, 0, 132)',
borderColor: 'rgb(255, 0, 132)',
data: flexible_list,
},
{
label: "Waste",
fill: false,
backgroundColor: 'rgb(200, 100, 250)',
borderColor: 'rgb(10, 30, 0)',
data: waste_list,
},
]
},
options: {}
});
</script>
</html>