Fixes to issues found during testing. #543
This commit is contained in:
parent
498c88ce38
commit
0f245e9038
4 changed files with 102 additions and 28 deletions
|
|
@ -26,6 +26,7 @@ use App\Ramcar\TradeInType;
|
||||||
use App\Ramcar\JOEventType;
|
use App\Ramcar\JOEventType;
|
||||||
use App\Ramcar\AdvanceOrderSlot;
|
use App\Ramcar\AdvanceOrderSlot;
|
||||||
use App\Ramcar\AutoAssignStatus;
|
use App\Ramcar\AutoAssignStatus;
|
||||||
|
use App\Ramcar\HubCriteria;
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
use App\Service\RisingTideGateway;
|
use App\Service\RisingTideGateway;
|
||||||
|
|
@ -35,6 +36,7 @@ use App\Service\RiderTracker;
|
||||||
use App\Service\MapTools;
|
use App\Service\MapTools;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
use App\Service\RiderAssignmentHandlerInterface;
|
use App\Service\RiderAssignmentHandlerInterface;
|
||||||
|
use App\Service\HubSelector;
|
||||||
|
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
|
@ -2330,7 +2332,7 @@ class APIController extends Controller implements LoggedController
|
||||||
|
|
||||||
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
|
||||||
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
|
||||||
RiderAssignmentHandlerInterface $rah)
|
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -2515,24 +2517,40 @@ class APIController extends Controller implements LoggedController
|
||||||
// check if hub is null
|
// check if hub is null
|
||||||
if ($hub == null)
|
if ($hub == null)
|
||||||
{
|
{
|
||||||
|
// TODO: set this properly. This is test data
|
||||||
|
$hub_criteria = new HubCriteria();
|
||||||
|
$hub_criteria->setPoint($jo->getCoordinates())
|
||||||
|
->setLimitResults(1)
|
||||||
|
->setLimitDistance(5)
|
||||||
|
->setInventoryCheck(true)
|
||||||
|
->setJoType($jo->getServiceType())
|
||||||
|
->setDateTime(new DateTime());
|
||||||
|
|
||||||
|
// add battery to items
|
||||||
|
$sku = $batt->getSAPCode();
|
||||||
|
if (!empty($sku))
|
||||||
|
$hub_criteria->addItem($batt->getSAPCode(), 1);
|
||||||
|
|
||||||
// find nearest hub
|
// find nearest hub
|
||||||
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
if (($jo->getServiceType() == ServiceType::BATTERY_REPLACEMENT_NEW) ||
|
||||||
($jo->getServicetype() == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
($jo->getServicetype() == ServiceType::BATTERY_REPLACEMENT_WARRANTY))
|
||||||
{
|
{
|
||||||
// get nearest hub
|
// get nearest hub
|
||||||
// $nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
// $nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
||||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
//$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||||
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools);
|
||||||
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($nearest_hub))
|
if (!empty($nearest_hubs))
|
||||||
{
|
{
|
||||||
//error_log('found nearest hub ' . $nearest_hub->getID());
|
//error_log('found nearest hub ' . $nearest_hub->getID());
|
||||||
// assign rider
|
// assign rider
|
||||||
$available_riders = $nearest_hub->getAvailableRiders();
|
$available_riders = $nearest_hubs[0]['hub']->getAvailableRiders();
|
||||||
if (count($available_riders) > 0)
|
if (count($available_riders) > 0)
|
||||||
{
|
{
|
||||||
$assigned_rider = null;
|
$assigned_rider = null;
|
||||||
|
|
@ -2553,7 +2571,7 @@ class APIController extends Controller implements LoggedController
|
||||||
$assigned_rider = $available_riders[0];
|
$assigned_rider = $available_riders[0];
|
||||||
|
|
||||||
//error_log('found rider ' . $assigned_rider->getID());
|
//error_log('found rider ' . $assigned_rider->getID());
|
||||||
$jo->setHub($nearest_hub);
|
$jo->setHub($nearest_hubs[0]['hub']);
|
||||||
$jo->setRider($assigned_rider);
|
$jo->setRider($assigned_rider);
|
||||||
$jo->setStatus(JOStatus::ASSIGNED);
|
$jo->setStatus(JOStatus::ASSIGNED);
|
||||||
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class HubCriteria
|
||||||
protected $flag_inventory_check; // flag if we need to check for inventory
|
protected $flag_inventory_check; // flag if we need to check for inventory
|
||||||
protected $jo_type; // jo service needed
|
protected $jo_type; // jo service needed
|
||||||
protected $date_time; // date and time to check if hub is open or not
|
protected $date_time; // date and time to check if hub is open or not
|
||||||
protected $items; // array of items: items[id] = quantity to check for and has_inventory is true
|
protected $items; // array of items: items[sku] = quantity to check for
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -89,10 +89,10 @@ class HubCriteria
|
||||||
return $this->date_time;
|
return $this->date_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addItem($id, $quantity)
|
public function addItem($sku, $quantity)
|
||||||
{
|
{
|
||||||
// at this point, id is assumed to be a valid item
|
// at this point, sku is assumed to be a valid item
|
||||||
$this->items[$id] = $quantity;
|
$this->items[$sku] = $quantity;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,13 @@ class HubSelector
|
||||||
$filtered_hubs = $hubs_jo_type;
|
$filtered_hubs = $hubs_jo_type;
|
||||||
|
|
||||||
// inventory filter
|
// inventory filter
|
||||||
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $has_inventory,
|
$hubs_inventory = $this->filterHubsByInventory($filtered_hubs, $flag_inventory_check,
|
||||||
$jo_type, $items);
|
$jo_type, $items);
|
||||||
$filtered_hubs = $hubs_inventory;
|
$filtered_hubs = $hubs_inventory;
|
||||||
|
|
||||||
// round robin filter
|
// round robin filter
|
||||||
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
//$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
||||||
$filtered_hubs = $hubs_round_robin;
|
//$filtered_hubs = $hubs_round_robin;
|
||||||
|
|
||||||
// max results filter
|
// max results filter
|
||||||
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
||||||
|
|
@ -73,6 +73,9 @@ class HubSelector
|
||||||
{
|
{
|
||||||
if (empty($hubs))
|
if (empty($hubs))
|
||||||
return $hubs;
|
return $hubs;
|
||||||
|
|
||||||
|
// for now only
|
||||||
|
return $hubs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByMaxResults($hubs, $limit_result)
|
protected function filterHubsByMaxResults($hubs, $limit_result)
|
||||||
|
|
@ -81,6 +84,14 @@ class HubSelector
|
||||||
return $hubs;
|
return $hubs;
|
||||||
if (empty($limit_result))
|
if (empty($limit_result))
|
||||||
return $hubs;
|
return $hubs;
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
for ($i = 0; $i < $limit_result; $i++)
|
||||||
|
{
|
||||||
|
$results[] = $hubs[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByJoType($hubs, $jo_type)
|
protected function filterHubsByJoType($hubs, $jo_type)
|
||||||
|
|
@ -91,13 +102,21 @@ class HubSelector
|
||||||
return $hubs;
|
return $hubs;
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach ($hubs as $hub)
|
foreach ($hubs as $hub_data)
|
||||||
{
|
{
|
||||||
$has_jo_type = false;
|
$hub = $hub_data['hub'];
|
||||||
|
|
||||||
|
// TODO: for now, have this return true
|
||||||
|
$has_jo_type = true;
|
||||||
// check if hub offers the jo_type
|
// check if hub offers the jo_type
|
||||||
// TODO: add service to hub
|
// TODO: add service to hub
|
||||||
if ($has_jo_type)
|
if ($has_jo_type)
|
||||||
$results[] = $hub;
|
$results[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
@ -113,27 +132,34 @@ class HubSelector
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
foreach ($hubs as $hub)
|
foreach ($hubs as $hub_data)
|
||||||
{
|
{
|
||||||
// go through each hub's opening times to check if hub is open
|
// go through each hub's opening times to check if hub is open
|
||||||
// for the specified time
|
// for the specified time
|
||||||
// get hub opening and closing times
|
// get hub opening and closing times
|
||||||
$time_open = date("H:i:s", $hub->getTimeOpen());
|
$hub = $hub_data['hub'];
|
||||||
$time_close = date("H:i:s", $hub->getTimeClose());
|
|
||||||
|
|
||||||
$filter_time = date("H:i:s", $date_time);
|
$time_open = $hub->getTimeOpen()->format("H:i:s");
|
||||||
|
$time_close = $hub->getTimeClose()->format("H:i:s");
|
||||||
|
|
||||||
|
$filter_time = $date_time->format("H:i:s");
|
||||||
|
|
||||||
if (($filter_time >= $time_open) &&
|
if (($filter_time >= $time_open) &&
|
||||||
($filter_time <= $time_close))
|
($filter_time <= $time_close))
|
||||||
{
|
{
|
||||||
$results[] = $hub;
|
$results[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByInventory($hubs, $has_inventory, $jo_type, $items)
|
protected function filterHubsByInventory($hubs, $flag_inventory_check, $jo_type, $items)
|
||||||
{
|
{
|
||||||
if (empty($hubs))
|
if (empty($hubs))
|
||||||
return $hubs;
|
return $hubs;
|
||||||
|
|
@ -144,21 +170,33 @@ class HubSelector
|
||||||
$results = [];
|
$results = [];
|
||||||
if ($flag_inventory_check)
|
if ($flag_inventory_check)
|
||||||
{
|
{
|
||||||
foreach ($hubs as $hub)
|
foreach ($hubs as $hub_data)
|
||||||
{
|
{
|
||||||
|
$hub = $hub_data['hub'];
|
||||||
|
|
||||||
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_NEW)
|
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||||
{
|
{
|
||||||
// call inventory
|
// call inventory
|
||||||
$has_items = $this->checkInventory($items, $hub);
|
$has_items = $this->checkInventory($items, $hub);
|
||||||
if ($has_items)
|
if ($has_items)
|
||||||
$results[] = $hub;
|
$results[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
|
||||||
{
|
{
|
||||||
// call inventory
|
// call inventory
|
||||||
$has_items = $this->checkInventory($items, $hub);
|
$has_items = $this->checkInventory($items, $hub);
|
||||||
if ($has_items)
|
if ($has_items)
|
||||||
$results[] = $hub;
|
$results[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -214,19 +252,36 @@ class HubSelector
|
||||||
{
|
{
|
||||||
// check if hub has all items
|
// check if hub has all items
|
||||||
$skus = [];
|
$skus = [];
|
||||||
$hubs[] = $hub;
|
$branch_codes[] = $hub->getBranchCode();
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
foreach ($items as $item)
|
foreach ($items as $key=> $value)
|
||||||
{
|
{
|
||||||
// add sap code of item/battery into array since
|
// add sap code of item/battery into array since
|
||||||
// getBranchesInventory takes in an array of hubs/branches
|
// getBranchesInventory takes in an array of hubs/branches
|
||||||
// and an array of skus
|
// and an array of skus
|
||||||
$sku[] = $item->getSAPCode();
|
// $items as format: $items[sku] = quantity
|
||||||
|
$skus[] = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call InventoryManager's getBranchesInventory to check if hub has all items
|
// call InventoryManager's getBranchesInventory to check if hub has all items
|
||||||
$result = $this->im->getBranchesInventory($hubs, $skus);
|
$branches_with_items = $this->im->getBranchesInventory($branch_codes, $skus);
|
||||||
|
|
||||||
|
if (!empty($branches_with_items))
|
||||||
|
{
|
||||||
|
// check if branch has enough quantity for item
|
||||||
|
foreach ($branches_with_items as $branch)
|
||||||
|
{
|
||||||
|
// get quantity from call
|
||||||
|
$qty_available = $branch['Quantity'];
|
||||||
|
|
||||||
|
// get the quantity request
|
||||||
|
$sku_requested = $branch['SapCode'];
|
||||||
|
$qty_requested = $items[$sku_requested];
|
||||||
|
if ($qty_available >= $qty_requested)
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return true or false
|
// return true or false
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ class InventoryManager
|
||||||
|
|
||||||
// check if the response is empty
|
// check if the response is empty
|
||||||
$results = [];
|
$results = [];
|
||||||
|
//error_log($response);
|
||||||
if (!empty($response))
|
if (!empty($response))
|
||||||
$results = json_decode($response, true);
|
$results = json_decode($response, true);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue