Add jo type, date, and inventory filters. #543

This commit is contained in:
Korina Cordero 2021-03-15 03:46:13 +00:00
parent de74290624
commit 498c88ce38

View file

@ -71,14 +71,36 @@ class HubSelector
protected function filterHubsByRoundRobin($hubs) protected function filterHubsByRoundRobin($hubs)
{ {
if (empty($hubs))
return $hubs;
} }
protected function filterHubsByMaxResults($hubs, $limit_result) protected function filterHubsByMaxResults($hubs, $limit_result)
{ {
if (empty($hubs))
return $hubs;
if (empty($limit_result))
return $hubs;
} }
protected function filterHubsByJoType($hubs, $jo_type) protected function filterHubsByJoType($hubs, $jo_type)
{ {
if (empty($hubs))
return $hubs;
if (empty($jo_type))
return $hubs;
$results = [];
foreach ($hubs as $hub)
{
$has_jo_type = false;
// check if hub offers the jo_type
// TODO: add service to hub
if ($has_jo_type)
$results[] = $hub;
}
return $results;
} }
protected function filterHubsByDateAndTime($hubs, $date_time) protected function filterHubsByDateAndTime($hubs, $date_time)
@ -95,6 +117,17 @@ class HubSelector
{ {
// go through each hub's opening times to check if hub is open // go through each hub's opening times to check if hub is open
// for the specified time // for the specified time
// get hub opening and closing times
$time_open = date("H:i:s", $hub->getTimeOpen());
$time_close = date("H:i:s", $hub->getTimeClose());
$filter_time = date("H:i:s", $date_time);
if (($filter_time >= $time_open) &&
($filter_time <= $time_close))
{
$results[] = $hub;
}
} }
return $results; return $results;
@ -115,11 +148,17 @@ class HubSelector
{ {
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_NEW) if ($jo_type == ServiceType::BATTERY_REPLACEMENT_NEW)
{ {
// call inventory // call inventory
$has_items = $this->checkInventory($items, $hub);
if ($has_items)
$results[] = $hub;
} }
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY) if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
{ {
// call inventory // call inventory
$has_items = $this->checkInventory($items, $hub);
if ($has_items)
$results[] = $hub;
} }
} }
} }
@ -174,8 +213,23 @@ class HubSelector
protected function checkInventory($items, $hub) protected function checkInventory($items, $hub)
{ {
// check if hub has all items // check if hub has all items
$skus = [];
$hubs[] = $hub;
$result = false;
foreach ($items as $item)
{
// add sap code of item/battery into array since
// getBranchesInventory takes in an array of hubs/branches
// and an array of skus
$sku[] = $item->getSAPCode();
}
// call InventoryManager's getBranchesInventory to check if hub has all items
$result = $this->im->getBranchesInventory($hubs, $skus);
// return true or false // return true or false
return $result;
} }
// convert db distance to kilometers // convert db distance to kilometers