Add hub selector filtering for available riders, refactor inventory filter to... #1731

Merged
arcticzero merged 42 commits from 800-automatically-reject-jo-if-no-riders-or-inventory into master 2024-07-18 08:34:03 +00:00
Showing only changes of commit 8da5381a1c - Show all commits

View file

@ -3026,8 +3026,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
//error_log("TOTAL HUBS FOUND WITH BRANCH CODE: " . count($inv_data)); //error_log("TOTAL HUBS FOUND WITH BRANCH CODE: " . count($inv_data));
// get all enabled filters
$enabled_filter_str = $_ENV['ENABLED_HUB_FILTERS'];
$enabled_filters = explode(",", $enabled_filter_str);
// 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 battery (if any) // get battery (if any)
/*
$skus = []; $skus = [];
$invoice = $obj->getInvoice(); $invoice = $obj->getInvoice();
$inv_items = $invoice->getItems(); $inv_items = $invoice->getItems();
@ -3072,7 +3079,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
error_log("SET QUANTITY OF " . $x . " HUBS TO NON ZERO"); error_log("SET QUANTITY OF " . $x . " HUBS TO NON ZERO");
// error_log(print_r($mres, true)); // error_log(print_r($mres, true));
*/ }
$params['obj'] = $obj; $params['obj'] = $obj;
// get template to display // get template to display
@ -4349,4 +4356,28 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
$this->rt->sendSMS($phone_number, $this->translator->trans('message.battery_brand_allcaps'), $msg); $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;
}
} }