From f57c9f5f4f00807547ad38771c26c7f96b9270fc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Feb 2023 03:08:17 +0000 Subject: [PATCH 1/4] Add CRUD for customer locations. #739 --- config/acl.yaml | 14 + config/menu.yaml | 4 + config/routes/customer_location.yaml | 35 +++ src/Controller/CustomerLocationController.php | 253 ++++++++++++++++++ src/Entity/CustomerLocation.php | 63 +++++ src/Entity/JobOrder.php | 18 ++ templates/customer-location/form.html.twig | 142 ++++++++++ templates/customer-location/list.html.twig | 146 ++++++++++ 8 files changed, 675 insertions(+) create mode 100644 config/routes/customer_location.yaml create mode 100644 src/Controller/CustomerLocationController.php create mode 100644 src/Entity/CustomerLocation.php create mode 100644 templates/customer-location/form.html.twig create mode 100644 templates/customer-location/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 64540ecf..0fe347e9 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -586,3 +586,17 @@ access_keys: label: Update - id: ownership_type.delete label: Delete + + - id: customer_location + label: Customer Location Access + acls: + - id: cust_location.menu + label: Menu + - id: cust_location.list + label: List + - id: cust_location.add + label: Add + - id: cust_location.update + label: Update + - id: cust_location.delete + label: Delete diff --git a/config/menu.yaml b/config/menu.yaml index b75a9d38..b2cccd56 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -249,3 +249,7 @@ main_menu: acl: ownership_type.menu label: Ownership Types parent: database + - id: customer_location_list + acl: cust_location.menu + label: Customer Locations + parent: database diff --git a/config/routes/customer_location.yaml b/config/routes/customer_location.yaml new file mode 100644 index 00000000..1ab10970 --- /dev/null +++ b/config/routes/customer_location.yaml @@ -0,0 +1,35 @@ +customer_location_list: + path: /customer-locations + controller: App\Controller\CustomerLocationController::index + methods: [GET] + +customer_location_rows: + path: /customer-locations/rowdata + controller: App\Controller\CustomerLocationController::datatableRows + methods: [POST] + +customer_location_add_form: + path: /customer-locations/newform + controller: App\Controller\CustomerLocationController::addForm + methods: [GET] + +customer_location_add_submit: + path: /customer-locations + controller: App\Controller\CustomerLocationController::addSubmit + methods: [POST] + +customer_location_update_form: + path: /customer-locations/{id} + controller: App\Controller\CustomerLocationController::updateForm + methods: [GET] + +customer_location_update_submit: + path: /customer-locations/{id} + controller: App\Controller\CustomerLocationController::updateSubmit + methods: [POST] + +customer_location_delete: + path: /customer-locations/{id} + controller: App\Controller\CustomerLocationController::deleteSubmit + methods: [DELETE] + diff --git a/src/Controller/CustomerLocationController.php b/src/Controller/CustomerLocationController.php new file mode 100644 index 00000000..f3287543 --- /dev/null +++ b/src/Controller/CustomerLocationController.php @@ -0,0 +1,253 @@ +render('customer-location/list.html.twig'); + } + + /** + * @IsGranted("cust_location.list") + */ + public function datatableRows(Request $req) + { + // get query builder + $qb = $this->getDoctrine() + ->getRepository(CustomerLocation::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $this->setQueryFilters($datatable, $tquery); + $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); + + // 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.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('cust_location.update')) + $row['meta']['update_url'] = $this->generateUrl('customer_location_update_form', ['id' => $row['id']]); + if ($this->isGranted('cust_location.delete')) + $row['meta']['delete_url'] = $this->generateUrl('customer_location_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="customer_location.list") + * @IsGranted("cust_location.add") + */ + public function addForm() + { + $cust_location = new CustomerLocation(); + $params = [ + 'cust_location' => $cust_location, + 'mode' => 'create', + ]; + + // response + return $this->render('customer-location/form.html.twig', $params); + } + + /** + * @IsGranted("cust_location.add") + */ + public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator) + { + $cust_location = new CustomerLocation(); + + $this->setObject($cust_location, $req); + + // validate + $errors = $validator->validate($cust_location); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->persist($cust_location); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + + } + + /** + * @Menu(selected="customer_location_list") + * @ParamConverter("cust_location", class="App\Entity\CustomerLocation") + * @IsGranted("cust_location.update") + */ + public function updateForm($id, EntityManagerInterface $em, CustomerLocation $cust_location) + { + $params = []; + $params['cust_location'] = $cust_location; + $params['mode'] = 'update'; + + // response + return $this->render('customer-location/form.html.twig', $params); + } + + /** + * @ParamConverter("cust_location", class="App\Entity\CustomerLocation") + * @IsGranted("cust_location.update") + */ + public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, CustomerLocation $cust_location) + { + $this->setObject($cust_location, $req); + + // validate + $errors = $validator->validate($cust_location); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + /** + * @ParamConverter("cust_location", class="App\Entity\CustomerLocation") + * @IsGranted("cust_location.update") + */ + public function deleteSubmit(EntityManagerInterface $em, CustomerLocation $cust_location) + { + // delete this object + $em->remove($cust_location); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + + protected function setObject(CustomerLocation $obj, Request $req) + { + // set and save values + $obj->setName($req->request->get('name')) + ->setCode($req->request->get('code')); + } + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + +} diff --git a/src/Entity/CustomerLocation.php b/src/Entity/CustomerLocation.php new file mode 100644 index 00000000..fd589685 --- /dev/null +++ b/src/Entity/CustomerLocation.php @@ -0,0 +1,63 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setCode($code) + { + $this->code = $code; + return $this; + } + + public function getCode() + { + return $this->code; + } +} diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index f9783568..b3b5a62e 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -422,6 +422,13 @@ class JobOrder */ protected $ownership_type; + // customer location + /** + * @ORM\ManyToOne(targetEntity="CustomerLocation", inversedBy="job_orders") + * @ORM\JoinColumn(name="cust_location_id", referencedColumnName="id", nullable=true) + */ + protected $cust_location; + public function __construct() { $this->date_create = new DateTime(); @@ -1199,4 +1206,15 @@ class JobOrder { return $this->ownership_type; } + + public function setCustomerLocation(CustomerLocation $cust_location = null) + { + $this->cust_location = $cust_location; + return $this; + } + + public function getCustomerLocation() + { + return $this->cust_location; + } } diff --git a/templates/customer-location/form.html.twig b/templates/customer-location/form.html.twig new file mode 100644 index 00000000..76af9e33 --- /dev/null +++ b/templates/customer-location/form.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Customer Locations

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Ownership Type + {{ cust_location.getName() }} + {% else %} + New Customer Location + {% endif %} +

