Check advance orders within 2 hours of order coming in before auto assigning #378
This commit is contained in:
parent
555d0dd3e7
commit
5eef2df4e0
1 changed files with 29 additions and 3 deletions
|
|
@ -51,6 +51,7 @@ use App\Entity\PrivacyPolicy;
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use DateInterval;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
// mobile API
|
// mobile API
|
||||||
|
|
@ -2289,8 +2290,7 @@ class APIController extends Controller implements LoggedController
|
||||||
return $cust;
|
return $cust;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findNearestHub($jo, EntityManagerInterface $em,
|
protected function findNearestHub($jo, EntityManagerInterface $em, MapTools $map_tools)
|
||||||
MapTools $map_tools)
|
|
||||||
{
|
{
|
||||||
// get the nearest 10 hubs
|
// get the nearest 10 hubs
|
||||||
$selected_hub = null;
|
$selected_hub = null;
|
||||||
|
|
@ -2314,7 +2314,33 @@ class APIController extends Controller implements LoggedController
|
||||||
$nearest = null;
|
$nearest = null;
|
||||||
foreach ($nearest_hubs_with_distance as $nhd)
|
foreach ($nearest_hubs_with_distance as $nhd)
|
||||||
{
|
{
|
||||||
if (count($nhd['hub']->getAvailableRiders()) > 0)
|
// get number of available riders
|
||||||
|
$count_riders = count($nhd['hub']->getAvailableRiders());
|
||||||
|
|
||||||
|
// get number of advance orders in the next 3 hours
|
||||||
|
$time_now = new DateTime();
|
||||||
|
$date_end = new DateTime();
|
||||||
|
$date_end->add(new DateInterval('PT2H'));
|
||||||
|
|
||||||
|
// NOTE: get advance orders via query
|
||||||
|
// get JOs assigned to hub that are advance orders and scheduled within 3 hours with
|
||||||
|
// for rider assignment status
|
||||||
|
$query = $em->createQuery('select count(jo) from App\Entity\JobOrder jo where jo.hub = :hub and jo.flag_advance = true and jo.date_schedule <= :date_end and jo.status = :status');
|
||||||
|
$count_advance_orders = $query->setParameters([
|
||||||
|
'hub' => $nhd['hub'],
|
||||||
|
'date_end' => $date_end,
|
||||||
|
'status' => JOStatus::RIDER_ASSIGN,
|
||||||
|
])
|
||||||
|
->setMaxResults(1)
|
||||||
|
->getSingleScalarResult();
|
||||||
|
|
||||||
|
error_log('HUB - ' . $nhd['hub']->getID());
|
||||||
|
error_log('RIDER COUNT - ' . $count_riders);
|
||||||
|
error_log('ADVANCE ORDER COUNT - ' . $count_advance_orders);
|
||||||
|
|
||||||
|
// if (count($nhd['hub']->getAvailableRiders()) > 0)
|
||||||
|
// if we have more riders than we have advance orders
|
||||||
|
if ($count_riders - $count_advance_orders > 0)
|
||||||
{
|
{
|
||||||
if (empty($nearest))
|
if (empty($nearest))
|
||||||
$nearest = $nhd;
|
$nearest = $nhd;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue