From 64689543164747503c0f30af848822e197e5e12b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Sat, 25 Jan 2020 06:08:14 +0000 Subject: [PATCH 01/11] Display hubs and riders in non-dynamic table for onestep edit. #312 --- .../job-order/cmb.form.onestep.html.twig | 71 +++++++++++++------ templates/job-order/form.onestep.html.twig | 27 +++++++ 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 1b043791..947de9c5 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -380,17 +380,19 @@ Hub Branch - Contact Numbers Action + {% if mode in ['onestep-edit'] %} + {% for hub in hubs %} + + {{ hub.hub.getName }} + {{ hub.hub.getBranch }} + {{ hub.hub.getContactNumbers }} + {% endfor %} + {% endif %} @@ -422,6 +424,24 @@ + {% if mode in ['onestep-edit'] %} + {% set avail_riders = obj.getHub.getAvailableRiders|default([]) %} + + + No riders available. + + + + {% if obj.getHub %} + {% for rider in avail_riders %} + + {{ rider.getFirstName }} + {{ rider.getLastName }} + {{ rider.getContactNumber }} + {{ rider.getPlateNumber }} + {% endfor %} + {% endif %} + {% endif %} @@ -623,25 +643,28 @@ $(function() { var marker = L.marker([lat, lng], { icon: icon_customer }); - // get nearest hubs ajax - var hub_table = ''; - $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { - var hubs = data['hubs']; - for (i in hubs) { - var hub = hubs[i]; - var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); - hubLayerGroup.addLayer(hub_marker); + {% if mode in ['onestep'] %} + // get nearest hubs ajax + var hub_table = ''; + $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { + var hubs = data['hubs']; + for (i in hubs) { + var hub = hubs[i]; + var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); + hubLayerGroup.addLayer(hub_marker); - hub_table += ''; - hub_table += '' + hub['name'] + ''; - hub_table += '' + hub['branch'] + ''; - hub_table += '' + hub['cnum'] + ''; - hub_table += ''; - hub_table += ''; - } + hub_table += ''; + hub_table += '' + hub['name'] + ''; + hub_table += '' + hub['branch'] + ''; + hub_table += '' + hub['cnum'] + ''; + hub_table += ''; + hub_table += ''; + } - $('#nearest_hubs').html(hub_table); - }); + $('#nearest_hubs').html(hub_table); + + }); + {% endif %} // add marker to layer group markerLayerGroup.addLayer(marker); @@ -776,6 +799,8 @@ $(function() { {% if mode in ['onestep-edit'] %} var lat = {{ obj.getCoordinates.getLatitude }}; var lng = {{ obj.getCoordinates.getLongitude }}; + var hub = {{ obj.getHub.getID }}; + var rider = {{ obj.getRider.getID }}; selectPoint(lat, lng); diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index f7a60b1f..84bc8eac 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -383,6 +383,14 @@ + {% if mode in ['onestep-edit'] %} + {% for hub in hubs %} + + {{ hub.hub.getName }} + {{ hub.hub.getBranch }} + {{ hub.hub.getContactNumbers }} + {% endfor %} + {% endif %} @@ -412,6 +420,24 @@ + {% if mode in ['onestep-edit'] %} + {% set avail_riders = obj.getHub.getAvailableRiders|default([]) %} + + + No riders available. + + + + {% if obj.getHub %} + {% for rider in avail_riders %} + + {{ rider.getFirstName }} + {{ rider.getLastName }} + {{ rider.getContactNumber }} + {{ rider.getPlateNumber }} + {% endfor %} + {% endif %} + {% endif %} @@ -607,6 +633,7 @@ $(function() { function selectPoint(lat, lng) { + alert('selectPoint'); // clear markers markerLayerGroup.clearLayers(); hubLayerGroup.clearLayers(); From 96bed8a49e0b6fbbfe784d263c472753fad7dbcc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Sat, 25 Jan 2020 10:42:26 +0000 Subject: [PATCH 02/11] Add highlight to selected hub and rider when loading onestepedit form. #312 --- .../job-order/cmb.form.onestep.html.twig | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 947de9c5..822ee7f1 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -666,6 +666,18 @@ $(function() { }); {% endif %} + {% if mode in ['onestep-edit'] %} + // get nearest hubs ajax + $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { + var hubs = data['hubs']; + for (i in hubs) { + var hub = hubs[i]; + var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); + hubLayerGroup.addLayer(hub_marker); + } + }); + {% endif %} + // add marker to layer group markerLayerGroup.addLayer(marker); @@ -729,7 +741,14 @@ $(function() { }); $(function() { - var selected_hub = ""; + {% if mode in ['onestep-edit'] %} + var selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + $('#hub-field').val(selected_hub); + {% endif %} + {% if mode in ['onestep'] %} + var selected_hub = ''; + {% endif %} + $('#hubs-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -781,7 +800,13 @@ $(function() { }); $(function() { - var selected_rider = ''; + {% if mode in ['onestep-edit'] %} + var selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + $('#rider-field').val(selected_rider); + {% endif %} + {% if mode in ['onestep'] %} + var selected_rider = ''; + {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); From adc6cc8c80fab786dabe1dcccc12756797f50431 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Sat, 25 Jan 2020 10:47:41 +0000 Subject: [PATCH 03/11] Add highlight to selected hub and rider when loading onestepedit form for resq. #312 --- templates/job-order/form.onestep.html.twig | 65 +++++++++++++++------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 84bc8eac..4bef4efb 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -640,25 +640,40 @@ $(function() { var marker = L.marker([lat, lng], { icon: icon_customer }); - // get nearest hubs ajax - var hub_table = ''; - $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { - var hubs = data['hubs']; - for (i in hubs) { - var hub = hubs[i]; - var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); - hubLayerGroup.addLayer(hub_marker); + {% if mode in ['onestep'] %} + // get nearest hubs ajax + var hub_table = ''; + $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { + var hubs = data['hubs']; + for (i in hubs) { + var hub = hubs[i]; + var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); + hubLayerGroup.addLayer(hub_marker); - hub_table += ''; - hub_table += '' + hub['name'] + ''; - hub_table += '' + hub['branch'] + ''; - hub_table += '' + hub['cnum'] + ''; - hub_table += ''; - hub_table += ''; - } + hub_table += ''; + hub_table += '' + hub['name'] + ''; + hub_table += '' + hub['branch'] + ''; + hub_table += '' + hub['cnum'] + ''; + hub_table += ''; + hub_table += ''; + } - $('#nearest_hubs').html(hub_table); - }); + $('#nearest_hubs').html(hub_table); + + }); + {% endif %} + + {% if mode in ['onestep-edit'] %} + // get nearest hubs ajax + $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { + var hubs = data['hubs']; + for (i in hubs) { + var hub = hubs[i]; + var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); + hubLayerGroup.addLayer(hub_marker); + } + }); + {% endif %} // add marker to layer group markerLayerGroup.addLayer(marker); @@ -723,7 +738,13 @@ $(function() { }); $(function() { - var selected_hub = ""; + {% if mode in ['onestep-edit'] %} + var selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + $('#hub-field').val(selected_hub); + {% endif %} + {% if mode in ['onestep'] %} + var selected_hub = ''; + {% endif %} $('#hubs-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -775,7 +796,13 @@ $(function() { }); $(function() { - var selected_rider = ''; + {% if mode in ['onestep-edit'] %} + var selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + $('#rider-field').val(selected_rider); + {% endif %} + {% if mode in ['onestep'] %} + var selected_rider = ''; + {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); From eb9b8bfdd298461aaf65a02a161fa2104ad24a90 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 27 Jan 2020 02:24:52 +0000 Subject: [PATCH 04/11] Fix bug for onestep edit when user selects another hub but does not select a new rider. #312 --- templates/job-order/cmb.form.onestep.html.twig | 14 ++++++++++---- templates/job-order/form.onestep.html.twig | 15 ++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 822ee7f1..5fff6343 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -604,6 +604,8 @@ $(function() { var form_in_process = false; + var selected_hub = ''; + var selected_rider = ''; // openstreet maps stuff // TODO: move this to a service @@ -742,11 +744,11 @@ $(function() { $(function() { {% if mode in ['onestep-edit'] %} - var selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; $('#hub-field').val(selected_hub); {% endif %} {% if mode in ['onestep'] %} - var selected_hub = ''; + selected_hub = ''; {% endif %} $('#hubs-table').on('click', 'tr', function() { @@ -765,6 +767,10 @@ $(function() { selected_hub = id; $('#hub-field').val(selected_hub); + // clear rider field + $('#rider-field').val(''); + selected_rider = ''; + // get riders of hub // get hub riders ajax // TODO: add latitude and longitude of delivery location to ajax request @@ -801,11 +807,11 @@ $(function() { $(function() { {% if mode in ['onestep-edit'] %} - var selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; $('#rider-field').val(selected_rider); {% endif %} {% if mode in ['onestep'] %} - var selected_rider = ''; + selected_rider = ''; {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 4bef4efb..aee7ca87 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -600,6 +600,8 @@ $(function() { var form_in_process = false; + var selected_hub = ''; + var selected_rider = ''; // openstreet maps stuff // TODO: move this to a service @@ -633,7 +635,6 @@ $(function() { function selectPoint(lat, lng) { - alert('selectPoint'); // clear markers markerLayerGroup.clearLayers(); hubLayerGroup.clearLayers(); @@ -739,11 +740,11 @@ $(function() { $(function() { {% if mode in ['onestep-edit'] %} - var selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; $('#hub-field').val(selected_hub); {% endif %} {% if mode in ['onestep'] %} - var selected_hub = ''; + selected_hub = ''; {% endif %} $('#hubs-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -761,6 +762,10 @@ $(function() { selected_hub = id; $('#hub-field').val(selected_hub); + // clear rider field + $('#rider-field').val(''); + selected_rider = ''; + // get riders of hub // get hub riders ajax // TODO: add latitude and longitude of delivery location to ajax request @@ -797,11 +802,11 @@ $(function() { $(function() { {% if mode in ['onestep-edit'] %} - var selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; $('#rider-field').val(selected_rider); {% endif %} {% if mode in ['onestep'] %} - var selected_rider = ''; + selected_rider = ''; {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); From 655ead7739ed0b7ba76719676cd7fe626086bec5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 27 Jan 2020 04:30:31 +0000 Subject: [PATCH 05/11] Change color of hubs and riders. #312 --- templates/job-order/cmb.form.onestep.html.twig | 2 +- templates/job-order/form.onestep.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 5fff6343..cfa2e393 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -626,7 +626,7 @@ $(function() { }); var icon_hub = L.divIcon({ className: 'map-div-icon', - html: "
", + html: "
", iconSize: [39, 42], iconAnchor: [15, 42] }); diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index aee7ca87..7b834830 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -622,7 +622,7 @@ $(function() { }); var icon_hub = L.divIcon({ className: 'map-div-icon', - html: "
", + html: "
", iconSize: [39, 42], iconAnchor: [15, 42] }); From 79b758f547b8885c7524fe97d8ebb5876340255c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 27 Jan 2020 06:33:03 +0000 Subject: [PATCH 06/11] Fix for rider icons not displaying in map. #312 --- .../job-order/cmb.form.onestep.html.twig | 39 ++++++++++--------- templates/job-order/form.onestep.html.twig | 36 ++++++++++------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index cfa2e393..8fa8498c 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -743,14 +743,6 @@ $(function() { }); $(function() { - {% if mode in ['onestep-edit'] %} - selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; - $('#hub-field').val(selected_hub); - {% endif %} - {% if mode in ['onestep'] %} - selected_hub = ''; - {% endif %} - $('#hubs-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -806,13 +798,6 @@ $(function() { }); $(function() { - {% if mode in ['onestep-edit'] %} - selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; - $('#rider-field').val(selected_rider); - {% endif %} - {% if mode in ['onestep'] %} - selected_rider = ''; - {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -830,12 +815,30 @@ $(function() { {% if mode in ['onestep-edit'] %} var lat = {{ obj.getCoordinates.getLatitude }}; var lng = {{ obj.getCoordinates.getLongitude }}; - var hub = {{ obj.getHub.getID }}; - var rider = {{ obj.getRider.getID }}; + + selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + $('#hub-field').val(selected_hub); + + selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + $('#rider-field').val(selected_rider); selectPoint(lat, lng); - // TODO: find a way to highlight the set hub + // need to put selected rider on map. selected_hub is already on map because of selectPoint + riderLayerGroup.clearLayers(); + + $.getJSON("{{ url('hub_riders') }}?id=" + selected_hub, function(data) { + var riders = data['riders']; + for (i in riders) { + var rider = riders[i]; + if (selected_rider == rider['id']) { + var rider_lat = rider['location'][0]; + var rider_lng = rider['location'][1]; + var rider_marker = L.marker([rider_lat, rider_lng], { icon: icon_rider_available }); + riderLayerGroup.addLayer(rider_marker); + } + } + }); {% endif %} {% if mode in ['update-processing', 'update-reassign-hub'] %} diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 7b834830..40fef7d4 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -739,13 +739,6 @@ $(function() { }); $(function() { - {% if mode in ['onestep-edit'] %} - selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; - $('#hub-field').val(selected_hub); - {% endif %} - {% if mode in ['onestep'] %} - selected_hub = ''; - {% endif %} $('#hubs-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -801,13 +794,6 @@ $(function() { }); $(function() { - {% if mode in ['onestep-edit'] %} - selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; - $('#rider-field').val(selected_rider); - {% endif %} - {% if mode in ['onestep'] %} - selected_rider = ''; - {% endif %} $('#rider-table').on('click', 'tr', function() { var id = $(this).data('id'); @@ -826,9 +812,29 @@ $(function() { var lat = {{ obj.getCoordinates.getLatitude }}; var lng = {{ obj.getCoordinates.getLongitude }}; + selected_hub = '{{ obj.getHub ? obj.getHub.getID: "" }}'; + $('#hub-field').val(selected_hub); + + selected_rider = '{{ obj.getRider ? obj.getRider.getID: "" }}'; + $('#rider-field').val(selected_rider); + selectPoint(lat, lng); - // TODO: find a way to highlight the set hub + // need to put selected rider on map. selected_hub is already on map because of selectPoint + riderLayerGroup.clearLayers(); + + $.getJSON("{{ url('hub_riders') }}?id=" + selected_hub, function(data) { + var riders = data['riders']; + for (i in riders) { + var rider = riders[i]; + if (selected_rider == rider['id']) { + var rider_lat = rider['location'][0]; + var rider_lng = rider['location'][1]; + var rider_marker = L.marker([rider_lat, rider_lng], { icon: icon_rider_available }); + riderLayerGroup.addLayer(rider_marker); + } + } + }); {% endif %} {% if mode in ['update-processing', 'update-reassign-hub'] %} From 95964bf3294555ef48a8abffbd969f4537a9cd6d Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 27 Jan 2020 17:40:39 +0000 Subject: [PATCH 07/11] Add README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..0fc05d72 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +MQTT format for location updates: +: \ No newline at end of file From cc2dd8c7ff1959703175614a7e7fa1ccf8f121a2 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 27 Jan 2020 17:41:07 +0000 Subject: [PATCH 08/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fc05d72..998e0dba 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ MQTT format for location updates: -: \ No newline at end of file +`:` \ No newline at end of file From ffb4551fb1bcd3c53553cbe86542e7e68e7ecaad Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jan 2020 05:03:20 +0000 Subject: [PATCH 09/11] Update composer lock after running composer require. #312 --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index a1172379..2aa7742d 100644 --- a/composer.lock +++ b/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "b101ecfbc1f6f2270f0e8ad326035b7e", From 555bd5ae9a1e402d597f1d91f78824682e88dc99 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jan 2020 05:20:11 +0000 Subject: [PATCH 10/11] Add Cancel Job Order button to onestep form. #313 --- templates/job-order/cmb.form.onestep.html.twig | 3 +++ templates/job-order/form.onestep.html.twig | 3 +++ 2 files changed, 6 insertions(+) diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 8fa8498c..8eced3cc 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -582,6 +582,9 @@
+ {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} + Cancel Job Order + {% endif %} Back
diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 40fef7d4..120943ad 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -578,6 +578,9 @@
+ {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} + Cancel Job Order + {% endif %} Back
From bc8ce40b1339020e1b5b2854603ca64d4602b171 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jan 2020 07:24:14 +0000 Subject: [PATCH 11/11] Add distance from customer to hub to hub table. #314 --- src/Controller/HubController.php | 1 + src/Service/MapTools.php | 29 +++++++++- .../job-order/cmb.form.onestep.html.twig | 25 ++++++++- templates/job-order/form.onestep.html.twig | 53 ++++++++++++++----- 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/Controller/HubController.php b/src/Controller/HubController.php index ffce16f6..aeaaec7a 100644 --- a/src/Controller/HubController.php +++ b/src/Controller/HubController.php @@ -314,6 +314,7 @@ class HubController extends Controller 'name' => $hub->getName(), 'branch' => $hub->getBranch(), 'cnum' => $hub->getContactNumbers(), + 'distance' => $hub_res['distance'], ]; } diff --git a/src/Service/MapTools.php b/src/Service/MapTools.php index f02618ba..6aa5848c 100644 --- a/src/Service/MapTools.php +++ b/src/Service/MapTools.php @@ -84,10 +84,23 @@ class MapTools { //error_log($row[0]->getName() . ' - ' . $row['dist']); $hubs[] = $row[0]; + + // get coordinates of hub + $hub_coordinates = $row[0]->getCoordinates(); + + $cust_lat = $point->getLatitude(); + $cust_lng = $point->getLongitude(); + + $hub_lat = $hub_coordinates->getLatitude(); + $hub_lng = $hub_coordinates->getLongitude(); + + // get distance in kilometers from customer point to hub point + $dist = $this->distance($cust_lat, $cust_lng, $hub_lat, $hub_lng); + $final_data[] = [ 'hub' => $row[0], 'db_distance' => $row['dist'], - 'distance' => 0, + 'distance' => $dist, 'duration' => 0, ]; } @@ -135,4 +148,18 @@ class MapTools return $final_data; */ } + + protected function distance($lat1, $lon1, $lat2, $lon2) + { + if (($lat1 == $lat2) && ($lon1 == $lon2)) + return 0; + + $theta = $lon1 - $lon2; + $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); + $dist = acos($dist); + $dist = rad2deg($dist); + $miles = $dist * 60 * 1.1515; + + return round(($miles * 1.609344), 1); + } } diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 8eced3cc..8e4ac45d 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -381,18 +381,21 @@ Hub Branch Contact Numbers + Distance in KM Action - {% if mode in ['onestep-edit'] %} + @@ -662,6 +665,7 @@ $(function() { hub_table += '' + hub['name'] + ''; hub_table += '' + hub['branch'] + ''; hub_table += '' + hub['cnum'] + ''; + hub_table += '' + hub['distance'] + ''; hub_table += ''; hub_table += ''; } @@ -673,13 +677,30 @@ $(function() { {% if mode in ['onestep-edit'] %} // get nearest hubs ajax + var hub_table = ''; $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { var hubs = data['hubs']; for (i in hubs) { var hub = hubs[i]; var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); hubLayerGroup.addLayer(hub_marker); + + if (selected_hub == hub['id']) { + hub_table += ''; + } + else { + hub_table += ''; + } + hub_table += '' + hub['name'] + ''; + hub_table += '' + hub['branch'] + ''; + hub_table += '' + hub['cnum'] + ''; + hub_table += '' + hub['distance'] + ''; + hub_table += ''; + hub_table += ''; + } + + $('#nearest_hubs').html(hub_table); }); {% endif %} diff --git a/templates/job-order/form.onestep.html.twig b/templates/job-order/form.onestep.html.twig index 120943ad..8e4ac45d 100644 --- a/templates/job-order/form.onestep.html.twig +++ b/templates/job-order/form.onestep.html.twig @@ -36,7 +36,9 @@
- +
@@ -326,7 +328,9 @@
- +
@@ -338,7 +342,9 @@
- + @@ -363,7 +369,9 @@
- +
@@ -372,25 +380,22 @@ Hub Branch - Contact Numbers + Distance in KM Action - {% if mode in ['onestep-edit'] %} +
@@ -405,7 +410,9 @@
- +
@@ -658,24 +665,42 @@ $(function() { hub_table += '' + hub['name'] + ''; hub_table += '' + hub['branch'] + ''; hub_table += '' + hub['cnum'] + ''; + hub_table += '' + hub['distance'] + ''; hub_table += ''; hub_table += ''; } $('#nearest_hubs').html(hub_table); - + }); {% endif %} {% if mode in ['onestep-edit'] %} // get nearest hubs ajax + var hub_table = ''; $.getJSON("{{ url('hub_nearest') }}?lat=" + lat + "&long=" + lng, function(data) { var hubs = data['hubs']; for (i in hubs) { var hub = hubs[i]; var hub_marker = L.marker([hub['lat'], hub['long']], { icon: icon_hub }); hubLayerGroup.addLayer(hub_marker); + + if (selected_hub == hub['id']) { + hub_table += ''; + } + else { + hub_table += ''; + } + hub_table += '' + hub['name'] + ''; + hub_table += '' + hub['branch'] + ''; + hub_table += '' + hub['cnum'] + ''; + hub_table += '' + hub['distance'] + ''; + hub_table += ''; + hub_table += ''; + } + + $('#nearest_hubs').html(hub_table); }); {% endif %}