Add hub filter option in .env. #605

This commit is contained in:
Korina Cordero 2021-07-29 06:40:07 +00:00
parent ac0edd5467
commit 0de8f71d0e
5 changed files with 37 additions and 20 deletions

View file

@ -89,3 +89,4 @@ HUB_JO_KEY=hub_jo_count
# hub geofence
HUB_GEOFENCE_ENABLE=set_to_true_or_false
HUB_FILTER_ENABLE=set_to_true_or_false

View file

@ -171,6 +171,7 @@ services:
arguments:
$country_code: "%env(COUNTRY_CODE)%"
$cust_distance_limit: "%env(CUST_DISTANCE_LIMIT_ADMIN_PANEL)%"
$hub_filter_enabled: "%env(HUB_FILTER_ENABLE)%"
#job order generator interface
App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler"

View file

@ -854,6 +854,8 @@ class APIController extends Controller implements LoggedController
return $res->getReturnResponse();
}
// TODO: remove later
// mobile app no longer calls this
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
@ -2767,22 +2769,31 @@ class APIController extends Controller implements LoggedController
$hub_criteria->setPoint($jo->getCoordinates());
// get distance limit for mobile from env
// get value of hub_filter_enable from env
$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__.'/../../.env');
$limit_distance = $_ENV['CUST_DISTANCE_LIMIT'];
$hub_filter_enabled = $_ENV['HUB_FILTER_ENABLE'];
// set distance limit
$hub_criteria->setLimitDistance($limit_distance);
if ($hub_geofence->isCovered($long, $lat))
// check if hub filter is enabled. If not, use default values
// for the rest of the HubCriteria fields
if ($hub_filter_enabled == 'true')
{
// 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');
$hub_criteria->setJoType($jo->getServiceType())
->setPaymentMethod($jo->getModeOfPayment())
->setRoundRobin(true);
error_log('hub filter is enabled');
// check if customer location is in hub filter area
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');
$hub_criteria->setJoType($jo->getServiceType())
->setPaymentMethod($jo->getModeOfPayment())
->setRoundRobin(true);
}
}
// add battery to items

View file

@ -21,10 +21,6 @@ class HubFilteringGeoChecker
public function isCovered($long, $lat)
{
// TODO: remove this
// NOTE: this is a temporary fix to disable hub filtering altogether
return false;
// check if geofence is enabled
if ($this->geofence_flag == 'true')
{

View file

@ -81,6 +81,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
protected $hub_dist;
protected $hub_geofence;
protected $cust_distance_limit;
protected $hub_filter_enable;
protected $template_hash;
@ -89,7 +90,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence,
string $cust_distance_limit)
string $cust_distance_limit, string $hub_filter_enabled)
{
$this->em = $em;
$this->ic = $ic;
@ -104,6 +105,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->hub_dist = $hub_dist;
$this->hub_geofence = $hub_geofence;
$this->cust_distance_limit = $cust_distance_limit;
$this->hub_filter_enabled = $hub_filter_enabled;
$this->loadTemplates();
}
@ -1986,14 +1988,20 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$hub_criteria->setPoint($obj->getCoordinates())
->setLimitResults(50);
if ($this->hub_geofence->isCovered($long, $lat))
// check if hub filter is enabled. If not, use default values
// for the rest of the HubCriteria fields
if ($this->hub_filter_enabled == 'true')
{
// if true, set other values for HubCriteria
error_log('Area is covered by hub filtering');
$hub_criteria->setLimitDistance($this->cust_distance_limit)
->setPaymentMethod($obj->getModeOfPayment())
->setJoType($obj->getServiceType())
->setRoundRobin(true);
error_log('hub filter is enabled');
if ($this->hub_geofence->isCovered($long, $lat))
{
// if true, set other values for HubCriteria
error_log('Area is covered by hub filtering');
$hub_criteria->setLimitDistance($this->cust_distance_limit)
->setPaymentMethod($obj->getModeOfPayment())
->setJoType($obj->getServiceType())
->setRoundRobin(true);
}
}
// check if emergency or not