Add geofence hub filtering to mobile API and to dispatch form. #575
This commit is contained in:
parent
12fd768849
commit
f40f6974e2
2 changed files with 67 additions and 24 deletions
|
|
@ -45,6 +45,7 @@ use App\Service\PromoLogger;
|
||||||
use App\Service\HubSelector;
|
use App\Service\HubSelector;
|
||||||
use App\Service\HubDistributor;
|
use App\Service\HubDistributor;
|
||||||
use App\Service\HubFilterLogger;
|
use App\Service\HubFilterLogger;
|
||||||
|
use App\Service\HubFilteringGeoChecker;
|
||||||
|
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
|
@ -856,7 +857,8 @@ class APIController extends Controller implements LoggedController
|
||||||
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
|
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||||
|
HubFilteringGeoChecker $hub_geofence)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -1021,13 +1023,20 @@ class APIController extends Controller implements LoggedController
|
||||||
$invoice = $ic->generateInvoice($icrit);
|
$invoice = $ic->generateInvoice($icrit);
|
||||||
$jo->setInvoice($invoice);
|
$jo->setInvoice($invoice);
|
||||||
|
|
||||||
// TODO: set this properly, since the other flags
|
// set more hub criteria fields
|
||||||
// are on default values
|
|
||||||
// TODO: check the new service HubFilteringGeoChecker
|
|
||||||
// if true, set other values for HubCriteria, if any
|
|
||||||
$hub_criteria = new HubCriteria();
|
$hub_criteria = new HubCriteria();
|
||||||
$hub_criteria->setPoint($jo->getCoordinates())
|
$hub_criteria->setPoint($jo->getCoordinates());
|
||||||
->setJoType($jo->getServiceType());
|
|
||||||
|
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');
|
||||||
|
$hub_criteria->setJoType($jo->getServiceType())
|
||||||
|
->setPaymentMethod($jo->getModeOfPayment())
|
||||||
|
->setRoundRobin(true);
|
||||||
|
}
|
||||||
|
|
||||||
// add battery to items
|
// add battery to items
|
||||||
$sku = $batt->getSAPCode();
|
$sku = $batt->getSAPCode();
|
||||||
|
|
@ -2395,7 +2404,8 @@ class APIController extends Controller implements LoggedController
|
||||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||||
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger,
|
||||||
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
|
HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger,
|
||||||
|
HubFilteringGeoChecker $hub_geofence)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -2580,13 +2590,19 @@ class APIController extends Controller implements LoggedController
|
||||||
// check if hub is null
|
// check if hub is null
|
||||||
if ($hub == null)
|
if ($hub == null)
|
||||||
{
|
{
|
||||||
|
$hub_criteria = new HubCriteria();
|
||||||
|
$hub_criteria->setPoint($jo->getCoordinates());
|
||||||
|
|
||||||
|
if ($hub_geofence->isCovered($long, $lat))
|
||||||
|
{
|
||||||
|
// if true, set other values for HubCriteria
|
||||||
// TODO: set this properly, since the other flags
|
// TODO: set this properly, since the other flags
|
||||||
// are on default values
|
// are on default values
|
||||||
// TODO: check the new service HubFilteringGeoChecker
|
// error_log('Area is covered by hub filtering');
|
||||||
// if true, set other values for HubCriteria, if any
|
$hub_criteria->setJoType($jo->getServiceType())
|
||||||
$hub_criteria = new HubCriteria();
|
->setPaymentMethod($jo->getModeOfPayment())
|
||||||
$hub_criteria->setPoint($jo->getCoordinates())
|
->setRoundRobin(true);
|
||||||
->setJoType($jo->getServiceType());
|
}
|
||||||
|
|
||||||
// add battery to items
|
// add battery to items
|
||||||
$sku = $batt->getSAPCode();
|
$sku = $batt->getSAPCode();
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ use App\Service\RisingTideGateway;
|
||||||
use App\Service\PromoLogger;
|
use App\Service\PromoLogger;
|
||||||
use App\Service\HubSelector;
|
use App\Service\HubSelector;
|
||||||
use App\Service\HubDistributor;
|
use App\Service\HubDistributor;
|
||||||
|
use App\Service\HubFilteringGeoChecker;
|
||||||
|
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
|
|
@ -78,6 +79,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
protected $rt;
|
protected $rt;
|
||||||
protected $promo_logger;
|
protected $promo_logger;
|
||||||
protected $hub_dist;
|
protected $hub_dist;
|
||||||
|
protected $hub_geofence;
|
||||||
|
|
||||||
protected $template_hash;
|
protected $template_hash;
|
||||||
|
|
||||||
|
|
@ -85,7 +87,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||||
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||||
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
|
string $country_code, WarrantyHandler $wh, RisingTideGateway $rt,
|
||||||
PromoLogger $promo_logger, HubDistributor $hub_dist)
|
PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->ic = $ic;
|
$this->ic = $ic;
|
||||||
|
|
@ -98,6 +100,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
$this->rt = $rt;
|
$this->rt = $rt;
|
||||||
$this->promo_logger = $promo_logger;
|
$this->promo_logger = $promo_logger;
|
||||||
$this->hub_dist = $hub_dist;
|
$this->hub_dist = $hub_dist;
|
||||||
|
$this->hub_geofence = $hub_geofence;
|
||||||
|
|
||||||
$this->loadTemplates();
|
$this->loadTemplates();
|
||||||
}
|
}
|
||||||
|
|
@ -498,7 +501,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
{
|
{
|
||||||
foreach ($customer_tags as $customer_tag)
|
foreach ($customer_tags as $customer_tag)
|
||||||
{
|
{
|
||||||
// TODO: not too comfy with this being hardcoded
|
|
||||||
if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId())
|
if ($customer_tag->getID() == $jo->getInvoice()->getUsedCustomerTagId())
|
||||||
{
|
{
|
||||||
// remove associated entity
|
// remove associated entity
|
||||||
|
|
@ -1973,13 +1975,21 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// get closest hubs
|
// get closest hubs
|
||||||
// set hub criteria
|
// set more hub criteria fields
|
||||||
// TODO: check the new service HubFilteringGeoChecker
|
$long = $obj->getCoordinates()->getLongitude();
|
||||||
// if true, set other values for HubCriteria
|
$lat = $obj->getCoordinates()->getLatitude();
|
||||||
|
|
||||||
$hub_criteria->setPoint($obj->getCoordinates())
|
$hub_criteria->setPoint($obj->getCoordinates())
|
||||||
->setLimitResults(50)
|
->setLimitResults(50);
|
||||||
->setPaymentMethod($obj->getModeOfPayment())
|
|
||||||
->setJoType($obj->getServiceType());
|
if ($this->hub_geofence->isCovered($long, $lat))
|
||||||
|
{
|
||||||
|
// if true, set other values for HubCriteria
|
||||||
|
// error_log('Area is covered by hub filtering');
|
||||||
|
$hub_criteria->setPaymentMethod($obj->getModeOfPayment())
|
||||||
|
->setJoType($obj->getServiceType())
|
||||||
|
->setRoundRobin(true);
|
||||||
|
}
|
||||||
|
|
||||||
// check if emergency or not
|
// check if emergency or not
|
||||||
$willing_to_wait = $obj->getWillWait();
|
$willing_to_wait = $obj->getWillWait();
|
||||||
|
|
@ -2262,10 +2272,27 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// get closest hubs
|
// get closest hubs
|
||||||
// TODO: check the new service HubFilteringGeoChecker
|
// set more hub criteria fields
|
||||||
// if true, set other values for HubCriteria
|
$long = $obj->getCoordinates()->getLongitude();
|
||||||
|
$lat = $obj->getCoordinates()->getLatitude();
|
||||||
|
|
||||||
$hub_criteria->setPoint($obj->getCoordinates())
|
$hub_criteria->setPoint($obj->getCoordinates())
|
||||||
->setLimitResults(50);
|
->setLimitResults(50);
|
||||||
|
|
||||||
|
if ($this->hub_geofence->isCovered($long, $lat))
|
||||||
|
{
|
||||||
|
// if true, set other values for HubCriteria
|
||||||
|
// error_log('Area is covered by hub');
|
||||||
|
$hub_criteria->setPaymentMethod($obj->getModeOfPayment())
|
||||||
|
->setJoType($obj->getServiceType())
|
||||||
|
->setRoundRobin(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if emergency or not
|
||||||
|
$willing_to_wait = $obj->getWillWait();
|
||||||
|
if ($willing_to_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT)
|
||||||
|
$hub_criteria->setEmergency(true);
|
||||||
|
|
||||||
$hubs = $hub_selector->find($hub_criteria);
|
$hubs = $hub_selector->find($hub_criteria);
|
||||||
|
|
||||||
$params['status_cancelled'] = JOStatus::CANCELLED;
|
$params['status_cancelled'] = JOStatus::CANCELLED;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue