Fix issue of invalid meta urls. #270
This commit is contained in:
parent
7989f6b6d6
commit
08bd23fe30
3 changed files with 11 additions and 246 deletions
|
|
@ -4,48 +4,25 @@ namespace App\Controller;
|
||||||
|
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
use App\Ramcar\JOStatus;
|
use App\Ramcar\JOStatus;
|
||||||
use App\Ramcar\WarrantyClass;
|
|
||||||
use App\Ramcar\DiscountApply;
|
|
||||||
use App\Ramcar\TradeInType;
|
use App\Ramcar\TradeInType;
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
use App\Ramcar\ModeOfPayment;
|
|
||||||
use App\Ramcar\TransactionOrigin;
|
|
||||||
use App\Ramcar\JOEventType;
|
|
||||||
use App\Ramcar\FacilitatedType;
|
|
||||||
use App\Ramcar\JORejectionReason;
|
|
||||||
|
|
||||||
use App\Entity\JobOrder;
|
|
||||||
use App\Entity\BatteryManufacturer;
|
|
||||||
use App\Entity\Customer;
|
|
||||||
use App\Entity\CustomerVehicle;
|
use App\Entity\CustomerVehicle;
|
||||||
//use App\Entity\Outlet;
|
|
||||||
use App\Entity\Hub;
|
|
||||||
use App\Entity\Promo;
|
use App\Entity\Promo;
|
||||||
use App\Entity\Rider;
|
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\JOEvent;
|
|
||||||
use App\Entity\JORejection;
|
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
use App\Service\JobOrderHandlerInterface;
|
use App\Service\JobOrderHandlerInterface;
|
||||||
use App\Service\MapTools;
|
use App\Service\MapTools;
|
||||||
use App\Service\HubCounter;
|
|
||||||
use App\Service\MQTTClient;
|
use App\Service\MQTTClient;
|
||||||
use App\Service\APNSClient;
|
use App\Service\APNSClient;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
|
||||||
use Doctrine\DBAL\Connection;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
use Catalyst\MenuBundle\Annotation\Menu;
|
use Catalyst\MenuBundle\Annotation\Menu;
|
||||||
|
|
||||||
use Mosquitto\Client as MosquittoClient;
|
|
||||||
use DateTime;
|
|
||||||
use DateInterval;
|
|
||||||
|
|
||||||
class JobOrderController extends Controller
|
class JobOrderController extends Controller
|
||||||
{
|
{
|
||||||
public function getJobOrders(Request $req, JobOrderHandlerInterface $jo_handler)
|
public function getJobOrders(Request $req, JobOrderHandlerInterface $jo_handler)
|
||||||
|
|
@ -168,78 +145,6 @@ class JobOrderController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkTier($tier)
|
|
||||||
{
|
|
||||||
// check specified tier
|
|
||||||
switch ($tier) {
|
|
||||||
case 'proc':
|
|
||||||
$tier_key = 'jo_proc';
|
|
||||||
$tier_name = 'Dispatch';
|
|
||||||
$rows_route = 'jo_proc_rows';
|
|
||||||
$edit_route = 'jo_proc_form';
|
|
||||||
$unlock_route = 'jo_proc_unlock';
|
|
||||||
$jo_status = JOStatus::PENDING;
|
|
||||||
break;
|
|
||||||
case 'assign':
|
|
||||||
$tier_key = 'jo_assign';
|
|
||||||
$tier_name = 'Assigning';
|
|
||||||
$rows_route = 'jo_assign_rows';
|
|
||||||
$edit_route = 'jo_assign_form';
|
|
||||||
$unlock_route = 'jo_assign_unlock';
|
|
||||||
$jo_status = JOStatus::RIDER_ASSIGN;
|
|
||||||
break;
|
|
||||||
case 'fulfill':
|
|
||||||
$tier_key = 'jo_fulfill';
|
|
||||||
$tier_name = 'Fullfillment';
|
|
||||||
$rows_route = 'jo_fulfill_rows';
|
|
||||||
$edit_route = 'jo_fulfill_form';
|
|
||||||
$unlock_route = '';
|
|
||||||
$jo_status = [
|
|
||||||
JOStatus::ASSIGNED,
|
|
||||||
JOStatus::IN_PROGRESS
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'open':
|
|
||||||
$tier_key = 'jo_open';
|
|
||||||
$tier_name = 'Open';
|
|
||||||
$rows_route = 'jo_open_rows';
|
|
||||||
$edit_route = '';
|
|
||||||
$unlock_route = '';
|
|
||||||
$jo_status = [
|
|
||||||
JOStatus::PENDING,
|
|
||||||
JOStatus::RIDER_ASSIGN,
|
|
||||||
JOStatus::ASSIGNED,
|
|
||||||
JOStatus::IN_PROGRESS,
|
|
||||||
JOStatus::IN_TRANSIT,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'all':
|
|
||||||
$tier_key = 'jo_open';
|
|
||||||
$tier_name = 'Open';
|
|
||||||
$rows_route = 'jo_open_rows';
|
|
||||||
$edit_route = 'jo_all_form';
|
|
||||||
$unlock_route = '';
|
|
||||||
$jo_status = '';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$exception = $this->createAccessDeniedException('No access.');
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check acl
|
|
||||||
$this->denyAccessUnlessGranted($tier_key . '.list', null, 'No access.');
|
|
||||||
|
|
||||||
// return params if allowed access
|
|
||||||
return [
|
|
||||||
'key' => $tier_key,
|
|
||||||
'name' => $tier_name,
|
|
||||||
'rows_route' => $rows_route,
|
|
||||||
'edit_route' => $edit_route,
|
|
||||||
'unlock_route' => $unlock_route,
|
|
||||||
'jo_status' => $jo_status
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="jo_proc")
|
* @Menu(selected="jo_proc")
|
||||||
*/
|
*/
|
||||||
|
|
@ -329,33 +234,35 @@ class JobOrderController extends Controller
|
||||||
throw $this->createAccessDeniedException($e->getMessage());
|
throw $this->createAccessDeniedException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj_rows = $params['rows'];
|
$rows = $params['rows'];
|
||||||
$meta = $params['meta'];
|
$meta = $params['meta'];
|
||||||
$tier_params = $params['tier_params'];
|
$tier_params = $params['tier_params'];
|
||||||
|
|
||||||
foreach ($obj_rows as $orow) {
|
foreach ($rows as $key => $data) {
|
||||||
// add crud urls
|
// add crud urls
|
||||||
|
$jo_id = $rows[$key]['id'];
|
||||||
|
|
||||||
if ($tier == 'open')
|
if ($tier == 'open')
|
||||||
{
|
{
|
||||||
$orow['meta']['reassign_hub_url'] = $this->generateUrl('jo_open_hub_form', ['id' => $orow['id']]);
|
$rows[$key]['meta']['reassign_hub_url'] = $this->generateUrl('jo_open_hub_form', ['id' => $jo_id]);
|
||||||
$orow['meta']['reassign_rider_url'] = $this->generateUrl('jo_open_rider_form', ['id' => $orow['id']]);
|
$rows[$key]['meta']['reassign_rider_url'] = $this->generateUrl('jo_open_rider_form', ['id' => $jo_id]);
|
||||||
$orow['meta']['edit_url'] = $this->generateUrl('jo_open_edit_form', ['id' => $orow['id']]);
|
$rows[$key]['meta']['edit_url'] = $this->generateUrl('jo_open_edit_form', ['id' => $jo_id]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$orow['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $orow['id']]);
|
$rows[$key]['meta']['update_url'] = $this->generateUrl($tier_params['edit_route'], ['id' => $jo_id]);
|
||||||
$orow['meta']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $orow['id']]);
|
$rows[$key]['meta']['pdf_url'] = $this->generateUrl('jo_pdf_form', ['id' => $jo_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tier_params['unlock_route'] != '')
|
if ($tier_params['unlock_route'] != '')
|
||||||
$orow['meta']['unlock_url'] = $this->generateUrl($tier_params['unlock_route'], ['id' => $orow['id']]);
|
$rows[$key]['meta']['unlock_url'] = $this->generateUrl($tier_params['unlock_route'], ['id' => $jo_id]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'meta' => $meta,
|
'meta' => $meta,
|
||||||
'data' => $obj_rows
|
'data' => $rows
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -504,58 +411,6 @@ class JobOrderController extends Controller
|
||||||
return $this->render('job-order/form.html.twig', $params);
|
return $this->render('job-order/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateVehicleBattery(JobOrder $jo)
|
|
||||||
{
|
|
||||||
// check if new battery
|
|
||||||
if ($jo->getServiceType() != ServiceType::BATTERY_REPLACEMENT_NEW)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// customer vehicle
|
|
||||||
$cv = $jo->getCustomerVehicle();
|
|
||||||
if ($cv == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// invoice
|
|
||||||
$invoice = $jo->getInvoice();
|
|
||||||
if ($invoice == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// invoice items
|
|
||||||
$items = $invoice->getItems();
|
|
||||||
if (count($items) <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// get first battery from invoice
|
|
||||||
$battery = null;
|
|
||||||
foreach ($items as $item)
|
|
||||||
{
|
|
||||||
$battery = $item->getBattery();
|
|
||||||
if ($battery != null)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no battery in order
|
|
||||||
if ($battery == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// warranty expiration
|
|
||||||
$warr = $jo->getWarrantyClass();
|
|
||||||
if ($warr == WarrantyClass::WTY_PRIVATE)
|
|
||||||
$warr_months = $battery->getWarrantyPrivate();
|
|
||||||
else if ($warr == WarrantyClass::WTY_COMMERCIAL)
|
|
||||||
$warr_months = $battery->getWarrantyCommercial();
|
|
||||||
else if ($warr == WarrantyClass::WTY_TNV)
|
|
||||||
$warr_months = 12;
|
|
||||||
|
|
||||||
$warr_date = new DateTime();
|
|
||||||
$warr_date->add(new DateInterval('P' . $warr_months . 'M'));
|
|
||||||
|
|
||||||
// update customer vehicle battery
|
|
||||||
$cv->setCurrentBattery($battery)
|
|
||||||
->setHasMotoliteBattery(true)
|
|
||||||
->setWarrantyExpiration($warr_date);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id)
|
public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.');
|
$this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.');
|
||||||
|
|
@ -588,25 +443,6 @@ class JobOrderController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendEvent(JobOrder $job_order, $payload)
|
|
||||||
{
|
|
||||||
$sessions = $job_order->getCustomer()->getMobileSessions();
|
|
||||||
if (count($sessions) == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$client = new MosquittoClient();
|
|
||||||
$client->connect('localhost', 1883);
|
|
||||||
|
|
||||||
foreach ($sessions as $sess)
|
|
||||||
{
|
|
||||||
$phone_num = $sess->getPhoneNumber();
|
|
||||||
$channel = 'motolite.control.' . $phone_num;
|
|
||||||
$client->publish($channel, json_encode($payload));
|
|
||||||
}
|
|
||||||
|
|
||||||
$client->disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="jo_open")
|
* @Menu(selected="jo_open")
|
||||||
*/
|
*/
|
||||||
|
|
@ -794,73 +630,6 @@ class JobOrderController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: re-enable search, figure out how to group the orWhere filters into one, so can execute that plus the pending filter
|
|
||||||
// check if datatable filter is present and append to query
|
|
||||||
protected function setQueryFilters($datatable, &$query, $qb, $hubs, $tier, $status)
|
|
||||||
{
|
|
||||||
switch ($tier)
|
|
||||||
{
|
|
||||||
case 'fulfill':
|
|
||||||
$query->where('q.status IN (:statuses)')
|
|
||||||
->andWhere('q.hub IN (:hubs)')
|
|
||||||
->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY)
|
|
||||||
->setParameter('hubs', $hubs, Connection::PARAM_STR_ARRAY);
|
|
||||||
break;
|
|
||||||
case 'assign':
|
|
||||||
$query->where('q.status = :status')
|
|
||||||
->andWhere('q.hub IN (:hubs)')
|
|
||||||
->setParameter('status', $status)
|
|
||||||
->setParameter('hubs', $hubs, Connection::PARAM_STR_ARRAY);
|
|
||||||
break;
|
|
||||||
case 'open':
|
|
||||||
if (isset($datatable['query']['data-rows-search']))
|
|
||||||
{
|
|
||||||
$query->innerJoin('q.cus_vehicle', 'cv')
|
|
||||||
->innerJoin('q.customer', 'c')
|
|
||||||
->where('q.status IN (:statuses)')
|
|
||||||
->andWhere('cv.plate_number like :filter or c.first_name like :filter or c.last_name like :filter or c.phone_mobile like :filter')
|
|
||||||
->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY)
|
|
||||||
->setParameter('filter', $datatable['query']['data-rows-search'] . '%');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$query->where('q.status IN (:statuses)')
|
|
||||||
->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'all':
|
|
||||||
if (isset($datatable['query']['data-rows-search']))
|
|
||||||
{
|
|
||||||
$query->innerJoin('q.cus_vehicle', 'cv')
|
|
||||||
->innerJoin('q.customer', 'c')
|
|
||||||
->where('cv.plate_number like :filter')
|
|
||||||
->orWhere('c.phone_mobile like :filter')
|
|
||||||
->orWhere('c.first_name like :filter or c.last_name like :filter')
|
|
||||||
->setParameter('filter', $datatable['query']['data-rows-search'] . '%');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$query->where('q.status = :status')
|
|
||||||
->setParameter('status', $status);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get only pending rows
|
|
||||||
/*
|
|
||||||
$query->where($qb->expr()->orX(
|
|
||||||
$qb->expr()where('q.status', 'pending');
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
// apply filters
|
|
||||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
|
||||||
$query->where('q.delivery_address LIKE :filter')
|
|
||||||
->orWhere($qb->expr()->concat('c.first_name', $qb->expr()->literal(' '), 'c.last_name') . ' LIKE :filter')
|
|
||||||
->orWhere('cv.plate_number LIKE :filter')
|
|
||||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function invoicePromo($em, InvoiceCriteria $criteria, $promo_id)
|
protected function invoicePromo($em, InvoiceCriteria $criteria, $promo_id)
|
||||||
{
|
{
|
||||||
// return error if there's a problem, false otherwise
|
// return error if there's a problem, false otherwise
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
||||||
else
|
else
|
||||||
$row['assignor'] = $orow->getAssignedBy()->getFullName();
|
$row['assignor'] = $orow->getAssignedBy()->getFullName();
|
||||||
|
|
||||||
$row['meta'] = [];
|
|
||||||
|
|
||||||
$rows[] = $row;
|
$rows[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,6 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
else
|
else
|
||||||
$row['assignor'] = $orow->getAssignedBy()->getFullName();
|
$row['assignor'] = $orow->getAssignedBy()->getFullName();
|
||||||
|
|
||||||
$row['meta'] = [];
|
|
||||||
|
|
||||||
$rows[] = $row;
|
$rows[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue