Add emergency filter. #554

This commit is contained in:
Korina Cordero 2021-04-27 09:38:29 +00:00
parent 63b989034d
commit 140ea8c738
4 changed files with 73 additions and 24 deletions

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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"));