diff --git a/config/services.yaml b/config/services.yaml index 056ed7c2..a5d7d05f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -328,15 +328,3 @@ services: App\Service\WarrantySerialLoadLogger: arguments: $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' diff --git a/src/Controller/TAPI/JobOrderController.php b/src/Controller/TAPI/JobOrderController.php index 306b224b..153fdfcc 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -43,6 +43,7 @@ use App\Service\HubFilteringGeoChecker; use App\Service\RiderTracker; use App\Service\PromoLogger; use App\Service\MapTools; +use App\Service\JobOrderCallbackRouter; use App\Entity\JobOrder; use App\Entity\CustomerVehicle; @@ -75,7 +76,8 @@ class JobOrderController extends APIController InventoryManager $im, MQTTClient $mclient, RiderAssignmentHandlerInterface $rah, PromoLogger $promo_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.'); @@ -380,6 +382,9 @@ class JobOrderController extends APIController $em->flush(); + // send callback + $jo_callback->sendJOStatusCallback($jo); + // make invoice json data $invoice_data = [ 'total_price' => number_format($invoice->getTotalPrice(), 2, '.', ''), diff --git a/src/Service/JobOrderCallbackRouter.php b/src/Service/JobOrderCallbackRouter.php index 9c604817..f553db9e 100644 --- a/src/Service/JobOrderCallbackRouter.php +++ b/src/Service/JobOrderCallbackRouter.php @@ -22,7 +22,7 @@ class JobOrderCallbackRouter // jo id and jo status $jo_data = [ 'id' => $jo->getID(), - 'status' => JOStatus::getName($jo->getStatus()), + // 'status' => JOStatus::getName($jo->getStatus()), ]; // send status diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 9a9a44a5..ee6831f0 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -64,6 +64,7 @@ use App\Service\PromoLogger; use App\Service\HubSelector; use App\Service\HubDistributor; use App\Service\HubFilteringGeoChecker; +use App\Service\JobOrderCallbackRouter; use CrEOF\Spatial\PHP\Types\Geometry\Point; @@ -90,6 +91,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $hub_geofence; protected $cust_distance_limit; protected $hub_filter_enable; + protected $jo_callback; protected $template_hash; @@ -98,7 +100,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 $hub_filter_enabled) + string $cust_distance_limit, string $hub_filter_enabled, JobOrderCallbackRouter $jo_callback) { $this->em = $em; $this->ic = $ic; @@ -114,6 +116,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->hub_geofence = $hub_geofence; $this->cust_distance_limit = $cust_distance_limit; $this->hub_filter_enabled = $hub_filter_enabled; + $this->jo_callback = $jo_callback; $this->loadTemplates(); } @@ -916,6 +919,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // get previous status + $old_status = $obj->getStatus(); + if (empty($error_array)) { // coordinates @@ -984,6 +990,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // update redis hub jo count $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; @@ -1068,6 +1083,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // get current user $user = $this->security->getUser(); + // get previous status + $old_status = $obj->getStatus(); + if (empty($error_array)) { // coordinates $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 $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; @@ -1205,6 +1232,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // get previous status + $old_status = $obj->getStatus(); + if (empty($error_array)) { // coordinates $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 $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 $rider = $obj->getRider(); @@ -1347,6 +1386,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if (empty($obj)) throw new NotFoundHttpException('The item does not exist'); + // get previous status + $old_status = $obj->getStatus(); + $cancel_reason = $req->request->get('cancel_reason'); //error_log('cancel_reason ' . $cancel_reason); @@ -1382,6 +1424,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ]; $mclient->sendEvent($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 @@ -1465,6 +1516,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // get previously assigned rider, if any $old_rider = $obj->getRider(); + // get previous status + $old_status = $obj->getStatus(); + if (empty($error_array)) { // rider mqtt event @@ -1566,6 +1620,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->hub_dist->decrementJoCountForHub($old_hub); if ($hub != null) $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; @@ -1744,6 +1807,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // get previous status + $old_status = $obj->getStatus(); + if (empty($error_array)) { // rider mqtt event // 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->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;