diff --git a/.env.dist b/.env.dist index a0693430..611bfcfe 100644 --- a/.env.dist +++ b/.env.dist @@ -70,8 +70,11 @@ INVENTORY_API_AUTH_TOKEN=insert_auth_token_here # API logging API_LOGGING=set_to_true_or_false -# customer distance limit in km -CUST_DISTANCE_LIMIT=set_to_number +# customer distance limit in km for mobile +CUST_DISTANCE_LIMIT=5 + +# customer distance limit in km for admin panel +CUST_DISTANCE_LIMIT_ADMIN_PANEL=5 MAPTILER_API_KEY=map_tiler_api_key diff --git a/config/services.yaml b/config/services.yaml index c4da052b..bed217dd 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -170,6 +170,7 @@ services: App\Service\JobOrderHandler\ResqJobOrderHandler: arguments: $country_code: "%env(COUNTRY_CODE)%" + $cust_distance_limit: "%env(CUST_DISTANCE_LIMIT_ADMIN_PANEL)%" #job order generator interface App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler" diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 31b720a6..cd0c8212 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1027,12 +1027,20 @@ class APIController extends Controller implements LoggedController $hub_criteria = new HubCriteria(); $hub_criteria->setPoint($jo->getCoordinates()); + // get distance limit for mobile from env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + $limit_distance = $_ENV['CUST_DISTANCE_LIMIT']; + + // set distance limit + $hub_criteria->setLimitDistance($limit_distance); + if ($hub_geofence->isCovered($long, $lat)) { // TODO: set this properly, since the other flags // are on default values. // if true, set other values for HubCriteria - // error_log('Area is covered by hub filtering'); + error_log('Area is covered by hub filtering'); $hub_criteria->setJoType($jo->getServiceType()) ->setPaymentMethod($jo->getModeOfPayment()) ->setRoundRobin(true); @@ -1096,7 +1104,7 @@ class APIController extends Controller implements LoggedController else { // log hub into hub_filter_log - $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider'); + $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID()); // continue to go through list to find hub with an available rider } } @@ -2758,12 +2766,20 @@ class APIController extends Controller implements LoggedController $hub_criteria = new HubCriteria(); $hub_criteria->setPoint($jo->getCoordinates()); + // get distance limit for mobile from env + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/../../.env'); + $limit_distance = $_ENV['CUST_DISTANCE_LIMIT']; + + // set distance limit + $hub_criteria->setLimitDistance($limit_distance); + if ($hub_geofence->isCovered($long, $lat)) { // if true, set other values for HubCriteria // TODO: set this properly, since the other flags // are on default values - // error_log('Area is covered by hub filtering'); + error_log('Area is covered by hub filtering'); $hub_criteria->setJoType($jo->getServiceType()) ->setPaymentMethod($jo->getModeOfPayment()) ->setRoundRobin(true); @@ -2827,7 +2843,7 @@ class APIController extends Controller implements LoggedController else { // log hub into hub_filter_log - $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider'); + $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID()); // continue to go through list to find hub with an available rider } } diff --git a/src/Service/HubDistributor.php b/src/Service/HubDistributor.php index 44069f03..8b296b7f 100644 --- a/src/Service/HubDistributor.php +++ b/src/Service/HubDistributor.php @@ -108,7 +108,7 @@ class HubDistributor return 1; }); - error_log('arranged hubs ' . json_encode($arranged_hubs)); + // error_log('arranged hubs ' . json_encode($arranged_hubs)); return $arranged_hubs; } diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index b414e59c..ac84b82d 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -56,6 +56,10 @@ class HubSelector $results = []; + error_log('payment methods ' . $payment_method); + error_log('distance limit ' . $limit_distance); + error_log('emergency flag ' . $flag_emergency); + // get all the hubs within distance $filtered_hubs = $this->getClosestHubs($point, $limit_distance, $jo_id, $customer_id); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index be3a4564..5a8ea914 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -80,6 +80,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $promo_logger; protected $hub_dist; protected $hub_geofence; + protected $cust_distance_limit; protected $template_hash; @@ -87,7 +88,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, string $country_code, WarrantyHandler $wh, RisingTideGateway $rt, - PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence) + PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence, + string $cust_distance_limit) { $this->em = $em; $this->ic = $ic; @@ -101,6 +103,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->promo_logger = $promo_logger; $this->hub_dist = $hub_dist; $this->hub_geofence = $hub_geofence; + $this->cust_distance_limit = $cust_distance_limit; $this->loadTemplates(); } @@ -1979,6 +1982,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $long = $obj->getCoordinates()->getLongitude(); $lat = $obj->getCoordinates()->getLatitude(); + // set result limit and location $hub_criteria->setPoint($obj->getCoordinates()) ->setLimitResults(50); @@ -1986,7 +1990,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface { // if true, set other values for HubCriteria error_log('Area is covered by hub filtering'); - $hub_criteria->setPaymentMethod($obj->getModeOfPayment()) + $hub_criteria->setLimitDistance($this->cust_distance_limit) + ->setPaymentMethod($obj->getModeOfPayment()) ->setJoType($obj->getServiceType()) ->setRoundRobin(true); } @@ -1994,7 +1999,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if emergency or not $willing_to_wait = $obj->getWillWait(); if ($willing_to_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT) + { + // reset distance limit if emergency + $hub_criteria->setLimitDistance(500); $hub_criteria->setEmergency(true); + } // get JO and customer id for logging purposes $jo_id = $obj->getID(); @@ -2292,7 +2301,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface { // if true, set other values for HubCriteria // error_log('Area is covered by hub'); - $hub_criteria->setPaymentMethod($obj->getModeOfPayment()) + $hub_criteria->setLimitDistance($this->cust_distance_limit) + ->setPaymentMethod($obj->getModeOfPayment()) ->setJoType($obj->getServiceType()) ->setRoundRobin(true); }