From afbe3aa00b107e2341bbbe79d6449986816c308a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 10:34:01 +0000 Subject: [PATCH] Add route to fulfill a cancelled job order. #442 --- config/acl.yaml | 2 ++ config/routes/job_order.yaml | 4 +++ src/Controller/JobOrderController.php | 27 ++++++++++++++++++- .../JobOrderHandler/ResqJobOrderHandler.php | 14 ++++++++++ templates/job-order/form.html.twig | 4 +++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/config/acl.yaml b/config/acl.yaml index abd73118..81b49726 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -270,6 +270,8 @@ access_keys: label: Autoassign Test - id: jo_hub.list label: Hub View + - id: jo_cancel.fulfill + label: Fulfill Cancelled JO - id: support label: Customer Support Access diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index 586ed81f..5b5eadbe 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -253,3 +253,7 @@ jo_hub_view_form: controller: App\Controller\JobOrderController::hubViewForm methods: [GET] +jo_fulfill_cancel_submit: + path: /job-order/all/{id} + controller: App\Controller\JobOrderController::fulfillCancelSubmit + methods: [POST] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index f23fc73c..0d766b6d 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -631,7 +631,6 @@ class JobOrderController extends Controller $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); $params['vmakes'] = $em->getRepository(Vehicle::class)->findAll(); $params['return_url'] = $this->generateUrl('jo_all'); - $params['submit_url'] = ''; $params['map_js_file'] = $gis->getJSJOFile(); $template = $params['template']; @@ -1153,6 +1152,32 @@ class JobOrderController extends Controller return $this->render($template, $params); } + public function fulfillCancelSubmit(Request $req, JobOrderHandlerInterface $jo_handler, $id) + { + $this->denyAccessUnlessGranted('jo_cancel.fulfill', null, 'No access.'); + + // TODO: make the service function to fulfill the cancelled JO + /* + $error_array = []; + $result = $jo_handler->openEditJobOrder($req, $id); + + $error_array = $result['error_array']; + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } */ + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + /** * @Menu(selected="jo_autoassign") diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e6cc6ec8..e25c2b4a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -492,6 +492,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setTypeID(JOEventType::OPEN_EDIT) ->setJobOrder($obj); + error_log('open edit?'); + if ($user != null) { $event->setUser($user); @@ -1562,6 +1564,18 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->fillDropdownParameters($params); $this->fillFormTags($params); + // check JO status to determine the mode and submit_url to return + if ($obj->getStatus() == JOStatus::CANCELLED) + { + $params['mode'] = 'fulfill-cancel'; + $params['submit_url'] = 'jo_fulfill_cancel_submit'; + } + else + { + $params['mode'] = 'update-all'; + $params['submit_url'] = ''; + } + // get template to display $params['template'] = $this->getTwigTemplate('jo_all_form'); diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index bba70b39..ffa39b96 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -848,7 +848,11 @@
{% if mode != 'update-all' %} + {% if mode == 'fulfill-cancel' %} + + {% else %} + {% endif %} {% endif %} {% if ftags.set_map_coordinate and is_granted('joborder.cancel') and not obj.isCancelled %} Cancel Job Order