+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/customer-location/list.html.twig b/templates/customer-location/list.html.twig new file mode 100644 index 00000000..f78a2833 --- /dev/null +++ b/templates/customer-location/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Customer Locations +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From 4717d7d9256ba37fc4136df757fe781b282997ba Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Feb 2023 07:13:48 +0000 Subject: [PATCH 2/4] Add customer location dropdown to JO form. #739 --- .../JobOrderHandler/ResqJobOrderHandler.php | 99 +++++++++++++++++-- templates/job-order/form.html.twig | 17 ++++ 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 9a9a44a5..880fb1c1 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -28,6 +28,7 @@ use App\Entity\Customer; use App\Entity\CustomerTag; use App\Entity\EmergencyType; use App\Entity\OwnershipType; +use App\Entity\CustomerLocation; use App\Ramcar\InvoiceCriteria; use App\Ramcar\ServiceType; @@ -424,6 +425,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + // get source of awareness if any $soa_type = $req->request->get('source_of_awareness', ''); @@ -489,7 +500,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setCallerClassification($caller_class) ->setGender($gender) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); // check if user is null, meaning call to create came from API if ($user != null) @@ -710,6 +722,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + if (empty($error_array)) { // get current user @@ -744,7 +766,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setCallerClassification($caller_class) ->setGender($gender) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); // did they change invoice? $invoice_items = $req->request->get('invoice_items', []); @@ -916,6 +939,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + if (empty($error_array)) { // coordinates @@ -947,7 +980,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setGender($gender) ->setCallerClassification($caller_class) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); // validate $errors = $this->validator->validate($obj); @@ -1065,6 +1099,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + // get current user $user = $this->security->getUser(); @@ -1098,7 +1142,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setCallerClassification($caller_class) ->setGender($gender) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); if ($user != null) { @@ -1205,6 +1250,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + if (empty($error_array)) { // coordinates $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); @@ -1232,7 +1287,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setGender($gender) ->setCallerClassification($caller_class) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); // validate $errors = $this->validator->validate($obj); @@ -1459,6 +1515,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + // get previously assigned hub, if any $old_hub = $obj->getHub(); @@ -1517,6 +1583,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setCallerClassification($caller_class) ->setEmergencyType($etype) ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location) ->clearRider(); if ($user != null) @@ -1744,6 +1811,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $ownertype_id = $req->request->get('ownership_type', 0); $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); + // check if customer location is set + // since we didn't provide a blank option in the dropdown, there is + // always a customer location set. + $cust_location_id = $req->request->get('cust_location'); + + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + if (empty($error_array)) { // rider mqtt event // NOTE: need to send this before saving because rider will be cleared @@ -1796,7 +1873,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setGender($gender) ->setCallerClassification($caller_class) ->setEmergencyType($etype) - ->setOwnershipType($owner_type); + ->setOwnershipType($owner_type) + ->setCustomerLocation($cust_location); if ($user != null) { @@ -3360,6 +3438,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } $params['ownership_types'] = $ownership_types; + // list of customer locations + $cust_locations = $em->getRepository(CustomerLocation::class)->findBy([], ['name' => 'ASC']); + $c_locations = []; + foreach ($cust_locations as $cust_location) + { + $c_locations[$cust_location->getID()] = $cust_location->getName(); + } + $params['cust_locations'] = $c_locations; + // list of hubs $hubs = $em->getRepository(Hub::class)->findBy([], ['name' => 'ASC']); $fac_hubs = []; diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index c90f863c..18ae6d27 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -560,6 +560,23 @@ Location +
+
+ + + +
+
+
+
From 2aef8e64e789cda01274984b0ba9680284077d07 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Feb 2023 08:02:37 +0000 Subject: [PATCH 3/4] Add blank option for customer location dropdown. Add checking for blank option. #739 --- .../JobOrderHandler/ResqJobOrderHandler.php | 119 ++++++++++-------- templates/job-order/form.html.twig | 1 + 2 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 880fb1c1..9c4b700e 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -426,14 +426,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } // get source of awareness if any $soa_type = $req->request->get('source_of_awareness', ''); @@ -723,14 +726,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } if (empty($error_array)) { @@ -940,14 +946,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } if (empty($error_array)) { @@ -1100,14 +1109,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } // get current user $user = $this->security->getUser(); @@ -1251,14 +1263,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } if (empty($error_array)) { // coordinates @@ -1516,14 +1531,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } // get previously assigned hub, if any $old_hub = $obj->getHub(); @@ -1812,14 +1830,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $owner_type = $em->getRepository(OwnershipType::class)->find($ownertype_id); // check if customer location is set - // since we didn't provide a blank option in the dropdown, there is - // always a customer location set. - $cust_location_id = $req->request->get('cust_location'); + $cust_location_id = $req->request->get('cust_location', 0); + if ($cust_location_id == 0) + $error_array['cust_location'] = 'Customer location is required.'; + else + { + // get customer location + $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - // get customer location - $cust_location = $em->getRepository(CustomerLocation::class)->find($cust_location_id); - if ($cust_location == null) - $error_array['cust_location'] = 'Invalid customer location'; + if ($cust_location == null) + $error_array['cust_location'] = 'Invalid customer location'; + } if (empty($error_array)) { // rider mqtt event diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 18ae6d27..9a8387b5 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -564,6 +564,7 @@