diff --git a/src/Ramcar/HubCriteria.php b/src/Ramcar/HubCriteria.php index cd10325d..b0b5fcfe 100644 --- a/src/Ramcar/HubCriteria.php +++ b/src/Ramcar/HubCriteria.php @@ -25,7 +25,7 @@ class HubCriteria $this->limit_distance = 500; $this->jo_type = ''; $this->date_time = null; - $this->has_inventory = false; + $this->flag_inventory_check = false; $this->items = []; $this->payment_method = ''; $flag_emergency = false; diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index c276000a..66506b90 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -64,24 +64,32 @@ class HubSelector $hubs_date_time = $this->filterHubsByDateAndTime($filtered_hubs, $date_time); $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); $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); $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); $filtered_hubs = $hubs_inventory; + //error_log('inventory hubs ' . json_encode($filtered_hubs)); + // round robin filter $hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs); $filtered_hubs = $hubs_round_robin; - error_log(json_encode($filtered_hubs)); + //error_log('round robin hubs ' . json_encode($filtered_hubs)); // max results filter $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 6c94509a..7807a6c8 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1945,6 +1945,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // get rejection reasons $params['rejection_reasons'] = JORejectionReason::getCollection(); + $hub_criteria = new HubCriteria(); + // get battery (if any) $skus = []; $items = []; @@ -1965,12 +1967,13 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $items[$sap_code] = $item_count + 1; else $items[$sap_code] = $item_count; + + $hub_criteria->addItem($sap_code, $item_count); } } // get closest hubs // set hub criteria - $hub_criteria = new HubCriteria(); $hub_criteria->setPoint($obj->getCoordinates()) ->setLimitResults(50) ->setPaymentMethod($obj->getModeOfPayment()) @@ -2229,8 +2232,34 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // get rejection reasons $params['rejection_reasons'] = JORejectionReason::getCollection(); - // get closest hubs $hub_criteria = new HubCriteria(); + + // get battery (if any) + $skus = []; + $items = []; + $invoice = $obj->getInvoice(); + $inv_items = $invoice->getItems(); + foreach ($inv_items as $inv_item) + { + $batt = $inv_item->getBattery(); + if ($batt == null) + continue; + + $skus[] = $batt->getSapCode(); + $item_count = 1; + if (!empty($batt->getSapCode())) + { + $sap_code = $batt->getSapCode(); + if (isset($items[$sap_code])) + $items[$sap_code] = $item_count + 1; + else + $items[$sap_code] = $item_count; + } + + $hub_criteria->addItem($sap_code, $item_count); + } + + // get closest hubs $hub_criteria->setPoint($obj->getCoordinates()) ->setLimitResults(50); $hubs = $hub_selector->find($hub_criteria);