-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrides.php
396 lines (289 loc) · 12.8 KB
/
rides.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<?php
//date_default_timezone_set("Asia/Kuala_Lumpur");
//Africa/Khartoum
date_default_timezone_set("Africa/Khartoum");
include("config.php");
//include('session.php');
?>
<html>
<head>
<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/3/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" >
<!-- Include Date Range Picker -->
<link href="jquery.datatables.yadcf.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="jquery.dataTables.yadcf.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// column constants
var ID =0;
//var S
var table = $('#requests').DataTable({
retrieve: true,
"processing": true,
"ajax": 'getRides.php',
"columnDefs": [
{
//$filters = array("passengerName" => 1 , "passenger_gender" => 2 , "driverName" => 3 ,"driver_gender" =>4, "price" => 5,"date" => 6,"time" => 7,"seconds" => 8, "status" => 9);
"targets": [ 8 ],
"visible": false
}], // end of columnDefs
responsive: true,
"pageLength": 50,
"aaSorting" : [[0, "desc"]],
// here is where you change the colors
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull )
{
if ( aData[10] == "pending" )
{
$('td', nRow).css('background-color', 'Orange');
}
else if ( aData[10] == "accepted" )
{
$('td', nRow).css('background-color', '#8D95DC');
}
else if ( aData[10] == "driver on the way" )
{
$('td', nRow).css('background-color', '#2CF51E');
}
else if ( aData[10] == "passenger on board" )
{
$('td', nRow).css('background-color', '#EA1DF9');
}
else if ( aData[10] == "canceled" )
{
$('td', nRow).css('background-color', '#F91D58');
}
}// end of colors
});// end of dataTables initialization
yadcf.init(table , [
{column_number :1, text_data_delimiter: ",", filter_type: "auto_complete"},
{column_number : 3, text_data_delimiter: ",", filter_type: "auto_complete"},
{column_number: 6 , filter_type: "range_date", date_format: "dd/mm/yyyy",filter_container_id: "dateFilter"},
{column_number : 10, data: ["noDriver", "completed","canceled","pending","accepted"], filter_default_label: "Status",filter_container_id:"statusFilter"},
{column_number : 2, data: ['male','female'], filter_default_label: "Select gender",filter_match_mode : "exact"},
{column_number : 4, data: ['male','female'], filter_default_label: "Select gender",filter_match_mode : "exact"},
{ column_number: 5, filter_type: "range_number_slider" },
]); // end of filters
/*.yadcf([
{column_number: 8,filter_container_id:"timeFilter", filter_type: "range_number_slider", data: [0,24]}
*/
//table.api({"ajax": "getRides.php"});
setInterval( function () {
table.ajax.reload();
}, 10000 );
var d = new Date();
var n = d.getHours();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = dd+'/'+mm+'/'+yyyy;
/*
yadcf.exFilterColumn(table, [
[8, {
from: n,
to: 24
}],
[
6, {
from: today
}
]
]);
*/
makeAndAttachSumaryTableHTML( getRidesDataArray() );
initializeAnalysisTable ();
updateSumaryTableWhenRideTableChangesChanges ();
});
function getRidesDataArray(){
/* this function gets the data from for the analysis table from the first table
ie., the data from the first table will be used in the second table */
var Requests_Table = $('#requests').DataTable();
var filteredDataArray = Requests_Table.rows( { filter : 'applied'} ).data();
// { filter : 'applied'}
return filteredDataArray ;
}
function makeAndAttachSumaryTableHTML (){
var sumaryTableHTML = makeSumaryTableHTML( getRidesDataArray() );
//console.log (AnalysisTableDivHTML);
$('#summaryTableDiv').html(sumaryTableHTML);
}
function makeSumaryTableHTML (filteredPoC_TableArray){
//console.log ("table array");
//console.log(filteredPoC_TableArray);
// define constants for the column numbers
var MONEY =5;
var STATUS = 10;
var no_ofRequests = filteredPoC_TableArray.length;
var no_ofCompleted=0;
var no_ofPending=0;
var no_ofAccepted=0;
var no_ofCanceled=0;
var no_ofNoDriver=0;
var money =0;
var i;
for (i=0;i<filteredPoC_TableArray.length;i++)
{
// console.log ((filteredPoC_TableArray[i][STATUS]).toLowerCase());
// calculate no_ofApprovedPoC, no_ofPendingPoC,no_ofRejectedPoC
if ( (filteredPoC_TableArray[i][STATUS]).toLowerCase() == "accepted"){
no_ofAccepted++;}
else if ( (filteredPoC_TableArray[i][STATUS]).toLowerCase() == "nodriver")
no_ofNoDriver++;
else if ( (filteredPoC_TableArray[i][STATUS]).toLowerCase() == "completed"){
no_ofCompleted++;
money += filteredPoC_TableArray[i][MONEY] ;
}
else if ( (filteredPoC_TableArray[i][STATUS]).toLowerCase() == "canceled")
no_ofCanceled++;
else if ( (filteredPoC_TableArray[i][STATUS]).toLowerCase() == "pending")
no_ofPending++;
}
// create the HTML
var analysisTableHTML;
// add the table ID and the header
analysisTableHTML= '<table id="summaryTable" style=" border: solid 1px black; width:30%;" class="display dataTable" cellspacing="0" ">\
<thead style="display:none;">\
<tr>\
<th> property </th>\
<th> value </th>\
</tr>\
</thead>';
// add the footer
// add the body of the table
analysisTableHTML +=
'<tbody>';
analysisTableHTML += '<tr style="color:#c0c0c0 background-color: black" class="borderRowColumn" ><td class="borderRowColumn">'+ "No. of Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofRequests + '</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn" ><td class="borderRowColumn">'+ "No. of Completed Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofCompleted +'</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn" ><td class="borderRowColumn">'+ "No. of Canceled Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofCanceled +'</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn"><td class="borderRowColumn">'+ "No. of No Driver Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofNoDriver +'</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn"><td class="borderRowColumn">'+ "No. of Pending Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofPending +'</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn"><td class="borderRowColumn">'+ "No. of Accepted Requests" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + no_ofAccepted +'</td></tr>';
analysisTableHTML += '<tr class="borderRowColumn"><td class="borderRowColumn">'+ "cash collected in SDG" +'</td>';
analysisTableHTML += '<td class="borderRowColumn">' + formatNo(money) +'</td></tr>';
analysisTableHTML += '</tbody></table>';
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['status', 'rides'],
['completed', no_ofCompleted],
['canceled', no_ofCanceled],
['no driver', no_ofNoDriver],
['accepted', no_ofPending],
['pending', no_ofAccepted]
]);
var options = {
title: 'rides based on status',
is3D: false,
colors:['green','orange','red','yellow','blue'],
};
// console.log("am here");
var chart = new google.visualization.PieChart(document.getElementById('ridesPiechart'));
chart.draw(data, options);
}
return analysisTableHTML;
}
function initializeAnalysisTable (){
$('#summaryTable').dataTable({
responsive: true,
"bFilter": false,
"bLengthChange": false,
"bPaginate": false,
"showNEntries": false,
"bLengthChange": false,
"bInfo" : false,
/* Disable initial sort */
"aaSorting": []
});
}
function updateSumaryTableWhenRideTableChangesChanges (){
var table = $('#requests').DataTable();
table.on( 'search.dt', function () {
$('#requests').on( 'draw.dt', function () {
setTimeout( function() // when the PoC table changes
{
//getRidesDataArray() ;
makeAndAttachSumaryTableHTML () ;
initializeAnalysisTable ();
}
, 500);
} );
} );
}
function formatNo(no ){
return (parseFloat(Math.round(no * 100) / 100).toFixed(2));
}
</script>
<style>
.title {
font-family:Georgia,serif;
color:#4E443C;
font-variant: small-caps; text-transform: none; font-weight: 100; margin-bottom: 0;
margin:auto;
font-size:30px;
text-align: center;
}
</head>
<body>
<!-- the rides-->
<?php include('welcome.php'); ?>
<div id="requestsDiv" style="width:100%; margin:auto;">
<div style="text-align: center;">
<span class = "title"> list of rides </span><br><br>
</div>
<!-- placeholder for filters-->
<div id="external_filter_container_wrapper">
<span style="color:#f08a00;" class="glyphicon glyphicon-calendar"></span> <label style="font-size:20px;">choose the date :</label><div id="dateFilter"></div><br>
<span style="color:#f08a00;" class="glyphicon glyphicon-time"></span> <label style="font-size:20px;">choose the time :</label><div id="timeFilter"></div><br>
<span style="color:#f08a00;" class="glyphicon glyphicon-user"></span> <label style="font-size:20px;" >the status :</label><div id="statusFilter"></div><br>
</div>
<table id="requests" class='display' cellspacing='0' width='100%' >
<thead>
<tr>
<th>ID</th>
<th>Passenger Name</th>
<th>Passenger Gender</th>
<th>Driver Name</th>
<th>Driver Gender</th>
<th>price</th>
<th>day</th>
<th>time</th>
<th>time in seconds</th>
<th>notes</th>
<th>status</th>
<th>acception time</th>
<th>driver on the way</th>
<th>passenger on board time</th>
<th>completion time</th>
</tr>
</thead>
</table>
</div>
<div style="text-align: center;">
<span class = "title"> summary </span><br><br>
</div>
<div id="summaryTableDiv" style="width:70%; margin:auto;">
</div>
</br>
<div id="ridesPiechart" style="width: 800px; height: 450px; border-style: solid;border-width: 2px; margin:auto;" ></div>
</body>
</html>