diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index b9e44c16..1ba355a2 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -24,6 +24,6 @@ jo_proc_form: methods: [GET] jo_proc_submit: - path: /job-order/processing + path: /job-order/processing/{id} controller: App\Controller\JobOrderController::processingSubmit methods: [POST] diff --git a/public/assets/css/style.css b/public/assets/css/style.css index c6ec12a6..c3219708 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -110,6 +110,10 @@ span.has-danger, text-align: center; } +.table-clickable tr { + cursor: pointer; +} + @media (min-width: 995px) { .modal-lg { max-width: 1024px; diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 17d438f7..69c40415 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -12,6 +12,8 @@ use App\Entity\CustomerVehicle; use App\Entity\Outlet; use App\Entity\Rider; +use App\Service\MapTools; + use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -235,6 +237,82 @@ class JobOrderController extends BaseController ]); } + public function processingForm(MapTools $map_tools, $id) + { + $this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.'); + + $params = $this->initParameters('jo_proc'); + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(JobOrder::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // get parent associations + $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); + $params['customers'] = $em->getRepository(Customer::class)->findAll(); + $params['outlet'] = $em->getRepository(Outlet::class)->findAll(); + $params['rider'] = $em->getRepository(Rider::class)->findAll(); + $params['service_types'] = ServiceType::getCollection(); + $params['statuses'] = JOStatus::getCollection(); + + // get closest outlets + $outlets = $map_tools->getClosestOutlets($obj->getCoordinates(), 10); + + $params['outlets'] = []; + + // format seconds into friendly time + foreach ($outlets as $outlet) { + $seconds = $outlet['duration']; + + if (!empty($seconds) && $seconds > 0) { + $hours = floor($seconds / 3600); + $minutes = floor(($seconds / 60) % 60); + $seconds = $seconds % 60; + + $outlet['duration'] = $hours . "hrs, " . $minutes . " mins, " . $seconds . " secs"; + } else { + $outlet['duration'] = false; + } + + $params['outlets'][] = $outlet; + } + + $params['obj'] = $obj; + + // response + return $this->render('job-order/form.html.twig', $params); + } + + public function processingSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('jo_in.list', null, 'No access.'); + + // initialize error list + $error_array = []; + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(JobOrder::class)->find($id); + + // make sure this object exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + error_log(print_r($req->request->all(), true)); + + // TODO: validation and saving of updated job order + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + // 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 diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 7659cce5..4607ee85 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -22,23 +22,32 @@