158 lines
5.2 KiB
PHP
158 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Catalyst\MenuBundle\Annotation\Menu;
|
|
|
|
use App\Entity\JobOrder;
|
|
|
|
use App\Service\JobOrderHandlerInterface;
|
|
|
|
use App\Ramcar\TransactionOrigin;
|
|
use App\Ramcar\JOStatus;
|
|
use App\Ramcar\ServiceType;
|
|
use App\Ramcar\WillingToWaitContent;
|
|
use App\Ramcar\CustomerClassification;
|
|
|
|
class ResqJobOrderController extends Controller
|
|
{
|
|
/**
|
|
* @Menu(selected="jo_resq_proc")
|
|
* @IsGranted("jo_resq_proc.list")
|
|
*/
|
|
public function listProcessing()
|
|
{
|
|
$params['table_refresh_rate'] = $this->container->getParameter('job_order_refresh_interval');
|
|
|
|
return $this->render('resq-job-order/list.processing.html.twig', $params);
|
|
}
|
|
|
|
/**
|
|
* @IsGranted("jo_resq_proc.list")
|
|
*/
|
|
public function datatableRows(Request $req, JobOrderHandlerInterface $jo_handler)
|
|
{
|
|
// get query builder
|
|
$qb = $this->getDoctrine()
|
|
->getRepository(JobOrder::class)
|
|
->createQueryBuilder('q');
|
|
|
|
// get datatable params
|
|
$datatable = $req->request->get('datatable');
|
|
|
|
// count total records
|
|
$tquery = $qb->select('COUNT(q)');
|
|
|
|
$this->setQueryFilters($datatable, $tquery, $qb, JOStatus::PENDING, TransactionOrigin::MOBILE_APP);
|
|
|
|
$total = $tquery->getQuery()
|
|
->getSingleScalarResult();
|
|
|
|
// get current page number
|
|
$page = $datatable['pagination']['page'] ?? 1;
|
|
|
|
$perpage = $datatable['pagination']['perpage'];
|
|
$offset = ($page - 1) * $perpage;
|
|
|
|
// add metadata
|
|
$meta = [
|
|
'page' => $page,
|
|
'perpage' => $perpage,
|
|
'pages' => ceil($total / $perpage),
|
|
'total' => $total,
|
|
'sort' => 'asc',
|
|
'field' => 'id'
|
|
];
|
|
|
|
// build query
|
|
$query = $qb->select('q');
|
|
|
|
$this->setQueryFilters($datatable, $query, $qb, JOStatus::PENDING, TransactionOrigin::MOBILE_APP);
|
|
|
|
// check if sorting is present, otherwise use default
|
|
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
|
$order = $datatable['sort']['sort'] ?? 'asc';
|
|
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
|
} else {
|
|
$query->orderBy('q.date_schedule', 'asc');
|
|
}
|
|
|
|
// get rows for this page
|
|
$query_obj = $query->setFirstResult($offset)
|
|
->setMaxResults($perpage)
|
|
->getQuery();
|
|
|
|
$obj_rows = $query_obj->getResult();
|
|
|
|
$statuses = JOStatus::getCollection();
|
|
$service_types = ServiceType::getCollection();
|
|
|
|
// process rows
|
|
$rows = [];
|
|
foreach ($obj_rows as $orow) {
|
|
$is_vip = false;
|
|
$is_emergency = false;
|
|
|
|
// check if customer is vip
|
|
$cust_class = $orow->getCustomer()->getCustomerClassification();
|
|
if ($cust_class == CustomerClassification::VIP)
|
|
$is_vip = true;
|
|
|
|
// check if customer is not willing to wait
|
|
$will_not_wait = $orow->getWillWait();
|
|
if ($will_not_wait == WillingToWaitContent::NOT_WILLING_TO_WAIT)
|
|
$is_emergency = true;
|
|
|
|
// add row data
|
|
$row['id'] = $orow->getID();
|
|
$row['customer_name'] = $orow->getCustomer()->getFirstName() . ' ' . $orow->getCustomer()->getLastName();
|
|
$row['delivery_address'] = $orow->getDeliveryAddress();
|
|
$row['date_schedule'] = $orow->getDateSchedule()->format("d M Y g:i A");
|
|
$row['type'] = $orow->isAdvanceOrder() ? 'Advanced Order' : 'Immediate';
|
|
$row['service_type'] = $service_types[$orow->getServiceType()];
|
|
$row['status'] = $statuses[$orow->getStatus()];
|
|
$row['flag_advance'] = $orow->isAdvanceOrder();
|
|
$row['plate_number'] = $orow->getCustomerVehicle()->getPlateNumber();
|
|
$row['is_mobile'] = $orow->getSource() == TransactionOrigin::MOBILE_APP;
|
|
$row['is_vip'] = $is_vip;
|
|
$row['is_emergency'] = $is_emergency;
|
|
|
|
$processor = $orow->getProcessedBy();
|
|
if ($processor == null)
|
|
$row['processor'] = '';
|
|
else
|
|
$row['processor'] = $orow->getProcessedBy()->getFullName();
|
|
|
|
// add the items for Actions
|
|
$jo_id = $orow->getID();
|
|
|
|
$row['meta']['update_url'] = $this->generateUrl('jo_proc_form', ['id' => $jo_id, 'origin' => 'resq']);
|
|
$row['meta']['unlock_url'] = $this->generateUrl('jo_proc_unlock', ['id' => $jo_id, 'origin' => 'resq']);
|
|
|
|
$rows[] = $row;
|
|
}
|
|
|
|
// response
|
|
return $this->json([
|
|
'meta' => $meta,
|
|
'data' => $rows
|
|
]);
|
|
}
|
|
|
|
protected function setQueryFilters($datatable, &$query, $qb, $status, $source)
|
|
{
|
|
$query->where('q.status = :status')
|
|
->andWhere('q.source = :source')
|
|
->setParameter('status', $status)
|
|
->setParameter('source', $source);
|
|
}
|
|
}
|