Fix issues with inventory filter flow #800
This commit is contained in:
parent
89e5dd799f
commit
76496ed6fe
1 changed files with 27 additions and 6 deletions
|
|
@ -86,14 +86,14 @@ class HubSelector
|
|||
|
||||
//error_log('payment hubs ' . json_encode($filtered_hubs));
|
||||
|
||||
// inventory filter
|
||||
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id);
|
||||
$filtered_hubs = $hubs_inventory;
|
||||
|
||||
// available riders filter
|
||||
$hubs_riders = $this->filterHubsByRiderAvailability($filtered_hubs, $flag_riders_check, $jo_type, $jo_id, $customer_id);
|
||||
$filtered_hubs = $hubs_riders;
|
||||
|
||||
// inventory filter
|
||||
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id);
|
||||
$filtered_hubs = $hubs_inventory;
|
||||
|
||||
//error_log('inventory hubs ' . json_encode($filtered_hubs));
|
||||
|
||||
// round robin filter
|
||||
|
|
@ -266,18 +266,23 @@ class HubSelector
|
|||
|
||||
protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items, $jo_id, $customer_id)
|
||||
{
|
||||
error_log("IN INVENTORY CHECK NOW");
|
||||
|
||||
// check if this is enabled
|
||||
if (!$flag_inventory_check) {
|
||||
error_log("INVENTORY CHECK " . $jo_id . ": DISABLED");
|
||||
return $hubs;
|
||||
}
|
||||
|
||||
// check hub list is not empty
|
||||
if (empty($hubs)) {
|
||||
error_log("INVENTORY CHECK " . $jo_id . ": NO HUBS");
|
||||
return $hubs;
|
||||
}
|
||||
|
||||
// check item list is not empty
|
||||
if (empty($items)) {
|
||||
error_log("INVENTORY CHECK " . $jo_id . ": NO ITEMS");
|
||||
return $hubs;
|
||||
}
|
||||
|
||||
|
|
@ -285,22 +290,32 @@ class HubSelector
|
|||
if ($jo_type != ServiceType::BATTERY_REPLACEMENT_NEW &&
|
||||
$jo_type != ServiceType::BATTERY_REPLACEMENT_WARRANTY
|
||||
) {
|
||||
error_log("INVENTORY CHECK " . $jo_id . ": INVALID SERVICE TYPE");
|
||||
return $hubs;
|
||||
}
|
||||
|
||||
// get a list of all hubs with branch codes
|
||||
$hub_array = $hubs->toArray();
|
||||
$branch_codes = array_filter(array_column($hub_array, 'branch_code'));
|
||||
$branch_codes = [];
|
||||
foreach ($hubs as $hub_data) {
|
||||
$branch_codes[] = $hub_data['hub']->getBranchCode();
|
||||
};
|
||||
|
||||
$hubs_to_filter = [];
|
||||
$results = [];
|
||||
|
||||
// call inventory manager for all hubs for selected SKUs
|
||||
$skus = array_keys($items);
|
||||
|
||||
error_log("CHECKING INVENTORY FOR " . count($skus) . " ITEM(S) ON HUBS " . count($branch_codes) . "...");
|
||||
|
||||
$branches = $this->im->getBranchesInventory($branch_codes, $skus);
|
||||
|
||||
error_log("REQUEST COMPLETE, RESULT COUNT: " . count($branches));
|
||||
error_log(print_r($branches, true));
|
||||
|
||||
// check each result to see if sufficient quantity exists to meet request
|
||||
foreach ($branches as $branch) {
|
||||
error_log("CHECKING BRANCH " . print_r($branch, true));
|
||||
// filter out branch if it does not have sufficient inventory
|
||||
if ($branch['Quantity'] < $items[$branch['SapCode']] &&
|
||||
!isset($hubs_to_filter[$branch['BranchCode']])
|
||||
|
|
@ -309,6 +324,8 @@ class HubSelector
|
|||
}
|
||||
}
|
||||
|
||||
error_log("COMPLETED BRANCH CHECKS");
|
||||
|
||||
// remove filtered hubs from list
|
||||
foreach ($hubs as $hub_data) {
|
||||
$hub_obj = $hub_data['hub'];
|
||||
|
|
@ -325,6 +342,8 @@ class HubSelector
|
|||
}
|
||||
}
|
||||
|
||||
error_log("COMPLETED HUB FILTERING, TOTAL RESULTS: " . count($results));
|
||||
|
||||
// return filtered hubs
|
||||
return $results;
|
||||
|
||||
|
|
@ -427,6 +446,8 @@ class HubSelector
|
|||
|
||||
// log this filter
|
||||
$this->hub_filter_logger->logFilteredHub($hub_obj, 'no_available_rider', $jo_id, $customer_id);
|
||||
|
||||
error_log("FILTERED HUB " . $hub_obj->getID() . " (no_available_rider)");
|
||||
} else {
|
||||
$results[] = $hub_data;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue