Resolve "Motiv connectivity" #1415
9 changed files with 157 additions and 11 deletions
|
|
@ -11,3 +11,7 @@ test_gmap:
|
||||||
test_distance:
|
test_distance:
|
||||||
path: /test/distance
|
path: /test/distance
|
||||||
controller: App\Controller\TestController::distance
|
controller: App\Controller\TestController::distance
|
||||||
|
|
||||||
|
test_motiv_connector:
|
||||||
|
path: /test/motiv_connector
|
||||||
|
controller: App\Controller\TestController::motivConnector
|
||||||
|
|
|
||||||
|
|
@ -242,3 +242,10 @@ services:
|
||||||
App\EventSubscriber\LogSubscriber:
|
App\EventSubscriber\LogSubscriber:
|
||||||
arguments:
|
arguments:
|
||||||
$api_log_flag: "%env(API_LOGGING)%"
|
$api_log_flag: "%env(API_LOGGING)%"
|
||||||
|
|
||||||
|
# motiv connector
|
||||||
|
App\Service\MotivConnector:
|
||||||
|
arguments:
|
||||||
|
$base_url: "%env(MOTIV_BASE_URL)%"
|
||||||
|
$sub_key: "%env(MOTIV_KEY)%"
|
||||||
|
$token: "%env(MOTIV_TOKEN)%"
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,13 @@ use App\Service\MapTools;
|
||||||
use App\Service\MQTTClient;
|
use App\Service\MQTTClient;
|
||||||
use App\Service\APNSClient;
|
use App\Service\APNSClient;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
|
|
||||||
|
use App\Service\RiderTracker;
|
||||||
|
use App\Service\MotivConnector;
|
||||||
|
|
||||||
use App\Service\GeofenceTracker;
|
use App\Service\GeofenceTracker;
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
@ -32,7 +37,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use App\Service\RiderTracker;
|
|
||||||
|
|
||||||
use Catalyst\MenuBundle\Annotation\Menu;
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
|
@ -311,13 +315,13 @@ class JobOrderController extends Controller
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="jo_proc")
|
* @Menu(selected="jo_proc")
|
||||||
*/
|
*/
|
||||||
public function processingForm(MapTools $map_tools, $id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis)
|
public function processingForm(MapTools $map_tools, $id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis, MotivConnector $motiv)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
|
$this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$params = $jo_handler->initializeProcessingForm($id, $map_tools);
|
$params = $jo_handler->initializeProcessingForm($id, $map_tools, $motiv);
|
||||||
}
|
}
|
||||||
catch (AccessDeniedHttpException $e)
|
catch (AccessDeniedHttpException $e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,17 @@ use Catalyst\AuthBundle\Service\ACLGenerator;
|
||||||
|
|
||||||
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
use App\Entity\Outlet;
|
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
|
||||||
use App\Service\MapTools;
|
|
||||||
use Doctrine\Common\Util\Debug;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Doctrine\Common\Util\Debug;
|
||||||
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
|
|
||||||
use Catalyst\MenuBundle\Annotation\Menu;
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
|
use App\Entity\Outlet;
|
||||||
|
use App\Service\MapTools;
|
||||||
|
use App\Service\MotivConnector;
|
||||||
|
|
||||||
|
|
||||||
class TestController extends Controller
|
class TestController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,4 +66,20 @@ class TestController extends Controller
|
||||||
|
|
||||||
return $this->render('home.html.twig');
|
return $this->render('home.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="home")
|
||||||
|
*/
|
||||||
|
public function motivConnector(MotivConnector $motiv)
|
||||||
|
{
|
||||||
|
$branches = [
|
||||||
|
'ZL0133',
|
||||||
|
'ZL0033',
|
||||||
|
];
|
||||||
|
$skus = [
|
||||||
|
'ECHD26AL-SPN00-L',
|
||||||
|
'ECHD26AL-SPN00-LX',
|
||||||
|
];
|
||||||
|
$motiv->getInventory($branches, $skus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1627,7 +1627,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize dispatch/processing job order form
|
// initialize dispatch/processing job order form
|
||||||
public function initializeProcessingForm($id, $map_tools)
|
public function initializeProcessingForm($id, $map_tools, $motiv)
|
||||||
{
|
{
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1810,7 +1810,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize dispatch/processing job order form
|
// initialize dispatch/processing job order form
|
||||||
public function initializeProcessingForm($id, $map_tools)
|
public function initializeProcessingForm($id, $map_tools, $motiv)
|
||||||
{
|
{
|
||||||
$em = $this->em;
|
$em = $this->em;
|
||||||
|
|
||||||
|
|
@ -1881,6 +1881,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
|
|
||||||
$params['hubs'] = [];
|
$params['hubs'] = [];
|
||||||
|
|
||||||
|
$branch_codes = [];
|
||||||
|
$inv_data = [];
|
||||||
|
|
||||||
// format duration and distance into friendly time
|
// format duration and distance into friendly time
|
||||||
foreach ($hubs as $hub) {
|
foreach ($hubs as $hub) {
|
||||||
// duration
|
// duration
|
||||||
|
|
@ -1921,13 +1924,55 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$params['hubs'][] = $hub;
|
// handle inventory data
|
||||||
|
$bcode = $hub['hub']->getBranchCode();
|
||||||
|
$hub['inventory'] = 0;
|
||||||
|
if ($bcode != '')
|
||||||
|
{
|
||||||
|
$branch_codes[] = $bcode;
|
||||||
|
$inv_data[$bcode] = [
|
||||||
|
'hub_id' => $hub_id,
|
||||||
|
'branch_code' => $bcode,
|
||||||
|
'inventory' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$params['hubs'][$hub_id] = $hub;
|
||||||
}
|
}
|
||||||
|
|
||||||
$params['obj'] = $obj;
|
$params['obj'] = $obj;
|
||||||
// get template to display
|
// get template to display
|
||||||
$params['template'] = $this->getTwigTemplate('jo_processing_form');
|
$params['template'] = $this->getTwigTemplate('jo_processing_form');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
$skus[] = $batt->getSapCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get inventory
|
||||||
|
$mres = $motiv->getInventory($branch_codes, $skus);
|
||||||
|
foreach ($mres as $mres_item)
|
||||||
|
{
|
||||||
|
$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(print_r($mres, true));
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ interface JobOrderHandlerInterface
|
||||||
public function initializeAllForm(int $id);
|
public function initializeAllForm(int $id);
|
||||||
|
|
||||||
// initialize dispatch/processing job order form
|
// initialize dispatch/processing job order form
|
||||||
public function initializeProcessingForm(int $id, MapTools $map_tools);
|
public function initializeProcessingForm(int $id, MapTools $map_tools, $motiv);
|
||||||
|
|
||||||
// initialize assign job order form
|
// initialize assign job order form
|
||||||
public function initializeAssignForm(int $id);
|
public function initializeAssignForm(int $id);
|
||||||
|
|
|
||||||
65
src/Service/MotivConnector.php
Normal file
65
src/Service/MotivConnector.php
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
class MotivConnector
|
||||||
|
{
|
||||||
|
protected $base_url;
|
||||||
|
protected $sub_key;
|
||||||
|
protected $token;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct($base_url, $sub_key, $token)
|
||||||
|
{
|
||||||
|
$this->base_url = $base_url;
|
||||||
|
$this->sub_key = $sub_key;
|
||||||
|
$this->token = $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateToken()
|
||||||
|
{
|
||||||
|
// NOTE: no need for now, since we use the pre-generated token
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInventory($branch_codes = [], $skus = [])
|
||||||
|
{
|
||||||
|
$body = [
|
||||||
|
'BranchCodes' => $branch_codes,
|
||||||
|
'Skus' => $skus
|
||||||
|
];
|
||||||
|
|
||||||
|
$body_text = json_encode($body);
|
||||||
|
|
||||||
|
$res = $this->curlPost('InventoryService', $body_text);
|
||||||
|
|
||||||
|
return json_decode($res, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function curlPost($url, $body)
|
||||||
|
{
|
||||||
|
$curl = curl_init();
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
CURLOPT_URL => $this->base_url . '/' . $url,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POSTFIELDS => $body,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Ocp-Apim-Subscription-Key: ' . $this->sub_key,
|
||||||
|
'Authorization: Bearer ' . $this->token,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
curl_setopt_array($curl, $options);
|
||||||
|
$res = curl_exec($curl);
|
||||||
|
|
||||||
|
curl_close($curl);
|
||||||
|
|
||||||
|
error_log('MOTIV API connector');
|
||||||
|
error_log(print_r($options, true));
|
||||||
|
error_log($res);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -616,6 +616,7 @@
|
||||||
-->
|
-->
|
||||||
<th class="text-right">Available Riders</th>
|
<th class="text-right">Available Riders</th>
|
||||||
<th class="text-right">Jobs For Assignment</th>
|
<th class="text-right">Jobs For Assignment</th>
|
||||||
|
<th class="text-right">Inventory</th>
|
||||||
<th>Contact Numbers</th>
|
<th>Contact Numbers</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -637,6 +638,7 @@
|
||||||
-->
|
-->
|
||||||
<td class="text-right">{{ hub.rider_count }}</td>
|
<td class="text-right">{{ hub.rider_count }}</td>
|
||||||
<td class="text-right">{{ hub.jo_count }}</td>
|
<td class="text-right">{{ hub.jo_count }}</td>
|
||||||
|
<td class="text-right">{{ hub.inventory|default('0') }}</td>
|
||||||
<td>{{ hub.hub.getContactNumbers|replace({"\n": ', '}) }}</td>
|
<td>{{ hub.hub.getContactNumbers|replace({"\n": ', '}) }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if hub.flag_rejected %}
|
{% if hub.flag_rejected %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue