From dc68f899e72a38342580e3fb6e6a7fd01eff3939 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 1 Jul 2021 02:54:22 +0000 Subject: [PATCH] Add jo id and customer id to hub filter logging. #594 --- src/Entity/HubFilterLog.php | 37 ++++++++++++++++ src/Service/HubFilterLogger.php | 6 ++- src/Service/HubSelector.php | 42 +++++++++---------- .../JobOrderHandler/ResqJobOrderHandler.php | 12 +++++- 4 files changed, 72 insertions(+), 25 deletions(-) diff --git a/src/Entity/HubFilterLog.php b/src/Entity/HubFilterLog.php index 2c4d8584..c1633684 100644 --- a/src/Entity/HubFilterLog.php +++ b/src/Entity/HubFilterLog.php @@ -44,9 +44,23 @@ class HubFilterLog */ protected $filter_type_id; + // jo id that made request + /** + * @ORM\Column(type="integer", nullable=true) + */ + protected $jo_id; + + // customer id that made request + /** + * @ORM\Column(type="integer", nullable=true) + */ + protected $customer_id; + public function __construct() { $this->date_create = new DateTime(); + $this->jo_id = null; + $this->customer_id = null; } public function getID() @@ -80,5 +94,28 @@ class HubFilterLog { return $this->filter_type_id; } + + public function setJobOrderId($jo_id) + { + $this->jo_id = $jo_id; + return $this; + } + + public function getJobOrderId() + { + return $this->jo_id; + } + + public function setCustomerId($customer_id) + { + $this->customer_id = $customer_id; + return $this; + } + + public function getCustomerId() + { + return $this->customer_id; + } + } diff --git a/src/Service/HubFilterLogger.php b/src/Service/HubFilterLogger.php index 74744a39..e25c6adb 100644 --- a/src/Service/HubFilterLogger.php +++ b/src/Service/HubFilterLogger.php @@ -16,12 +16,14 @@ class HubFilterLogger $this->em = $em; } - public function logFilteredHub(Hub $hub, $filter_type) + public function logFilteredHub(Hub $hub, $filter_type, $jo_id, $customer_id) { $hub_filter_log = new HubFilterLog(); $hub_filter_log->setHub($hub) - ->setFilterTypeId($filter_type); + ->setFilterTypeId($filter_type) + ->setJobOrderId($jo_id) + ->setCustomerId($customer_id); $this->em->persist($hub_filter_log); $this->em->flush(); diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index a0f78213..87dd14d2 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -39,7 +39,7 @@ class HubSelector $this->rt = $rt; } - public function find(HubCriteria $criteria) + public function find(HubCriteria $criteria, $jo_id, $customer_id) { $point = $criteria->getPoint(); $limit_results = $criteria->getLimitResults(); @@ -55,33 +55,33 @@ class HubSelector $results = []; // get all the hubs within distance - $filtered_hubs = $this->getClosestHubs($point, $limit_distance); + $filtered_hubs = $this->getClosestHubs($point, $limit_distance, $jo_id, $customer_id); error_log('closest hubs ' . json_encode($filtered_hubs)); if (!$flag_emergency) { // filter the first hub results for date and opening times - $hubs_date_time = $this->filterHubsByDateAndTime($filtered_hubs, $date_time); + $hubs_date_time = $this->filterHubsByDateAndTime($filtered_hubs, $date_time, $jo_id, $customer_id); $filtered_hubs = $hubs_date_time; //error_log('date_time hubs ' . json_encode($filtered_hubs)); // filter jo types - $hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type); + $hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type, $jo_id, $customer_id); $filtered_hubs = $hubs_jo_type; //error_log('jo_type hubs ' . json_encode($filtered_hubs)); // filter hubs by payment methods - $hubs_payment_method = $this->filterHubsByPaymentMethod($filtered_hubs, $payment_method); + $hubs_payment_method = $this->filterHubsByPaymentMethod($filtered_hubs, $payment_method, $jo_id, $customer_id); $filtered_hubs = $hubs_payment_method; //error_log('payment hubs ' . json_encode($filtered_hubs)); // inventory filter $hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, - $jo_type, $items); + $jo_type, $items, $jo_id, $customer_id); $filtered_hubs = $hubs_inventory; //error_log('inventory hubs ' . json_encode($filtered_hubs)); @@ -93,7 +93,7 @@ class HubSelector //error_log('round robin hubs ' . json_encode($filtered_hubs)); // max results filter - $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results); + $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results, $jo_id, $customer_id); $filtered_hubs = $hubs_max_result; } @@ -120,7 +120,7 @@ class HubSelector } - protected function filterHubsByMaxResults($hubs, $limit_result) + protected function filterHubsByMaxResults($hubs, $limit_result, $jo_id, $customer_id) { if (empty($hubs)) return $hubs; @@ -133,13 +133,13 @@ class HubSelector if ($i < $limit_result) $results[] = $hubs[$i]; else - $this->hub_filter_logger->logFilteredHub($hubs[$i]['hub'], 'max_results'); + $this->hub_filter_logger->logFilteredHub($hubs[$i]['hub'], 'max_results', $jo_id, $customer_id); } return $results; } - protected function filterHubsByJoType($hubs, $jo_type) + protected function filterHubsByJoType($hubs, $jo_type, $jo_id, $customer_id) { if (empty($hubs)) return $hubs; @@ -163,13 +163,13 @@ class HubSelector 'duration' => $hub_data['duration'], ]; else - $this->hub_filter_logger->logFilteredHub($hub, 'job_order_type'); + $this->hub_filter_logger->logFilteredHub($hub, 'job_order_type', $jo_id, $customer_id); } return $results; } - protected function filterHubsByPaymentMethod($hubs, $payment_method) + protected function filterHubsByPaymentMethod($hubs, $payment_method, $jo_id, $customer_id) { if (empty($hubs)) return $hubs; @@ -201,16 +201,16 @@ class HubSelector } if (!$flag_found_pmethod) - $this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method'); + $this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method', $jo_id, $customer_id); } else - $this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method'); + $this->hub_filter_logger->logFilteredHub($hub, 'no_payment_method', $jo_id, $customer_id); } return $results; } - protected function filterHubsByDateAndTime($hubs, $date_time) + protected function filterHubsByDateAndTime($hubs, $date_time, $jo_id, $customer_id) { if (empty($hubs)) return $hubs; @@ -245,13 +245,13 @@ class HubSelector ]; } else - $this->hub_filter_logger->logFilteredHub($hub, 'date_and_time'); + $this->hub_filter_logger->logFilteredHub($hub, 'date_and_time', $jo_id, $customer_id); } return $results; } - protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items) + protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id) { if (empty($hubs)) return $hubs; @@ -290,7 +290,7 @@ class HubSelector error_log($message); $this->sendSMSMessage($hub, $items); - $this->hub_filter_logger->logFilteredHub($hub, 'no_inventory'); + $this->hub_filter_logger->logFilteredHub($hub, 'no_inventory', $jo_id, $customer_id); } } if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY) @@ -317,7 +317,7 @@ class HubSelector error_log($message); $this->sendSMSMessage($hub, $items); - $this->hub_filter_logger->logFilteredHub($hub, 'no_inventory'); + $this->hub_filter_logger->logFilteredHub($hub, 'no_inventory', $jo_id, $customer_id); } } } @@ -326,7 +326,7 @@ class HubSelector return $results; } - protected function getClosestHubs(Point $point, $limit_distance) + protected function getClosestHubs(Point $point, $limit_distance, $jo_id, $customer_id) { // get closest hubs based on st_distance function from db $query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h WHERE h.status_open = true ORDER BY dist'; @@ -367,7 +367,7 @@ class HubSelector } else { - $this->hub_filter_logger->logFilteredHub($row[0], 'distance'); + $this->hub_filter_logger->logFilteredHub($row[0], 'not_within_distance', $jo_id, $customer_id); } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 3637e4a1..d5aeefd4 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1996,7 +1996,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if ($willing_to_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT) $hub_criteria->setEmergency(true); - $hubs = $hub_selector->find($hub_criteria); + // get JO and customer id for logging purposes + $jo_id = $obj->getID(); + $customer_id = $obj->getCustomer()->getID(); + + $hubs = $hub_selector->find($hub_criteria, $jo_id, $customer_id); $params['hubs'] = []; @@ -2293,7 +2297,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if ($willing_to_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT) $hub_criteria->setEmergency(true); - $hubs = $hub_selector->find($hub_criteria); + // get JO and customer id for logging purposes + $jo_id = $obj->getID(); + $customer_id = $obj->getCustomer()->getID(); + + $hubs = $hub_selector->find($hub_criteria, $jo_id, $customer_id); $params['status_cancelled'] = JOStatus::CANCELLED; $params['hubs'] = [];