From 140ea8c7385d81dcfc2095dd7ffcf7ca8a3c1eb0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 27 Apr 2021 09:38:29 +0000 Subject: [PATCH] Add emergency filter. #554 --- src/Controller/APIController.php | 29 ++++++++++++ src/Ramcar/HubCriteria.php | 13 ++++++ src/Service/HubSelector.php | 46 ++++++++++--------- .../JobOrderHandler/ResqJobOrderHandler.php | 9 ++-- 4 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index cbd1af10..ff776f52 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -29,6 +29,7 @@ use App\Ramcar\JOEventType; use App\Ramcar\AdvanceOrderSlot; use App\Ramcar\AutoAssignStatus; use App\Ramcar\HubCriteria; +use App\Ramcar\WillingToWaitContent; use App\Service\InvoiceGeneratorInterface; use App\Service\RisingTideGateway; @@ -922,6 +923,14 @@ class APIController extends Controller implements LoggedController } $jo->setServiceType($stype); + // check if willing to wait is true or not + $will_wait = $req->request->get('willing_to_wait'); + // check for 'false' text + if ($will_wait === false || $will_wait === 0 || $will_wait === '0' || $will_wait == 'false') + $jo->setWillWait(WillingToWaitContent::NOT_WILLING_TO_WAIT); + else + $jo->setWillWait(WillingToWaitContent::WILLING_TO_WAIT); + // validate warranty $warr = $req->request->get('warranty'); if (!WarrantyClass::validate($warr)) @@ -1030,6 +1039,12 @@ class APIController extends Controller implements LoggedController if (!empty($jo->getModeOfPayment())) $hub_criteria->setPaymentMethod($jo->getModeOfPayment()); + // check if willing to wait is true or not + if ($jo->getWillWait() == WillingToWaitContent::NOT_WILLING_TO_WAIT) + { + $hub_criteria->setEmergency(true); + } + // find nearest hubs $nearest_hubs = $hub_select->find($hub_criteria); @@ -2449,6 +2464,14 @@ class APIController extends Controller implements LoggedController } $jo->setServiceType($stype); + // check if willing to wait is true or not + $will_wait = $req->request->get('willing_to_wait'); + // check for 'false' text + if ($will_wait === false || $will_wait === 0 || $will_wait === '0' || $will_wait == 'false') + $jo->setWillWait(WillingToWaitContent::NOT_WILLING_TO_WAIT); + else + $jo->setWillWait(WillingToWaitContent::WILLING_TO_WAIT); + // validate warranty $warr = $req->request->get('warranty'); if (!WarrantyClass::validate($warr)) @@ -2560,6 +2583,12 @@ class APIController extends Controller implements LoggedController if (!empty($jo->getModeOfPayment())) $hub_criteria->setPaymentMethod($jo->getModeOfPayment()); + // check if willing to wait is true or not + if ($jo->getWillWait() == WillingToWaitContent::NOT_WILLING_TO_WAIT) + { + $hub_criteria->setEmergency(true); + } + // find nearest hubs $nearest_hubs = $hub_select->find($hub_criteria); diff --git a/src/Ramcar/HubCriteria.php b/src/Ramcar/HubCriteria.php index 91f19c0e..f00c1281 100644 --- a/src/Ramcar/HubCriteria.php +++ b/src/Ramcar/HubCriteria.php @@ -16,6 +16,7 @@ class HubCriteria protected $date_time; // date and time to check if hub is open or not protected $items; // array of items: items[sku] = quantity to check for protected $payment_method; // payment method of JO + protected $flag_emergency; // flag if emergency or not public function __construct() { @@ -27,6 +28,7 @@ class HubCriteria $this->flag_inventory_check = false; $this->items = []; $this->payment_method = ''; + $flag_emergency = false; } public function setPoint(Point $point) @@ -124,4 +126,15 @@ class HubCriteria { return $this->payment_method; } + + public function setEmergency($flag_emergency = true) + { + $this->flag_emergency = $flag_emergency; + return $this; + } + + public function isEmergency() + { + return $this->flag_emergency; + } } diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index a323a8c3..a6bf9442 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -49,6 +49,7 @@ class HubSelector $items = $criteria->getItems(); $date_time = $criteria->getDateTime(); $payment_method = $criteria->getPaymentMethod(); + $flag_emergency = $criteria->isEmergency(); $results = []; @@ -57,34 +58,37 @@ class HubSelector //error_log('closest hubs ' . json_encode($filtered_hubs)); - // filter the first hub results for date and opening times - $hubs_date_time = $this->filterHubsByDateAndTime($filtered_hubs, $date_time); - $filtered_hubs = $hubs_date_time; + if (!$flag_emergency) + { + // filter the first hub results for date and opening times + $hubs_date_time = $this->filterHubsByDateAndTime($filtered_hubs, $date_time); + $filtered_hubs = $hubs_date_time; - // filter jo types - $hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type); - $filtered_hubs = $hubs_jo_type; + // filter jo types + $hubs_jo_type = $this->filterHubsByJoType($filtered_hubs, $jo_type); + $filtered_hubs = $hubs_jo_type; - // filter hubs by payment methods - $hubs_payment_method = $this->filterHubsByPaymentMethod($filtered_hubs, $payment_method); - $filtered_hubs = $hubs_payment_method; + // filter hubs by payment methods + $hubs_payment_method = $this->filterHubsByPaymentMethod($filtered_hubs, $payment_method); + $filtered_hubs = $hubs_payment_method; - // filter hubs by rider availability + // filter hubs by rider availability - // inventory filter - $hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, - $jo_type, $items); - $filtered_hubs = $hubs_inventory; + // inventory filter + $hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, + $jo_type, $items); + $filtered_hubs = $hubs_inventory; - // round robin filter - $hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs); - $filtered_hubs = $hubs_round_robin; + // round robin filter + $hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs); + $filtered_hubs = $hubs_round_robin; - //error_log(json_encode($filtered_hubs)); + //error_log(json_encode($filtered_hubs)); - // max results filter - $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results); - $filtered_hubs = $hubs_max_result; + // max results filter + $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results); + $filtered_hubs = $hubs_max_result; + } $results = $filtered_hubs; diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 04e9e513..fd1fb2af 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1898,9 +1898,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // get rejection reasons $params['rejection_reasons'] = JORejectionReason::getCollection(); - // set hub criteria - $hub_criteria = new HubCriteria(); - // get battery (if any) $skus = []; $items = []; @@ -1931,6 +1928,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setLimitResults(50) ->setPaymentMethod($obj->getModeOfPayment()) ->setJoType($obj->getServiceType()); + + // 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 = $map_tools->getClosestHubs($obj->getCoordinates(), 50, date("H:i:s"));