-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes_planning.html
2971 lines (2556 loc) · 128 KB
/
routes_planning.html
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Daakiya - Route Optimization and Delivery Management</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link href="./css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="css/theme.css" rel="stylesheet"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script src="./js/date.format.js"></script>
<![endif]-->
<link rel="icon" href="./img/favicon-d.png">
</head>
<html>
<body>
<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-app.js"></script>
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-firestore.js"></script>
<!--<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase.js"></script>-->
<!--Load Access Keys -->
<script src="./accessKeys.js"></script>
<!-- Load React. -->
<!--<!– Note: when deploying, replace "development.js" with "production.min.js". –>-->
<!--<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>-->
<!--<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>-->
<!--<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>-->
<!--<script type="text/babel" src="js/order_list/order_list_view_main.js"></script>-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="./js/vendor/jquery-3.4.1.min.js"><\/script>')</script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script type="text/javascript" src="./templates/signIn_include.js"></script>
<script type="text/javascript" src="./js/moment.js"></script>
<script type="text/javascript">
//Default map center if user has not allowed location access
let latitude = 19.075983;
let longitude = 72.877655;
//Get Geolocation
function getLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Geolocation is not supported");
//Showing Default Map Location
//moveMap(map)
//moveMyMapAndMarker(latitude, longitude);
}
}
function showPosition(position){
console.log("Setting location : "+position.coords.latitude + " " + position.coords.longitude);
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
// A $( document ).ready() block.
$( document ).ready(function() {
getLocation();
console.log( "ready!" );
$("#navbarLoader").load('./templates/navbar.html')
let htmlContent = '\n' +
' <div class="row">' +
' <h3 class="col-xs-12 col-md-12 col-lg-12 text-center" >Getting your delivery fleet...</h3>\n' +
' <img src="./img/globe.gif" class="col-xs-12 col-md-12 col-lg-12" style="\n' +
' margin-top: -266px;\n' +
' z-index: -30;\n' +
' margin-left: 17px;\n' +
' "/>\n' +
' </div>';
//$("#render_container").html(htmlContent)
$("#render_container").html(htmlContent)
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
console.log("Loaded ", user)
$("#emailId").text(userDetails.email)
//Fetch all orders belonging to that user id - auth.currentUser.uid
let currentUserId = firebase.auth().currentUser.uid; //W0snQdSu0hdDUmTH85BlJKzkPTr2
console.log("currentUserId: ",currentUserId)
//getOrders(currentUserId)
//renderTimeline();
getDeliveryAssociates(currentUserId)
} else {
// No user is signed in.
window.location.href = "/";
}
});
});
async function deleteOrder (orderRef) {
try {
orderRef.setAttribute("disabled", true)
let orderNumber = orderRef.getAttribute("data-id")
console.log(orderNumber)
//Fetch records from firestore
let snapshot = await firebase.firestore().collection("orders")
.where("createdBy", "==", ""+firebase.auth().currentUser.uid)
.where("orderNumber", "==" , orderNumber).get()
snapshot.forEach(async (doc) => {
console.log("deleting",doc.data())
let isDeleted = await doc.ref.delete();
//window.location.reload()
$('#row-'+orderNumber).hide()
})
} catch (e){
console.log("Unable to delete order : ",e);
}
}
function getOrdersForThisUser () {
getOrdersFromFirestore();
}
var orderData = []
var deliveryBoysData = []
async function getOrdersFromFirestore () {
let docs;
try {
let currentUserId = firebase.auth().currentUser.uid;
let startTimeRange = $("#startTimeRange").val();
console.log("startTimeRange : "+startTimeRange)
let endTimeRange = $("#endTimeRange").val();
console.log("endTimeRange : "+endTimeRange)
//Validate data otherwise throw an error
let isValidated = true;
if (startTimeRange == "" || startTimeRange == undefined){
$("#startTimeRange").addClass("background-input")//background-input
isValidated = false;
}
if (endTimeRange == "" || endTimeRange == undefined){
$("#endTimeRange").addClass("background-input")
isValidated = false;
}
if ($("#tripName").val() == undefined || $("#tripName").val() == "") {
$("#tripName").addClass("background-input")
isValidated = false;
}
if (isValidated == false){
return;
}
getOrders();
showScreen2();
//firebase.firestore().collection("orders").where("createdBy", "==", "W0snQdSu0hdDUmTH85BlJKzkPTr2").orderBy("creationDate", "desc").get();
docs = await firebase.firestore().collection("orders")
.where("createdBy", "==", currentUserId+"")
.where("status", "==", "NEW"+"")
.where("eta", ">=", startTimeRange)//"2019-06-19T02:22")
.where("eta", "<=", endTimeRange)//"2019-06-29T02:22"+"")
.orderBy("eta", "asc").get();
//console.log("docs.length : "+docs.length)
}
catch (e) {
console.log("error: ",e);
}
console.log("Total orders : "+docs.docs.length)
renderOrders (docs.docs);
}
async function getDeliveryAssociates (currentUserId) {
let docs;
try {
//firebase.firestore().collection("orders").where("createdBy", "==", "W0snQdSu0hdDUmTH85BlJKzkPTr2").orderBy("creationDate", "desc").get();
docs = await firebase.firestore().collection("delivery_associates")
.where("createdBy", "==", currentUserId+"")
.where("status", "==", "AVAILABLE")
.get();
}
catch (e) {
console.log("error: ",e);
}
console.log("Total orders : "+docs.docs.length)
renderDeliveryAssociates (docs.docs);
}
function renderDeliveryAssociates (docs) {
try {
let htmlContent = ''
// ' <div class="row">\n' +
// ' <div class="col-xs-12 col-md-12 col-lg-2"></div>\n' +
// '\n' +
// ' <div class="col-xs-12 col-md-12 col-lg-7">\n' +
// ' <h4 class="text-center">No Delivery Associates present, Please add your fleet\n' +
// // ' <img src="./img/bluBox.png"/>\n' +
// ' </h4>\n' +
// ' </div>\n' +
// ' </div>\n' +
// ' \n' +
// ' <hr/>'
if (docs.length == 0){
$("#render_container").html(htmlContent)
}
else {
htmlContent = "";
//htmlContent += '<div class="row">' +
docs.forEach((doc) => {
let currentDocument = doc.data();
deliveryBoysData.push(currentDocument)
console.log(doc.id +" "+ doc.data())
let format = ""
let statusFlagColor = "";
try {
if (currentDocument.custAddress == undefined) {
currentDocument.custAddress = "Not available";
}
if ((currentDocument.status+"").toUpperCase() == "AVAILABLE"){
statusFlagColor = "success";
}
else {
statusFlagColor = "warning";
}
}catch (e){
console.log("Unable to format dates",e)
}
htmlContent += '\n' +
' <div class="col-xs-12 col-md-12 col-lg-3 thumbnail boxPadding orderRow rowToBeSelected " onclick="selectDeliveryAssociate(this)" id="'+ doc.id +'" >\n' +
' <h4>'+currentDocument.associateName+'</h4>\n' +
' <p><b>Status</b> :\n' +
' <span class="label label-'+statusFlagColor+'">'+currentDocument.status+'</span>\n' +
' <br>\n' +
' <b>Emp# </b> : 274534<br>\n' +
' <b>Address</b> : IIT Powai, Near Powai Lake, Hiranandani, Andheri (East), Mumbai - 400003</p>\n' +
'\n' +
' <!-- Edit, Mark Complete, Delete, <span class="label label-danger">Non Geocoded</span>-->\n' +
// ' <button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">\n' +
// ' Track<span class="glyphicon glyphicon-map-marker"></span>\n' +
// ' </button>' +
'<button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">\n' +
' Select\n' +
' </button>\n' +
' </div>'
})
htmlContent += '</div>\n' +
$("#render_container").html(htmlContent)
}
}catch (e) {
console.log(e)
}
}
var deliveryAssociate = [];
/**
* Will select delivery associate
* */
function selectDeliveryAssociate (row) {
let currentDeliveryBoyId = row.getAttribute("id");
//If rowSelected does not exists? add that row otherwise deselect that row
if ($('#'+row.getAttribute("id")+'').hasClass('rowSelected') == false) {
if ($('#'+row.getAttribute("id")+'').hasClass('rowDeSelected')) {
$('#'+row.getAttribute("id")+'').removeClass('rowDeSelected')
}
//row.addClass("rowSelected")
$('#'+row.getAttribute("id")+'').addClass('rowSelected')
//Add Element to array
//if (orders.indexOf(currentOrderId) == false) {
deliveryAssociate.push(currentDeliveryBoyId)
}
else {
//row.addClass("rowSelected")
//Add Class rowDeSelected
//
$('#'+row.getAttribute("id")+'').removeClass('rowSelected')
$('#'+row.getAttribute("id")+'').addClass('rowDeSelected')
//orders.pop(currentOrderId);
deliveryAssociate = deliveryAssociate.filter(function(ele){ return ele != currentDeliveryBoyId; });
}
if (deliveryAssociate.length >= 1) {
//Remove attribute - disabled="true" from Finalize Trip Button - #finalizeTrip
document.getElementById("finalizeTrip").removeAttribute("disabled")
}
else {
//Add Attribute - disabled = true to finalize trip button
document.getElementById("finalizeTrip").setAttribute("disabled", "true");
}
console.log("deliveryAssociate: ",deliveryAssociate)
}
/**
* Will Select Orders
* @param row
*/
function selectRow (row) {
//console.log(row)
let currentOrderId = row.getAttribute("id");
//If rowSelected does not exists? add that row otherwise deselect that row
if ($('#'+row.getAttribute("id")+'').hasClass('rowSelected') == false) {
if ($('#'+row.getAttribute("id")+'').hasClass('rowDeSelected')) {
$('#'+row.getAttribute("id")+'').removeClass('rowDeSelected')
}
//row.addClass("rowSelected")
$('#'+row.getAttribute("id")+'').addClass('rowSelected')
//Add Element to array
//if (orders.indexOf(currentOrderId) == false) {
orders.push(currentOrderId)
}
else {
//row.addClass("rowSelected")
//Add Class rowDeSelected
//
$('#'+row.getAttribute("id")+'').removeClass('rowSelected')
$('#'+row.getAttribute("id")+'').addClass('rowDeSelected')
//orders.pop(currentOrderId);
orders = orders.filter(function(ele){ return ele != currentOrderId; });
}
console.log(orders)
if (orders.length >= 1){
//Enable Next button - // #nextButtonSelectDeliveryBoys
document.getElementById("nextButtonSelectDeliveryBoys").removeAttribute("disabled")
//$("#nextButtonSelectDeliveryBoys").removeAttribute("disabled");
}
else {
//$("#nextButtonSelectDeliveryBoys").setAttribute("disabled", "true");
document.getElementById("nextButtonSelectDeliveryBoys").setAttribute("disabled", "true");
}
}
function distinct(value, index, self) {
return self.indexOf(value) === index;
}
async function completeOrder (orderNumber, status){
try {
//
// let doc = await firebase.firestore().collection("orders").where("orderNumber", "==", ""+orderNumber).get()
await firebase.firestore().collection("orders").where("orderNumber", "==", ""+orderNumber)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
// Build doc ref from doc.id
firebase.firestore().collection("orders").doc(doc.id).update({status: status});
// $('#myModal').modal({show : true})
});
}).catch(function (error) {
console.log("Unable to mark order "+status+": ",error)
})
//console.log(doc.ref.update({status: "COMPLETED"}))
}catch (error) {
console.log("Unable to mark order "+status+": ",error)
}
}
async function planTrip () {
try {
console.log("Planning Trip...");
await $("#screen3").fadeOut("700", function () {
$("#screen4").fadeIn("300")
});
//Get all orders
console.log("order: ", orders);
console.log("orderData: ", orderData);
//let selectedOrders = [];
//Select those order objects where Document.orderID was present in orders array - //Get all orders with those Order Numbers present in Orders Array
let selectedOrders = [];
for (let i = 0; i < orders.length; i++){
let order = orders[i]
completeOrder(order+"", "INTRANSIT")
//order;//Current Order
let doc = await firebase.firestore().collection("orders")
.where("createdBy", "==", "" + firebase.auth().currentUser.uid)
.where("orderNumber", "==", order).get()
await doc.forEach(async (orderRecord) => {
selectedOrders.push(orderRecord.data())
console.log("adding : ", orderRecord.data())
});
}
//selectedOrders = selectedOrders.filter( distinct );
console.log("selectedOrders: "+selectedOrders)
//Get All Delivery Associates
console.log("deliveryAssociate: ", deliveryAssociate);
console.log("deliveryBoysData : ", deliveryBoysData);
let selectedDBs = [];
for (let i = 0; i < deliveryAssociate.length; i++){
let deliveryAssociateId = deliveryAssociate[i]
//order;//Current Order
let doc = await firebase.firestore().collection("delivery_associates")
.doc(deliveryAssociateId).get()
console.log("DB Data: ",doc.data());
selectedDBs.push(doc.data())
}
console.log("selectedDBs: ",selectedDBs)
//Get Service Time - id="serviceTime"
let serviceTime = $("#serviceTime").val();
//Change Service Time to zero if it is invalid
if (serviceTime <= 0) {
serviceTime = 0;
}
//Add 60 seconds to service time - eg 15 * 60 as the Waypoints API takes in time
serviceTime = serviceTime * 60;
//If Order Numbers len <= 1
if (selectedOrders.length <= 0){
console.log("No Orders present for planning..");
return;
}
//If DB.len <= 1
if (selectedDBs.length <= 0) {
console.log("No delivery boys present at the moment")
}
//Set all order statuses to INTRANSIT
//Set DB Status to INTRANSIT
//Construct a URL like below
// let waypointsURL = 'https://wse.api.here.com/2/findsequence.json' +
// '?departure=2019-09-09T16:52:00Z' +
// '&start=Order1;52.52282,13.37011;' +
// '&destination2=Order2;52.50341,13.44429;at:2019-09-10T16:52:00Z;st:1800' +
// '&destination3=Order3;52.51293,13.24021;at:2019-09-11T16:52:00Z;st:1800' +
// '&end=Order4;52.53066,13.38511;at:2019-09-12T16:52:00Z;st:1800' +
// '&mode=fastest;car;traffic:enabled' +
// '&app_code='+module_HEREDeveloperAccess.app_id+
// '&app_id='+module_HEREDeveloperAccess.app_id
let waypointsURL = 'https://wse.api.here.com/2/findsequence.json?' +
// '?departure=2019-09-09T16:52:00Z' +
// '&start=Order1;52.52282,13.37011;' +
// '&destination2=Order2;52.50341,13.44429;at:2019-09-10T16:52:00Z;st:1800' +
// '&destination3=Order3;52.51293,13.24021;at:2019-09-11T16:52:00Z;st:1800' +
// '&end=Order4;52.53066,13.38511;at:2019-09-12T16:52:00Z;st:1800' +
'mode=fastest;car;traffic:enabled' +
'&app_code='+module_HEREDeveloperAccess.app_code+
'&app_id='+module_HEREDeveloperAccess.app_id;
for (let i=0; i< selectedOrders.length; i++) {
let currentOrder = selectedOrders[i];
//Get its orderNumber
let currentOrderNumber = currentOrder.orderNumber;
//
//
//Get its eta : Append - ':00Z' after - DateTime - <2019-09-09T16:52>
let eta = currentOrder.eta + ":00Z";
//Get Position Params
let position = currentOrder.position;
//If i=0 enter Departure and Start- // Enter ETA as departure
if (i==0) {
waypointsURL +=
"&departure="+eta+//":00Z"+
'&start='+currentOrderNumber+';'
+position[0]+','+position[1]+';' ;
}
//If i=length-1 Enter 'end' header parameter and not destinationN
else if (i == selectedOrders.length - 1) {
waypointsURL +=
'&end='+currentOrderNumber+';'
+position[0]+','+position[1]
+';at:'+eta+';st:'+serviceTime;
}
else {
waypointsURL +=
'&destination'+i+'='+currentOrderNumber+';' +
''+position[0]+','+position[1]+';at:'+eta+';st:'+serviceTime;
}
}
console.log("waypointsURL: "+waypointsURL);
//Call waypoints API
// await $.ajax({
// //https://wse.api.here.com/2/findsequence.json?departure=2019-09-09T16:52:00Z&start=Order1;52.52282,13.37011;&destination2=Order2;52.50341,13.44429;at:2019-09-10T16:52:00Z;st:1800&destination3=Order3;52.51293,13.24021;at:2019-09-11T16:52:00Z;st:1800&end=Order4;52.53066,13.38511;at:2019-09-12T16:52:00Z;st:1800&mode=fastest;car;traffic:enabled&app_code=53DQ_ew0UvU1KmWtUJQDYQ&app_id=st58tn5HdBdzSlMNw5OX
// url: waypointsURL,
// dataType: 'json',
// type: 'get',
// contentType: 'application/json',
// processData: false,
// success: function( data, textStatus, jQxhr ){
// //$('#response pre').html( JSON.stringify( data ) );
// console.log("data", data);
// //resolve(data)
// },
// error: function( jqXhr, textStatus, errorThrown ){
// console.log( errorThrown );
// //reject(jqXhr)
// }
// });
let waypointsResponse = await getWaypointsData(waypointsURL)
if (waypointsResponse.results.length <=0 ) {
console.log("Unable to create a route plan "+waypointsResponse)
throw new Error ("Unable to create a route plan.");
}
//FadeOut for location loader
let doc = {
tripName: $("#tripName").val(),
tripStatus : "NEW",
waypointsData : waypointsResponse,
orders : orders,
assignedDeliveryAssociate : selectedDBs[0],
createdAt : new Date().getTime(),
createdBy : firebase.auth().currentUser.uid
}
//Add Routes output to firestore
let documentAdd = await firebase.firestore().collection("routes").add(doc);
console.log(documentAdd)
if (documentAdd) {
console.log("document successfully added..")
}
else {
console.log("Unable to add route data...")
}
//For fetching data - firebase.firestore().collection("routes").doc("Aqj1xqHMg1UY66kezJvu").get().then((doc) => {console.log(doc.data())})
//Render output to screen5 - timelineList
await renderTimeline(waypointsResponse)
console.log(serviceTime)
}
catch (e) {
let htmlContent = '<div id="" style="">\n' +
' <br>\n' +
' <h2 class="text-center">Error while planning, Please try after some time</h2>\n' +
' </div>'
$("#renderTimeline").html(htmlContent)
//Fadeout location loader and show timeline
$("#screen4").fadeOut("150", function () {
$("#renderTimeline").fadeIn(300)
})
console.log(e)
}
}
function getWaypointsData (waypointsURL) {
return new Promise ((resolve,reject) => {
$.ajax({
//https://wse.api.here.com/2/findsequence.json?departure=2019-09-09T16:52:00Z&start=Order1;52.52282,13.37011;&destination2=Order2;52.50341,13.44429;at:2019-09-10T16:52:00Z;st:1800&destination3=Order3;52.51293,13.24021;at:2019-09-11T16:52:00Z;st:1800&end=Order4;52.53066,13.38511;at:2019-09-12T16:52:00Z;st:1800&mode=fastest;car;traffic:enabled&app_code=53DQ_ew0UvU1KmWtUJQDYQ&app_id=st58tn5HdBdzSlMNw5OX
url: waypointsURL,
dataType: 'json',
type: 'get',
contentType: 'application/json',
processData: false,
success: function( data, textStatus, jQxhr ){
//$('#response pre').html( JSON.stringify( data ) );
console.log("data", data);
resolve(data)
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
reject(jqXhr)
}
});
}) ;
}
function renderOrders (docs) {
try{
let htmlContent = '\n' +
' <div class="row">\n' +
' <div class="col-xs-12 col-md-12 col-lg-2"></div>\n' +
'\n' +
' <div class="col-xs-12 col-md-12 col-lg-7">\n' +
' <h4 class="text-center">No Orders available at this moment, Please add orders\n' +
' <img src="./img/bluBox.png"/>\n' +
' </h4>\n' +
' </div>\n' +
' </div>\n' +
' \n' +
' <hr/>'
if (docs.length == 0){
$("#plannedOrders").html(htmlContent)
}
else {
htmlContent = "";
docs.forEach((doc) => {
let currentDocument = doc.data();
orderData.push(currentDocument);
let format = ""
let statusFlagColor = "";
try {
if (currentDocument.eta != "" && currentDocument.eta != undefined) {
let eta = new Date((currentDocument.eta));
format = moment(eta).format('MMMM Do YYYY, h:mm:ss a');;//(eta, "dddd, mmmm dS, yyyy, h:MM:ss TT");
if (format == ""){
format = moment(eta).format('MMMM Do YYYY');
}
}
if (currentDocument.custAddress == undefined) {
currentDocument.custAddress = "Not available";
}
if ((currentDocument.status+"").toUpperCase() == "NEW"){
statusFlagColor = "success";
}
else if ((currentDocument.status+"").toUpperCase() == "INTRANSIT"){
statusFlagColor = "warning";
}
else if ((currentDocument.status+"").toUpperCase() == "COMPLETED"){
statusFlagColor = "info";
}
else if ((currentDocument.status+"").toUpperCase() == "CANCELLED"){
statusFlagColor = "danger";
}
else {
statusFlagColor = "info";
}
}catch (e){
console.log("Unable to format dates",e)
}
htmlContent += '\n' +
'<div class="row order orderRow rowToBeSelected" onclick="selectRow(this)" id="'+currentDocument.orderNumber+'" style="">\n' +
'\n' +
' <img src="https://image.maps.api.here.com/mia/1.6/mapview?c='+currentDocument.position[0]+'%2C'+currentDocument.position[1]+'&z=14&w=250&h=120&f=1&app_id='+module_HEREDeveloperAccess.app_id+'&app_code='+module_HEREDeveloperAccess.app_code+'"\n' +
' class="col-xs-12 col-md-12 col-lg-3 thumbnail "/>\n' +
'\n' +
' <div class="col-xs-12 col-md-12 col-lg-7">\n' +
' <h4>Order# - '+currentDocument.orderNumber+'</h4>\n' +
' <p><b>Status</b> : <span class="label label-'+statusFlagColor+'">'+currentDocument.status+'</span> <br>\n' +
' <b>ETA</b> : '+format+'<br>\n' +
' <b>Customer</b> : '+ currentDocument.customerName+'<br>\n' +
' <b>Address</b> : '+currentDocument.custAddress+'</p>\n' +
' </div>\n' +
'\n' +
' <div class="buttons col-xs-12 col-md-12 col-lg-2">\n' +
' <button type="button" style="margin:5px" class="col-xs-2 col-md-3 col-lg-11 btn btn-default">\n' +
' Select\n' +
' </button>\n' +
' </div>\n' +
' </div>' +
'' +
// ' <div class="row" id="row-'+currentDocument.orderNumber+'">\n' +
// '\n' +
// ' <img src="https://image.maps.api.here.com/mia/1.6/mapview?c='+currentDocument.position[0]+'%2C'+currentDocument.position[1]+'&z=14&w=250&h=120&f=1&app_id='+module_HEREDeveloperAccess.app_id+'&app_code='+module_HEREDeveloperAccess.app_code+'"\n' +
// ' class="col-xs-12 col-md-12 col-lg-3 thumbnail "/>\n' +
// '\n' +
// ' <div class="col-xs-12 col-md-12 col-lg-7">\n' +
// ' <h4>Order# - '+currentDocument.orderNumber+'</h4>\n' +
// ' <p><b>Status</b> : <span class="label label-'+statusFlagColor+'">'+currentDocument.status+'</span> <br/>\n' +
// ' <b>ETA</b> : '+format+'<br/>\n' +
// ' <b>Customer</b> : '+ currentDocument.customerName+' <br/>\n' +
// ' <b>Address</b> : '+currentDocument.custAddress+'</p>\n' +
// '\n' +
// ' <!-- Edit, Mark Complete, Delete, <span class="label label-danger">Non Geocoded</span>-->\n' +
// ' </div>\n' +
// '\n' +
// ' <div class="buttons col-xs-12 col-md-12 col-lg-2">\n' +
// ' <a href="./order_edit_form.html?orderNumber='+currentDocument.orderNumber+'" type="button" style="margin:5px" class="col-xs-2 col-md-3 col-lg-11 btn btn-default">\n' +
// ' Edit\n' +
// ' </a>\n' +
// ' <button type="button" onclick="deleteOrder(this)" data-id="'+currentDocument.orderNumber+'" style="margin:5px" class="col-xs-2 col-md-3 col-lg-11 btn btn-default">\n' +
// ' Delete\n' +
// ' </button>\n' +
// '\n' +
// ' <div class = "btn-group">\n' +
// ' <button type = "button" style="margin:5px" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">\n' +
// ' More Option\n' +
// ' <span class = "caret"></span>\n' +
// ' </button>\n' +
// '\n' +
// ' <ul class = "dropdown-menu" role = "menu">\n' +
// ' <li><a href = "#">Mark Order Complete</a></li>\n' +
// ' <li><a href = "#">Mark In Transit</a></li>\n' +
// ' <li><a href = "#">Order Cancelled</a></li>\n' +
// '\n' +
// ' <li class = "divider"></li>\n' +
// ' <li><a href = "#">Navigate to order</a></li>\n' +
// ' </ul>\n' +
// ' </div>\n' +
'\n' +
' </div>\n' +
'\n' +
// ' </div>\n' +
' '
})
$("#plannedOrders").html(htmlContent)
}
}catch (e) {
console.log(e)
}
}
</script>
<!-- Fixed navbar -->
<!--<nav class="navbar navbar-inverse navbar-fixed-top">-->
<!-- <div class="container">-->
<!-- <div class="navbar-header">-->
<!-- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">-->
<!-- <span class="sr-only">Toggle navigation</span>-->
<!-- <span class="icon-bar"></span>-->
<!-- <span class="icon-bar"></span>-->
<!-- <span class="icon-bar"></span>-->
<!-- </button>-->
<!-- <a class="navbar-brand col-xs-1 col-md-2 col-lg-2" href="#">Daakiya</a>-->
<!-- </div>-->
<!-- <div id="navbar" class="navbar-collapse collapse">-->
<!-- <ul class="nav navbar-nav col-xs-12 col-md-6 col-lg-6">-->
<!-- <li><a href="#">Dashboard</a></li>-->
<!-- <li><a href="#">Delivery Associates</a></li>-->
<!-- <li><a href="#">Orders</a></li>-->
<!-- <li><a href="#">Routes</a></li>-->
<!-- <!– <li class="dropdown">–>-->
<!-- <!– <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>–>-->
<!-- <!– <ul class="dropdown-menu">–>-->
<!-- <!– <li><a href="#">Action</a></li>–>-->
<!-- <!– <li><a href="#">Another action</a></li>–>-->
<!-- <!– <li><a href="#">Something else here</a></li>–>-->
<!-- <!– <li role="separator" class="divider"></li>–>-->
<!-- <!– <li class="dropdown-header">Nav header</li>–>-->
<!-- <!– <li><a href="#">Separated link</a></li>–>-->
<!-- <!– <li><a href="#">One more separated link</a></li>–>-->
<!-- <!– </ul>–>-->
<!-- <!– </li>–>-->
<!-- </ul>-->
<!-- <ul class="nav navbar-nav col-xs-12 col-md-4 col-lg-3" style="float: right;">-->
<!-- <li><a href="#" class="navbar-nav" >[email protected]</a></li>-->
<!-- <li><a href="#" class="navbar-nav" >Logout</a></li>-->
<!-- </ul>-->
<!-- </div><!–/.nav-collapse –>-->
<!-- </div>-->
<!--</nav>-->
<div id="navbarLoader"></div>
<style type="text/css">
.background-input {
background-color:#d9edff;
color:#000;
}
.thumbnail {
padding: 4px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
display: inline-block;
max-width: 100%;
height: auto;
box-shadow: 0 1px 2px rgba(0,0,0,.075);
}
.header {
margin-top: -19px;
margin-bottom: 29px;
background: linear-gradient(45deg, #083100 0%, #336d61 100%);
box-shadow: 0px 8px 31px 0px #0e0b0b96 inset;
padding-top: 28px;
padding-bottom: 27px;
color: #ececec;
text-shadow: 1px 1px 1px #000;
background: linear-gradient(45deg, #0e1d0c 0%, #335a6d 100%)
/*linear-gradient(45deg, #0e1d0c00 0%, #00000036 100%);*/
}
.header .dropdown-menu {
text-shadow: 0px 0px 0px #000;
}
</style>
<div class="header">
<div class="container">
<div class="">
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-6"><h1>Route Planning</h1></div>
<div class="col-xs-12 col-md-12 col-lg-6" style="margin-top: 15px;">
<div class = "col-xs-3 col-md-3 col-lg-2 btn-group">
<!-- <button type = "button" style="margin:5px" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">-->
<!-- Filter By-->
<!-- <span class = "caret"></span>-->
<!-- </button>-->
<!-- <ul class = "dropdown-menu" role = "menu">-->
<!-- <li><a href = "#">All New Orders</a></li>-->
<!-- <li><a href = "#">All In Transit Orders</a></li>-->
<!-- <li><a href = "#">All Completed Orders</a></li>-->
<!-- <li><a href = "#">All Cancelled Orders</a></li>-->
<!-- </ul>-->
</div>
<div class = "col-xs-9 col-md-9 col-lg-2 btn-group">
<!-- <button type = "button" style="margin:5px" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">-->
<!-- Sort By-->
<!-- <span class = "caret"></span>-->
<!-- </button>-->
<!-- <ul class = "dropdown-menu" role = "menu">-->
<!-- <li><a href = "#">Sort by last added date desc</a></li>-->
<!-- <li><a href = "#">Order Number desc</a></li>-->
<!-- <li><a href = "#">Customer Name desc</a></li>-->
<!-- <li><a href = "#">Sort by last added date asc</a></li>-->
<!-- <li><a href = "#">Order Number asc</a></li>-->
<!-- <li><a href = "#">Customer Name asc</a></li>-->
<!-- </ul>-->
</div>
<div class="col-xs-7 col-md-6 col-lg-4" style="margin-left: -20px;">
<!-- <input type="email" style="margin-top: 5px; margin-left: 20px;" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Search Order Number" />-->
</div>
<!-- <button class="col-xs-3 col-md-3 col-lg-2 btn btn-primary" type="button" style="margin:5px">-->
<!-- Search <span class="glyphicon glyphicon-search"></span>-->
<!-- </button>-->
<!-- <button class="col-xs-2 col-md-2 col-lg-1 btn btn-primary" type="button" style="margin: 5px;border-radius: 82px;width: 40px;border: 1px solid #FFF;">-->
<!-- <span class="glyphicon glyphicon-plus" style=""></span>-->
<!-- <!– </button>–>-->
<!-- <a href="./delivery_associate_add_form.html" class="col-xs-6 col-md-6 col-lg-4 btn btn-primary" type="button" style="margin: 5px;border-radius: 82px;width: 135px;border: 1px solid #FFF;">-->
<!-- Create Plan <span class="glyphicon glyphicon-plus" style=""></span>-->
<!-- </a>-->
</div>
</div>
</div>
</div>
</div>
<div class="container" role="main">
<!-- <div class="row">-->
<!-- <h3 class="col-xs-12 col-md-12 col-lg-12 text-center" >Hang Tight, Fetching orders...</h3>-->
<!-- <img src="./img/globe.gif" class="col-xs-12 col-md-12 col-lg-12" style="-->
<!-- margin-top: -266px;-->
<!-- z-index: -30;-->
<!-- margin-left: 17px;-->
<!-- "/>-->
<!-- </div>-->
<style type="text/css">
.boxPadding {
margin-left: 0px;
padding-left: 13px;
padding-bottom: 6px;
padding-top: 10px;
}
</style>
<div class="row">
<!-- -->
<!-- <div class="col-xs-12 col-md-12 col-lg-3 thumbnail boxPadding" >-->
<!-- <h4>Franz Ferdinand</h4>-->
<!-- <p><b>Status</b> :-->
<!-- <span class="label label-success">AVAILABLE</span>-->
<!-- <br>-->
<!-- <b>Emp# </b> : 274534<br>-->
<!-- <b>Address</b> : IIT Powai, Near Powai Lake, Hiranandani, Andheri (East), Mumbai - 400003</p>-->
<!-- <!– Edit, Mark Complete, Delete, <span class="label label-danger">Non Geocoded</span>–>-->
<!-- <button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Track<span class="glyphicon glyphicon-map-marker"></span>-->
<!-- </button><button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Delete-->
<!-- </button>-->
<!-- </div>-->
<!-- <div class="col-xs-12 col-md-12 col-lg-3 thumbnail boxPadding" >-->
<!-- <h4>Franz Ferdinand</h4>-->
<!-- <p><b>Status</b> :-->
<!-- <span class="label label-success">AVAILABLE</span>-->
<!-- <br>-->
<!-- <b>Emp# </b> : 274534<br>-->
<!-- <b>Address</b> : IIT Powai, Near Powai Lake, Hiranandani, Andheri (East), Mumbai - 400003</p>-->
<!-- <!– Edit, Mark Complete, Delete, <span class="label label-danger">Non Geocoded</span>–>-->
<!-- <button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Track<span class="glyphicon glyphicon-map-marker"></span>-->
<!-- </button><button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Delete-->
<!-- </button>-->
<!-- </div>-->
<!-- <div class="col-xs-12 col-md-12 col-lg-3 thumbnail boxPadding" >-->
<!-- <h4>Franz Ferdinand</h4>-->
<!-- <p><b>Status</b> :-->
<!-- <span class="label label-success">AVAILABLE</span>-->
<!-- <br>-->
<!-- <b>Emp# </b> : 274534<br>-->
<!-- <b>Address</b> : IIT Powai, Near Powai Lake, Hiranandani, Andheri (East), Mumbai - 400003</p>-->
<!-- <!– Edit, Mark Complete, Delete, <span class="label label-danger">Non Geocoded</span>–>-->
<!-- <button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Track<span class="glyphicon glyphicon-map-marker"></span>-->
<!-- </button><button type="button" style="margin:5px" class="col-xs-2 col-md-3 btn btn-default">-->
<!-- Delete-->
<!-- </button>-->
<!-- </div>-->
<!-- <div class="col-xs-12 col-md-12 col-lg-3 thumbnail boxPadding" >-->
<!-- <h4>Franz Ferdinand</h4>-->