-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter-cancelled.php
326 lines (285 loc) · 12.5 KB
/
filter-cancelled.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
include('dbinfo.php');
if(isset($_POST["category"])){
if( count($_POST["category"]) > 0){
$fran_arr = $_POST["category"];
array_splice($fran_arr, 0, 1);
$franchises_sel = implode("','",$fran_arr);
$franchises_sel = "AND category.category_name IN ('" . $franchises_sel . "')";
if($franchises_sel == "AND category.category_name IN ('')"){
$franchises_sel = '';
}
}
else{
$franchises_sel = '';
}
}
else{
$franchises_sel = '';
}
if(isset($_POST["status"])){
if( count($_POST["status"]) > 0){
$status_arr = $_POST["status"];
array_splice($status_arr, 0, 1);
$status_sel = implode("','",$status_arr);
$status_sel = "AND appointment_summary.status IN ('" . $status_sel . "')";
if($status_sel == "AND appointment_summary.status IN ('')"){
$status_sel = "AND appointment_summary.status IN ('CANCELLED','REJECTED')";
}
}
else{
$status_sel = "AND appointment_summary.status IN ('CANCELLED','REJECTED')";
}
}
else{
$status_sel = "AND appointment_summary.status IN ('CANCELLED','REJECTED')";
}
$counts = array();
$count_reasons = array();
$categories = array();
$reasons = array();
$count = 0;
// $time_slots = array("09:00:00","10:00:00","11:00:00","12:00:00","13:00:00","14:00:00","15:00:00","16:00:00","17:00:00","18:00:00","19:00:00","20:00:00","21:00:00","22:00:00","23:00:00","24:00:00");
// $time_slots_str = array("9 - 10 AM","10 - 11 AM","11 - 12 AM","12 - 1 PM","1 - 2 PM","2 - 3 PM","3 - 4 PM","4 - 5 PM","5 - 6 PM","6 - 7 PM","7 - 8 PM","8 - 9 PM","9 10 PM","10 - 11 PM","11 - 12 PM");
$i = 0;
$sql1 = "SELECT count(category.category_name) as 'count', category.category_name
FROM appointment_service
LEFT JOIN appointment_summary
ON appointment_service.appointment_id=appointment_summary.appointment_id
LEFT JOIN service
ON appointment_service.service_id=service.service_id
LEFT JOIN sub_category
ON service.sub_category_id= sub_category.sub_category_id
LEFT JOIN category
ON sub_category.category_id= category.category_id
WHERE (appointment_summary.booking_date BETWEEN '" . $_POST['date-from_submit'] . " 00:00:00" . "' AND '" . $_POST['date-to_submit'] . " 00:00:00" ."')
" . $franchises_sel . " " . $status_sel . "
GROUP BY category.category_name;";
$sql2 = "SELECT count(reason.reason) as 'count', reason.reason
FROM appointment
LEFT JOIN appointment_summary
ON appointment.appointment_id=appointment_summary.appointment_id
LEFT JOIN reason
ON reason.reason_id=appointment.reason_id
WHERE (`booking_date` BETWEEN '" . $_POST['date-from_submit'] . " 00:00:00" . "' AND '" . $_POST['date-to_submit'] . " 00:00:00" ."')
" . $status_sel . "
AND reason.reason != ''
GROUP BY reason.reason;";
// print_r($sql1);
// echo count($time_slots)-1;
// for($j=0; $j < count($time_slots)-1 ; $j++){
// $result1 = $con->query($sql1);
// while($row1 = $result1->fetch_assoc()){
// $start_time_diff = strtotime($row1["time"]) - strtotime($time_slots[$j]);
// $end_time_diff = strtotime($time_slots[$j+1]) - strtotime($row1["time"]);
// // echo strtotime($row1["time"]) - strtotime($time_slots[$j]) . " - " . strtotime($time_slots[$j+1]) - strtotime($row1["time"]) . "<br>";
// if( ( $start_time_diff > 0 && $start_time_diff <= 3600 ) && ( $end_time_diff >= 0 && $end_time_diff <= 3600 ) ){
// // echo $start_time_diff . " - " . $end_time_diff . "\n";
// // echo $row1["time"] . "\n";
// $count += $row1["count"];
// // echo $count . "\n";
// }
// }
// $counts[$i] = $count;
// $i++;
// $count = 0;
// // $hex = substr(str_shuffle('ABCDEF0123456789'), 0, 6);
// // $rand_colors[$i] = '#' . $hex;
// // $rand_colors[$i] = hex2rgba($rand_colors[$i], 0.5);
// }
$result1 = $con->query($sql1);
while($row1 = $result1->fetch_assoc()){
$counts[$i] = $row1["count"];
$categories[$i] = $row1["category_name"];
$i++;
}
$i = 0;
$result2 = $con->query($sql2);
while($row2 = $result2->fetch_assoc()){
$count_reasons[$i] = $row2["count"];
$reasons[$i] = $row2["reason"];
$i++;
}
// $time_slots_str_copy = $time_slots_str;
// $counts_copy = $counts;
// // echo count($counts_copy);
// for($k = 0; $k < count($counts_copy); $k++){
// if($counts_copy[$k] == 0){
// array_splice($counts_copy, $k, 1);
// // print_r($counts_copy);
// array_splice($time_slots_str_copy, $k, 1);
// // print_r($time_slots_str_copy);
// $k--;
// }
// }
// $i = 0;
// $result2 = $con->query($sql2);
// while($row2 = $result2->fetch_assoc()){
// $count_franchises[$i] = $row2["count"];
// $franchises[$i] = $row2["franchise_name"];
// $i++;
// }
$select_str = '<option value="" disabled selected>Categories</option>';
for( $l = 0; $l < count($categories); $l++ ){
$select_str .= '<option value="' . $categories[$l] . '">' . $categories[$l] . '</option>';
}
$status_str = '<option value="" disabled selected>Status</option>';
$status_str .= '<option value="CANCELLED">Cancelled</option>';
$status_str .= '<option value="REJECTED">Rejected</option>';
// print_r($counts);
// print_r($chart_nos);
$con->close();
$json[] = array(
array( 'type' => 'bar',
'data' => array(
'labels' => $categories,
'datasets' => array( array(
'label' => 'Cancelled/Rejected Categories',
'data' => $counts,
'backgroundColor' => array(
"#ff365a",
"#34a3fa",
"#ffba00",
"#00d481",
"#50e3c2",
"#9013fe",
"#8d4234",
"#6a6a81",
"#f8970c",
"#a18d2c",
"#dfdfdf",
"#f8970c",
"#aec9a2",
"#f9565c",
"#504616",
"#70621e",
"#d278ea",
"#d787ec",
"#dc96ee",
"#e1a5f1",
"#e6b4f3",
"#ebc3f5",
"#f0d2f8",
"#cd6ae8",
"#e86ac4",
"#8e6ae8",
"#f9565c",
"#f9a256",
"#f956ae",
"#f9565c",
"#5cf956",
"#565cf9"
)
) )
),
'options' => array(
'scales' => array(
'yAxes' => array( array(
'ticks' => array(
'beginAtZero' => true
)
) )
)
)
),
array( 'type' => 'doughnut',
'data' => array(
'labels' => $categories,
'datasets' => array( array(
'data' => $counts,
'backgroundColor' => array(
"#ff365a",
"#34a3fa",
"#ffba00",
"#00d481",
"#50e3c2",
"#9013fe",
"#8d4234",
"#6a6a81",
"#f8970c",
"#a18d2c",
"#dfdfdf",
"#f8970c",
"#aec9a2",
"#f9565c",
"#504616",
"#70621e",
"#d278ea",
"#d787ec",
"#dc96ee",
"#e1a5f1",
"#e6b4f3",
"#ebc3f5",
"#f0d2f8",
"#cd6ae8",
"#e86ac4",
"#8e6ae8",
"#f9565c",
"#f9a256",
"#f956ae",
"#f9565c",
"#5cf956",
"#565cf9"
)
) )
)
),
array( $select_str ),
array( $status_str ),
array( 'type' => 'horizontalBar',
'data' => array(
'labels' => $reasons,
'datasets' => array( array(
'label' => 'Cancelled/Rejected Reasons',
'data' => $count_reasons,
'backgroundColor' => array(
"#ff365a",
"#34a3fa",
"#ffba00",
"#00d481",
"#50e3c2",
"#9013fe",
"#8d4234",
"#6a6a81",
"#f8970c",
"#a18d2c",
"#dfdfdf",
"#f8970c",
"#aec9a2",
"#f9565c",
"#504616",
"#70621e",
"#d278ea",
"#d787ec",
"#dc96ee",
"#e1a5f1",
"#e6b4f3",
"#ebc3f5",
"#f0d2f8",
"#cd6ae8",
"#e86ac4",
"#8e6ae8",
"#f9565c",
"#f9a256",
"#f956ae",
"#f9565c",
"#5cf956",
"#565cf9"
)
) )
),
'options' => array(
'scales' => array(
'xAxes' => array( array(
'ticks' => array(
'beginAtZero' => true
)
) )
)
)
),
array( $count_reasons )
);
$jsonstring = json_encode($json);
echo $jsonstring;
?>