Enable inventory retrieval if inventory checks are disabled #800
This commit is contained in:
parent
f8d90cbdcd
commit
8da5381a1c
1 changed files with 73 additions and 42 deletions
|
|
@ -3026,54 +3026,61 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
|
||||
//error_log("TOTAL HUBS FOUND WITH BRANCH CODE: " . count($inv_data));
|
||||
|
||||
// get battery (if any)
|
||||
/*
|
||||
$skus = [];
|
||||
$invoice = $obj->getInvoice();
|
||||
$inv_items = $invoice->getItems();
|
||||
foreach ($inv_items as $inv_item)
|
||||
{
|
||||
$batt = $inv_item->getBattery();
|
||||
if ($batt == null)
|
||||
continue;
|
||||
// get all enabled filters
|
||||
$enabled_filter_str = $_ENV['ENABLED_HUB_FILTERS'];
|
||||
$enabled_filters = explode(",", $enabled_filter_str);
|
||||
|
||||
$skus[] = $batt->getSapCode();
|
||||
}
|
||||
// if inventory filter is disabled, fetch inventory here
|
||||
if (!in_array('InventoryHubFilter', $enabled_filters) || $this->skipInventoryCheck($obj->getCoordinates())) {
|
||||
error_log("NO INVENTORY CHECKS, GETTING INVENTORY FOR JO " . $obj->getID());
|
||||
|
||||
// get inventory
|
||||
$mres = $motiv->getInventory($branch_codes, $skus);
|
||||
$x = 0;
|
||||
|
||||
error_log("TOTAL RESULTS FROM MOTIV: " . count($mres) . " OUT OF " . count($branch_codes) . " BRANCH CODES AND " . count($skus) . " SKUS");
|
||||
|
||||
foreach ($mres as $mres_item)
|
||||
{
|
||||
// check if we have a valid response from motiv, ignore otherwise
|
||||
if (isset($mres_item['BranchCode']))
|
||||
// get battery (if any)
|
||||
$skus = [];
|
||||
$invoice = $obj->getInvoice();
|
||||
$inv_items = $invoice->getItems();
|
||||
foreach ($inv_items as $inv_item)
|
||||
{
|
||||
$bcode = $mres_item['BranchCode'];
|
||||
$inv_count = $mres_item['Quantity'];
|
||||
if (isset($inv_data[$bcode]))
|
||||
{
|
||||
$hub_id = $inv_data[$bcode]['hub_id'];
|
||||
$batt = $inv_item->getBattery();
|
||||
if ($batt == null)
|
||||
continue;
|
||||
|
||||
$params['hubs'][$hub_id]['inventory'] = $inv_count;
|
||||
|
||||
error_log("SETTING HUB " . $hub_id . " INVENTORY TO " . $inv_count);
|
||||
$x++;
|
||||
} else {
|
||||
error_log("CANNOT FIND BCODE FOR " . $bcode);
|
||||
}
|
||||
} else {
|
||||
error_log("CANNOT FIND BCODE FOR RESULT: " . print_r($mres_item, true));
|
||||
$skus[] = $batt->getSapCode();
|
||||
}
|
||||
|
||||
// get inventory
|
||||
$mres = $motiv->getInventory($branch_codes, $skus);
|
||||
$x = 0;
|
||||
|
||||
error_log("TOTAL RESULTS FROM MOTIV: " . count($mres) . " OUT OF " . count($branch_codes) . " BRANCH CODES AND " . count($skus) . " SKUS");
|
||||
|
||||
foreach ($mres as $mres_item)
|
||||
{
|
||||
// check if we have a valid response from motiv, ignore otherwise
|
||||
if (isset($mres_item['BranchCode']))
|
||||
{
|
||||
$bcode = $mres_item['BranchCode'];
|
||||
$inv_count = $mres_item['Quantity'];
|
||||
if (isset($inv_data[$bcode]))
|
||||
{
|
||||
$hub_id = $inv_data[$bcode]['hub_id'];
|
||||
|
||||
$params['hubs'][$hub_id]['inventory'] = $inv_count;
|
||||
|
||||
error_log("SETTING HUB " . $hub_id . " INVENTORY TO " . $inv_count);
|
||||
$x++;
|
||||
} else {
|
||||
error_log("CANNOT FIND BCODE FOR " . $bcode);
|
||||
}
|
||||
} else {
|
||||
error_log("CANNOT FIND BCODE FOR RESULT: " . print_r($mres_item, true));
|
||||
}
|
||||
}
|
||||
|
||||
error_log("SET QUANTITY OF " . $x . " HUBS TO NON ZERO");
|
||||
|
||||
// error_log(print_r($mres, true));
|
||||
}
|
||||
|
||||
error_log("SET QUANTITY OF " . $x . " HUBS TO NON ZERO");
|
||||
|
||||
// error_log(print_r($mres, true));
|
||||
*/
|
||||
|
||||
|
||||
$params['obj'] = $obj;
|
||||
// get template to display
|
||||
$params['template'] = $this->getTwigTemplate('jo_open_hub_form');
|
||||
|
|
@ -4349,4 +4356,28 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
$this->rt->sendSMS($phone_number, $this->translator->trans('message.battery_brand_allcaps'), $msg);
|
||||
}
|
||||
|
||||
protected function skipInventoryCheck(Point $coordinates): bool
|
||||
{
|
||||
$long = $coordinates->getLongitude();
|
||||
$lat = $coordinates->getLatitude();
|
||||
|
||||
// get supported area given a set of coordinates
|
||||
$query = $this->em->createQuery('SELECT s from App\Entity\SupportedArea s where st_contains(s.coverage_area, point(:long, :lat)) = true');
|
||||
$area = $query->setParameter('long', $long)
|
||||
->setParameter('lat', $lat)
|
||||
->setMaxResults(1)
|
||||
->getOneOrNullResult();
|
||||
|
||||
if ($area !== null) {
|
||||
// get all exceptions
|
||||
$exceptions = $area->getHubFilterExceptions();
|
||||
|
||||
if (isset($exceptions['no_inventory'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// filter is in place
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue