From 498c88ce3814292c724c0175476ce9e3030674c1 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 15 Mar 2021 03:46:13 +0000 Subject: [PATCH] Add jo type, date, and inventory filters. #543 --- src/Service/HubSelector.php | 56 ++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index ad6f54dd..2a9f7a80 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -71,14 +71,36 @@ class HubSelector protected function filterHubsByRoundRobin($hubs) { + if (empty($hubs)) + return $hubs; } protected function filterHubsByMaxResults($hubs, $limit_result) { + if (empty($hubs)) + return $hubs; + if (empty($limit_result)) + return $hubs; } 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) @@ -95,6 +117,17 @@ class HubSelector { // go through each hub's opening times to check if hub is open // 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; @@ -115,11 +148,17 @@ class HubSelector { 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) { // call inventory + $has_items = $this->checkInventory($items, $hub); + if ($has_items) + $results[] = $hub; } } } @@ -174,8 +213,23 @@ class HubSelector protected function checkInventory($items, $hub) { // 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 $result; } // convert db distance to kilometers