diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index 621195b1..6ea3a3c5 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -262,3 +262,8 @@ jo_cancel_reasons: path: /ajax/jo_cancel_reasons controller: App\Controller\JobOrderController::cancelReasons methods: [GET] + +jo_geofence: + path: /ajax/job-order/geofence + controller: App\Controller\JobOrderController::checkGeofence + methods: [GET] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 11446515..e10f8496 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -23,6 +23,7 @@ use App\Service\MapTools; use App\Service\MQTTClient; use App\Service\APNSClient; use App\Service\InventoryManager; +use App\Service\GeofenceTracker; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -1186,6 +1187,19 @@ class JobOrderController extends Controller ]); } + // ajax call + public function checkGeofence(Request $req, GeofenceTracker $geo) + { + $lat = $req->query->get('lat'); + $lng = $req->query->get('lng'); + + $is_covered = $geo->isCovered($lng, $lat); + + return $this->json([ + 'is_covered' => $is_covered + ]); + } + /** * @Menu(selected="jo_autoassign") */ diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 95dae4e0..71a4a42e 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -992,6 +992,26 @@ $(function() { function selectPoint(lat, lng) { + // check if point is in coverage area + $.ajax({ + method: "GET", + url: "{{ url('jo_geofence') }}", + data: { + 'lat': lat, + 'lng': lng + } + }).done(function(response) { + if (response.is_covered === false) + { + console.log('Not in coverage area'); + swal({ + title: 'Warning!', + text: 'Our service is limited to some areas in Metro Manila, Laguna, and Baguio only. We will update you as soon as we are able to cover your area', + type: 'warning', + }); + } + }); + // clear markers markerLayerGroup.clearLayers();