diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index ebd431ad..330164aa 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -558,6 +558,14 @@ class JobOrderController extends BaseController throw $this->createNotFoundException('The job order does not have an assigning status'); } + // check if hub is assigned to current user + $user_hubs = $this->getUser()->getHubs(); + if (!in_array($obj->getHub()->getID(), $user_hubs)) + { + $em->getConnection()->rollback(); + throw $this->createNotFoundException('The job order is not on a hub assigned to this user'); + } + // check if we are the assignor $assignor = $obj->getAssignedBy(); $user = $this->getUser(); diff --git a/src/Service/MapTools.php b/src/Service/MapTools.php index d62fe0a7..693b3c21 100644 --- a/src/Service/MapTools.php +++ b/src/Service/MapTools.php @@ -60,7 +60,7 @@ class MapTools public function getClosestHubs(Point $point, $limit, $time = false) { // get closest hubs based on st_distance function from db - $query = $this->em->createQuery('SELECT h, st_distance(o.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h' . ($time ? ' WHERE :time BETWEEN h.time_open AND h.time_close' : '') . ' ORDER BY dist') + $query = $this->em->createQuery('SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h' . ($time ? ' WHERE :time BETWEEN h.time_open AND h.time_close' : '') . ' ORDER BY dist') ->setParameter('lat', $point->getLatitude()) ->setParameter('lng', $point->getLongitude()); diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index fc7628bd..bc91ef46 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -379,18 +379,18 @@
| Outlet | +Hub | Branch | Distance | Travel Time | @@ -399,21 +399,21 @@Contact Numbers | ||
|---|---|---|---|---|---|---|---|
| {{ outlet.outlet.getName }} | -{{ outlet.outlet.getBranch }} | -{{ outlet.distance ? outlet.distance : '-' }} | -{{ outlet.duration ? outlet.duration : '-' }} | + {% for hub in hubs %} +||||
| {{ hub.hub.getName }} | +{{ hub.hub.getBranch }} | +{{ hub.distance ? hub.distance : '-' }} | +{{ hub.duration ? hub.duration : '-' }} | 0 | 0 | -{{ outlet.outlet.getContactNumbers }} | +{{ hub.hub.getContactNumbers }} |
| @@ -653,14 +613,14 @@ $(function() { {% endif %} {% if mode == 'update-processing' %} - // display outlet map - var omap = new GMaps({ - div: '#outlet_map', + // display hub map + var hmap = new GMaps({ + div: '#hub_map', lat: {{ obj.getCoordinates.getLatitude }}, lng: {{ obj.getCoordinates.getLongitude }} }); - omap.addMarker({ + hmap.addMarker({ lat: {{ obj.getCoordinates.getLatitude }}, lng: {{ obj.getCoordinates.getLongitude }}, icon: '/assets/images/icon-destination.png', @@ -668,12 +628,12 @@ $(function() { content: "Destination" }); - {% for outlet in outlets %} - omap.addMarker({ - lat: {{ outlet.outlet.getCoordinates.getLatitude }}, - lng: {{ outlet.outlet.getCoordinates.getLongitude }}, - title: "{{ outlet.outlet.getName }}", - content: "{{ outlet.outlet.getName }}", + {% for hub in hubs %} + hmap.addMarker({ + lat: {{ hub.hub.getCoordinates.getLatitude }}, + lng: {{ hub.hub.getCoordinates.getLongitude }}, + title: "{{ hub.hub.getName }}", + content: "{{ hub.hub.getName }}", icon: '/assets/images/icon-outlet.png' }); {% endfor %} @@ -695,8 +655,8 @@ $(function() { fields['invoice_items'] = invoiceItems; {% if mode == 'update-processing' %} - // add selected outlet to data - fields['outlet'] = selectedOutlet; + // add selected hub to data + fields['hub'] = selectedHub; {% endif %} {% if mode == 'update-assigning' %} @@ -1049,21 +1009,21 @@ $(function() { */ {% if mode == 'update-processing' %} - var selectedOutlet = '{{ obj.getOutlet ? obj.getOutlet.getID : "" }}'; + var selectedHub = '{{ obj.getHub ? obj.getHub.getID : "" }}'; - $("#outlets-table tbody tr").click(function() { + $("#hubs-table tbody tr").click(function() { var id = $(this).data('id'); var lat = $(this).data('lat'); var lng = $(this).data('lng'); - if (id != selectedOutlet) { - // highlight this row, set outlet value - $("#outlets-table").find('.m-table__row--primary').removeClass('m-table__row--primary'); + if (id != selectedHub) { + // highlight this row, set hub value + $("#hubs-table").find('.m-table__row--primary').removeClass('m-table__row--primary'); $(this).addClass('m-table__row--primary'); // set value - selectedOutlet = id; + selectedHub = id; // center the map omap.setCenter(lat, lng); @@ -1072,7 +1032,7 @@ $(function() { $(this).removeClass('m-table__row--primary'); // remove id value - selectedOutlet = ''; + selectedHub = ''; } }); {% endif %} @@ -1084,7 +1044,7 @@ $(function() { var id = $(this).data('id'); if (id != selectedRider) { - // highlight this row, set outlet value + // highlight this row, set hub value $("#riders-table").find('.m-table__row--primary').removeClass('m-table__row--primary'); $(this).addClass('m-table__row--primary'); |