Manually call the callback URL when JO status is changed. #737

This commit is contained in:
Korina Cordero 2023-02-17 08:57:38 +00:00
parent b22a3464be
commit d569ea55d1
4 changed files with 83 additions and 15 deletions

View file

@ -328,15 +328,3 @@ services:
App\Service\WarrantySerialLoadLogger: App\Service\WarrantySerialLoadLogger:
arguments: arguments:
$em: "@doctrine.orm.entity_manager" $em: "@doctrine.orm.entity_manager"
# entity listener for the third party JO status
App\EntityListener\JobOrderStatusListener:
arguments:
$jo_callback: "@App\\Service\\JobOrderCallbackRouter"
tags:
- name: doctrine.orm.entity_listener
event: 'preUpdate'
entity: 'App\Entity\JobOrder'
- name: doctrine.orm.entity_listener
event: 'postPersist'
entity: 'App\Entity\JobOrder'

View file

@ -43,6 +43,7 @@ use App\Service\HubFilteringGeoChecker;
use App\Service\RiderTracker; use App\Service\RiderTracker;
use App\Service\PromoLogger; use App\Service\PromoLogger;
use App\Service\MapTools; use App\Service\MapTools;
use App\Service\JobOrderCallbackRouter;
use App\Entity\JobOrder; use App\Entity\JobOrder;
use App\Entity\CustomerVehicle; use App\Entity\CustomerVehicle;
@ -75,7 +76,8 @@ class JobOrderController extends APIController
InventoryManager $im, MQTTClient $mclient, 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, EntityManagerInterface $em) HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em,
JobOrderCallbackRouter $jo_callback)
{ {
$this->denyAccessUnlessGranted('tapi_jo.request', null, 'No access.'); $this->denyAccessUnlessGranted('tapi_jo.request', null, 'No access.');
@ -380,6 +382,9 @@ class JobOrderController extends APIController
$em->flush(); $em->flush();
// send callback
$jo_callback->sendJOStatusCallback($jo);
// make invoice json data // make invoice json data
$invoice_data = [ $invoice_data = [
'total_price' => number_format($invoice->getTotalPrice(), 2, '.', ''), 'total_price' => number_format($invoice->getTotalPrice(), 2, '.', ''),

View file

@ -22,7 +22,7 @@ class JobOrderCallbackRouter
// jo id and jo status // jo id and jo status
$jo_data = [ $jo_data = [
'id' => $jo->getID(), 'id' => $jo->getID(),
'status' => JOStatus::getName($jo->getStatus()), // 'status' => JOStatus::getName($jo->getStatus()),
]; ];
// send status // send status

View file

@ -64,6 +64,7 @@ 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 App\Service\HubFilteringGeoChecker;
use App\Service\JobOrderCallbackRouter;
use CrEOF\Spatial\PHP\Types\Geometry\Point; use CrEOF\Spatial\PHP\Types\Geometry\Point;
@ -90,6 +91,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
protected $hub_geofence; protected $hub_geofence;
protected $cust_distance_limit; protected $cust_distance_limit;
protected $hub_filter_enable; protected $hub_filter_enable;
protected $jo_callback;
protected $template_hash; protected $template_hash;
@ -98,7 +100,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
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, HubFilteringGeoChecker $hub_geofence, PromoLogger $promo_logger, HubDistributor $hub_dist, HubFilteringGeoChecker $hub_geofence,
string $cust_distance_limit, string $hub_filter_enabled) string $cust_distance_limit, string $hub_filter_enabled, JobOrderCallbackRouter $jo_callback)
{ {
$this->em = $em; $this->em = $em;
$this->ic = $ic; $this->ic = $ic;
@ -114,6 +116,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->hub_geofence = $hub_geofence; $this->hub_geofence = $hub_geofence;
$this->cust_distance_limit = $cust_distance_limit; $this->cust_distance_limit = $cust_distance_limit;
$this->hub_filter_enabled = $hub_filter_enabled; $this->hub_filter_enabled = $hub_filter_enabled;
$this->jo_callback = $jo_callback;
$this->loadTemplates(); $this->loadTemplates();
} }
@ -916,6 +919,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$ownertype_id = $req->request->get('ownership_type', 0); $ownertype_id = $req->request->get('ownership_type', 0);
$owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id);
// get previous status
$old_status = $obj->getStatus();
if (empty($error_array)) if (empty($error_array))
{ {
// coordinates // coordinates
@ -984,6 +990,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// update redis hub jo count // update redis hub jo count
$this->hub_dist->incrementJoCountForHub($hub); $this->hub_dist->incrementJoCountForHub($hub);
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
} }
return $error_array; return $error_array;
@ -1068,6 +1083,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get current user // get current user
$user = $this->security->getUser(); $user = $this->security->getUser();
// get previous status
$old_status = $obj->getStatus();
if (empty($error_array)) { if (empty($error_array)) {
// coordinates // coordinates
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
@ -1140,6 +1158,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// call rider assignment handler's assignJobOrder // call rider assignment handler's assignJobOrder
$this->rah->assignJobOrder($obj, $rider); $this->rah->assignJobOrder($obj, $rider);
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
} }
return $error_array; return $error_array;
@ -1205,6 +1232,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$ownertype_id = $req->request->get('ownership_type', 0); $ownertype_id = $req->request->get('ownership_type', 0);
$owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id);
// get previous status
$old_status = $obj->getStatus();
if (empty($error_array)) { if (empty($error_array)) {
// coordinates // coordinates
$point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat'));
@ -1269,6 +1299,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// validated! save the entity // validated! save the entity
$em->flush(); $em->flush();
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
// get rider // get rider
$rider = $obj->getRider(); $rider = $obj->getRider();
@ -1347,6 +1386,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
if (empty($obj)) if (empty($obj))
throw new NotFoundHttpException('The item does not exist'); throw new NotFoundHttpException('The item does not exist');
// get previous status
$old_status = $obj->getStatus();
$cancel_reason = $req->request->get('cancel_reason'); $cancel_reason = $req->request->get('cancel_reason');
//error_log('cancel_reason ' . $cancel_reason); //error_log('cancel_reason ' . $cancel_reason);
@ -1382,6 +1424,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
]; ];
$mclient->sendEvent($obj, $payload); $mclient->sendEvent($obj, $payload);
$mclient->sendRiderEvent($obj, $payload); $mclient->sendRiderEvent($obj, $payload);
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
} }
// set hub for job order // set hub for job order
@ -1465,6 +1516,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
// get previously assigned rider, if any // get previously assigned rider, if any
$old_rider = $obj->getRider(); $old_rider = $obj->getRider();
// get previous status
$old_status = $obj->getStatus();
if (empty($error_array)) if (empty($error_array))
{ {
// rider mqtt event // rider mqtt event
@ -1566,6 +1620,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->hub_dist->decrementJoCountForHub($old_hub); $this->hub_dist->decrementJoCountForHub($old_hub);
if ($hub != null) if ($hub != null)
$this->hub_dist->incrementJoCountForHub($hub); $this->hub_dist->incrementJoCountForHub($hub);
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
} }
return $error_array; return $error_array;
@ -1744,6 +1807,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$ownertype_id = $req->request->get('ownership_type', 0); $ownertype_id = $req->request->get('ownership_type', 0);
$owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id);
// get previous status
$old_status = $obj->getStatus();
if (empty($error_array)) { if (empty($error_array)) {
// rider mqtt event // rider mqtt event
// NOTE: need to send this before saving because rider will be cleared // NOTE: need to send this before saving because rider will be cleared
@ -1845,6 +1911,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
]; ];
$mclient->sendEvent($obj, $payload); $mclient->sendEvent($obj, $payload);
$mclient->sendRiderEvent($obj, $payload); $mclient->sendRiderEvent($obj, $payload);
// send callback url if source is third party
if ($obj->getJOSource() != null)
{
// need to check if the JO status changed
$current_status = $obj->getStatus();
if ($old_status != $current_status)
$this->jo_callback->sendJOStatusCallback($obj);
}
} }
return $error_array; return $error_array;