From 505177360ee463a3dd4518dba20d304aa7adac50 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 08:58:41 +0000 Subject: [PATCH 01/14] Add date filter for hub view. #444 --- .../JobOrderHandler/ResqJobOrderHandler.php | 39 +++++++++++++------ templates/job-order/list.hubview.html.twig | 31 +++++++++++++++ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e6cc6ec8..6380878a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2765,20 +2765,35 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->andWhere('h.flag_hub_view = :flag_hub_view') ->setParameter('flag_hub_view', true); } + if (isset($datatable['query']['schedule_date'])) + { + $start = $datatable['query']['schedule_date'][0] . ' ' . '00:00:00'; + $end = $datatable['query']['schedule_date'][1] . ' ' . '23:59:00'; + + $date_start = DateTime::createFromFormat('m/d/Y H:i:s', $start); + $date_end = DateTime::createFromFormat('m/d/Y H:i:s', $end); + + $query->andWhere('q.date_schedule >= :date_start') + ->andWhere('q.date_schedule <= :date_end') + ->setParameter('date_start', $date_start) + ->setParameter('date_end', $date_end); + } + else + { + $c_date = new DateTime(); + $start_curr_date = $c_date->format('Y-m-d') . ' ' . '00:00:00'; + $end_curr_date = $c_date->format('Y-m-d') . ' ' . '23:59:00'; - $c_date = new DateTime(); - $start_curr_date = $c_date->format('Y-m-d') . ' ' . '00:00:00'; - $end_curr_date = $c_date->format('Y-m-d') . ' ' . '23:59:00'; + $start_current_date = DateTime::createFromFormat('Y-m-d H:i:s', $start_curr_date); + $end_current_date = DateTime::createFromFormat('Y-m-d H:i:s', $end_curr_date); - $start_current_date = DateTime::createFromFormat('Y-m-d H:i:s', $start_curr_date); - $end_current_date = DateTime::createFromFormat('Y-m-d H:i:s', $end_curr_date); - - $query->andWhere('q.date_schedule >= :start_current_date') - ->andWhere('q.date_schedule <= :end_current_date') - ->andWhere('q.status IN (:statuses)') - ->setParameter('start_current_date', $start_current_date) - ->setParameter('end_current_date', $end_current_date) - ->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY); + $query->andWhere('q.date_schedule >= :start_current_date') + ->andWhere('q.date_schedule <= :end_current_date') + ->andWhere('q.status IN (:statuses)') + ->setParameter('start_current_date', $start_current_date) + ->setParameter('end_current_date', $end_current_date) + ->setParameter('statuses', $status, Connection::PARAM_STR_ARRAY); + } break; default: $query->where('q.status = :status') diff --git a/templates/job-order/list.hubview.html.twig b/templates/job-order/list.hubview.html.twig index d59a76dc..e3f80710 100644 --- a/templates/job-order/list.hubview.html.twig +++ b/templates/job-order/list.hubview.html.twig @@ -42,6 +42,17 @@ +
+
+
+ +
+ +
+ +
+
+
@@ -59,6 +70,10 @@ {% block scripts %} {% endblock %} From afbe3aa00b107e2341bbbe79d6449986816c308a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 10:34:01 +0000 Subject: [PATCH 02/14] 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 From c3e36ad0551cc6fb98a8339e8790d0fd0f66ef68 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jul 2020 05:58:21 +0000 Subject: [PATCH 03/14] Add fulfill for cancelled job orders. #442 --- config/routes/job_order.yaml | 2 +- src/Controller/JobOrderController.php | 5 ++- .../JobOrderHandler/ResqJobOrderHandler.php | 33 +++++++++++++++++++ templates/job-order/form.html.twig | 24 +++++++++++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index 5b5eadbe..f31dd94b 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -254,6 +254,6 @@ jo_hub_view_form: methods: [GET] jo_fulfill_cancel_submit: - path: /job-order/all/{id} + path: /job-order/fulfillcancel/{id} controller: App\Controller\JobOrderController::fulfillCancelSubmit methods: [POST] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 0d766b6d..11d761eb 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -1157,9 +1157,8 @@ class JobOrderController extends Controller $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); + $result = $jo_handler->fulfillCancelledJobOrder($req, $id); $error_array = $result['error_array']; @@ -1170,7 +1169,7 @@ class JobOrderController extends Controller 'success' => false, 'errors' => $error_array ], 422); - } */ + } // return successful response return $this->json([ diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e25c2b4a..da1690c5 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2968,4 +2968,37 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface return $params; } + public function fulfillCancelledJobOrder(Request $req, $id) + { + // initialize error list + $error_array = []; + + // get object data + $em = $this->em; + $obj = $em->getRepository(JobOrder::class)->find($id); + + // make sure this object exists + if (empty($obj)) + throw new NotFoundHttpException('The item does not exist'); + + $obj->fulfill(); + + // the event + $event = new JOEvent(); + $event->setDateHappen(new DateTime()) + ->setTypeID(JOEventType::FULFILL) + ->setJobOrder($obj); + + // get current user + $user = $this->security->getUser(); + if ($user != null) + { + $event->setUser($user); + } + + $event->setUser($user); + $em->persist($event); + $em->flush(); + } + } diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index ffa39b96..9d8d5dc4 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -849,7 +849,7 @@
{% if mode != 'update-all' %} {% if mode == 'fulfill-cancel' %} - + Fulfill {% else %} {% endif %} @@ -1772,6 +1772,28 @@ $(function() { }); }); }); + + // fulfill cancelled job order + $(".btn-fulfill-cancel-job-order").click(function(e) { + var url = $(this).prop('href'); + + e.preventDefault(); + + $.ajax({ + method: "POST", + url: url, + }).done(function(response) { + swal({ + title: 'Done!', + text: response.success, + type: 'success', + onClose: function() { + window.location.href = "{{ return_url }}"; + } + }); + }); + + }); }); {% endblock %} From ed0eefc1d896550acded6560a12941efa58d3b0b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jul 2020 06:48:40 +0000 Subject: [PATCH 04/14] Add Battery Facilitated By column in View All. #443 --- src/Service/JobOrderHandler/ResqJobOrderHandler.php | 6 ++++++ templates/job-order/list.all.html.twig | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 5bbb3f2e..cc394b1c 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -183,6 +183,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface else $row['assignor'] = $orow->getAssignedBy()->getFullName(); + $hub_facilitated = $orow->getFacilitatedBy(); + if ($hub_facilitated == null) + $row['hub_facilitated'] = ''; + else + $row['hub_facilitated'] = $orow->getFacilitatedBy()->getName(); + $rows[] = $row; } diff --git a/templates/job-order/list.all.html.twig b/templates/job-order/list.all.html.twig index 01ff98d5..a2c6b7c6 100644 --- a/templates/job-order/list.all.html.twig +++ b/templates/job-order/list.all.html.twig @@ -116,6 +116,10 @@ field: 'delivery_address', title: 'Customer Area' }, + { + field: 'hub_facilitated', + title: 'Battery Facilitated By' + }, { field: 'type', title: 'Schedule' From 18dd63ac16e2ab7e88f9ff6c177191bac4e8944d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jul 2020 08:07:56 +0000 Subject: [PATCH 05/14] Make Landmark field in JO required. #447 --- src/Service/JobOrderHandler/ResqJobOrderHandler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index cc394b1c..c578d30a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -320,6 +320,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + // TODO: check status before saving since JO might already // have a status that needs to be retained From 964dce9842f853a962fc5c77f90a2563f5988c42 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 28 Jul 2020 10:10:59 +0000 Subject: [PATCH 06/14] Add Willing to Wait tickbox and Reason for not waiting text field. #445 --- src/Entity/JobOrder.php | 34 ++++++++++++++++++ .../JobOrderHandler/ResqJobOrderHandler.php | 24 +++++++++++-- templates/job-order/form.html.twig | 12 +++++++ utils/mqtt_rider/rider_location_cache.pyc | Bin 1929 -> 1929 bytes 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 8bcdbb77..6309dc6d 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -334,6 +334,18 @@ class JobOrder */ protected $phone_mobile; + // flag if customer is willing to wait + /** + * @ORM\Column(type="boolean", nullable=true) + */ + protected $flag_will_wait; + + // reason for not willing to wait + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $reasons_not_waiting; + public function __construct() { $this->date_create = new DateTime(); @@ -356,6 +368,8 @@ class JobOrder $this->meta = []; $this->phone_mobile = ''; + + $this->flag_will_wait = true; } public function getID() @@ -962,5 +976,25 @@ class JobOrder return $this->phone_mobile; } + public function setWillingToWait($flag = true) + { + $this->flag_will_wait = $flag; + return $this; + } + public function isWillingToWait() + { + return $this->flag_will_wait; + } + + public function setReasonsNotWait($reasons) + { + $this->reasons_not_waiting = $reasons; + return $this; + } + + public function getReasonsNotWait() + { + return $this->reasons_not_waiting; + } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index c578d30a..28fa2c0f 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -324,6 +324,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if (empty($req->request->get('landmark'))) $error_array['landmark'] = 'Landmark is required.'; + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + // TODO: check status before saving since JO might already // have a status that needs to be retained @@ -353,7 +359,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setORName($req->request->get('or_name')) ->setPromoDetail($req->request->get('promo_detail')) ->setModeOfPayment($req->request->get('mode_of_payment')) - ->setLandmark($req->request->get('landmark')); + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); // check if user is null, meaning call to create came from API if ($user != null) @@ -444,6 +452,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.'; } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + if (empty($error_array)) { // get current user @@ -468,7 +486,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setORName($req->request->get('or_name')) ->setPromoDetail($req->request->get('promo_detail')) ->setModeOfPayment($req->request->get('mode_of_payment')) - ->setLandmark($req->request->get('landmark')); + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); // did they change invoice? $invoice_items = $req->request->get('invoice_items', []); diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 9d8d5dc4..b449bad0 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -292,6 +292,18 @@
+
+
+ + + +
+
+ + + +
+
diff --git a/utils/mqtt_rider/rider_location_cache.pyc b/utils/mqtt_rider/rider_location_cache.pyc index e8968436ff784ec3bb1aca3ba18a64dba399a0d8..a5798640299d44a6305d0987feb0c64b2a312daa 100644 GIT binary patch delta 36 rcmeC=@8oA^{>;mDW@+0-_A)kpMlL2HMgc|^Mj<8vMgiu@J#2pgq&5f- delta 36 rcmeC=@8oA^{>;l2t*F0|y^M{YiHli?QGk(!QHWW9Nq}W?58Gb=f}IA) From ca37b72d5794e831ad792b91d239ee81625832a7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 29 Jul 2020 05:22:33 +0000 Subject: [PATCH 07/14] Check if role has permission to fulfill cancelled orders. #453 --- templates/job-order/form.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index b449bad0..37857d15 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -860,7 +860,7 @@
{% if mode != 'update-all' %} - {% if mode == 'fulfill-cancel' %} + {% if mode == 'fulfill-cancel' and is_granted('jo_cancel.fulfill') %} Fulfill {% else %} From 3af78fd49bb7cc4db824c2f8a6e12c42959ae4f0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 30 Jul 2020 03:23:03 +0000 Subject: [PATCH 08/14] Add checking for SSL_ENABLE for Dashboard. #453 --- .env.dist | 3 +++ config/packages/twig.yaml | 1 + public/assets/js/map_mqtt.js | 5 +++-- templates/home.html.twig | 11 ++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.env.dist b/.env.dist index bd82f980..9fc0a002 100644 --- a/.env.dist +++ b/.env.dist @@ -74,3 +74,6 @@ MAPTILER_API_KEY=map_tiler_api_key # API version API_VERSION=insert_api_version_here + +#SSL_ENABLE for websockets +SSL_ENABLE=set_to_true_or_false diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 1c848030..ade96bcc 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -8,3 +8,4 @@ twig: mqtt_host: "%env(MQTT_WS_HOST)%" mqtt_port: "%env(MQTT_WS_PORT)%" dashboard_enable: "%env(DASHBOARD_ENABLE)%" + ssl_enable: "%env(SSL_ENABLE)%" diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 0e6bdb31..250e00c6 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -1,7 +1,8 @@ class MapEventHandler { - constructor(options, dashmap) { + constructor(options, dashmap, ssl) { this.options = options; this.dashmap = dashmap; + this.ssl = ssl; } connect(user_id, host, port) { @@ -11,7 +12,7 @@ class MapEventHandler { this.mqtt = new Paho.MQTT.Client(host, port, client_id); var options = { - // useSSL: true, + useSSL: this.ssl, timeout: 3, invocationContext: this, onSuccess: this.onConnect.bind(this), diff --git a/templates/home.html.twig b/templates/home.html.twig index 69cb59c0..ebe8cff3 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -45,7 +45,7 @@ function initMap(r_markers, c_markers, icons) { return dashmap; } -function initEventHandler(dashmap) { +function initEventHandler(dashmap, icons, ssl) { var options = { 'track_jo': true, 'track_rider': true, @@ -58,7 +58,7 @@ function initEventHandler(dashmap) { }, }; - var event_handler = new MapEventHandler(options, dashmap); + var event_handler = new MapEventHandler(options, dashmap, ssl); event_handler.connect('{{ app.user.getID }}', '{{ mqtt_host }}', {{ mqtt_port }}); } @@ -94,8 +94,13 @@ var icons = { var r_markers = {}; var c_markers = {}; + var ssl = false; + {% if ssl_enable == 'true' %} + ssl = true; + {% endif %} + var dashmap = initMap(r_markers, c_markers, icons); - initEventHandler(dashmap, icons); + initEventHandler(dashmap, icons, ssl); {% endif %} From 4cd75acb46613a58e6ca8096aade13b1de0ea55e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 31 Jul 2020 01:42:50 +0000 Subject: [PATCH 09/14] Add updating of landmark, willing to wait, and reason when updating JO form. #453 --- .../JobOrderHandler/ResqJobOrderHandler.php | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 28fa2c0f..9c8fbd1e 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -619,6 +619,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $fac_by = null; } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + if (empty($error_array)) { // coordinates @@ -638,7 +648,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setDeliveryAddress($req->request->get('delivery_address')) ->setFacilitatedType($fac_type) ->setFacilitatedBy($fac_by) - ->setHub($hub); + ->setHub($hub) + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); // validate $errors = $this->validator->validate($obj); @@ -712,6 +725,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + // get current user $user = $this->security->getUser(); @@ -732,7 +755,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setTier2Notes($req->request->get('tier2_notes')) ->setDeliveryAddress($req->request->get('delivery_address')) ->setDateAssign(new DateTime()) - ->setRider($rider); + ->setRider($rider) + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); if ($user != null) { @@ -795,6 +821,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.'; } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + if (empty($error_array)) { // coordinates $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); @@ -809,7 +845,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setDeliveryInstructions($req->request->get('delivery_instructions')) ->setTier1Notes($req->request->get('tier1_notes')) ->setTier2Notes($req->request->get('tier2_notes')) - ->setDeliveryAddress($req->request->get('delivery_address')); + ->setDeliveryAddress($req->request->get('delivery_address')) + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); // validate $errors = $this->validator->validate($obj); @@ -979,6 +1018,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + if (empty($error_array)) { // rider mqtt event @@ -1006,7 +1055,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setTier2Notes($req->request->get('tier2_notes')) ->setDeliveryAddress($req->request->get('delivery_address')) ->setHub($hub) - ->clearRider(); + ->clearRider() + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); if ($user != null) { @@ -1180,6 +1232,16 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // check if landmark is set + if (empty($req->request->get('landmark'))) + $error_array['landmark'] = 'Landmark is required.'; + + // check if customer is not willing to wait + $will_wait = $req->request->get('flag_will_wait'); + $reason = $req->request->get('no_wait_reason'); + if ((!($will_wait)) && (empty($reason))) + $error_array['no_wait_reason'] = 'Reason is needed.'; + if (empty($error_array)) { // rider mqtt event // NOTE: need to send this before saving because rider will be cleared @@ -1206,7 +1268,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setTier2Notes($req->request->get('tier2_notes')) ->setDeliveryAddress($req->request->get('delivery_address')) ->setDateAssign(new DateTime()) - ->setRider($rider); + ->setRider($rider) + ->setLandmark($req->request->get('landmark')) + ->setWillingToWait($req->request->get('flag_will_wait', false)) + ->setReasonsNotWait($req->request->get('no_wait_reason')); if ($user != null) { From 2e9a5585d4c2edc41c894967d6484c77be329350 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 3 Aug 2020 10:58:36 +0000 Subject: [PATCH 10/14] Add dropdown for cancellation reasons. #449 --- config/routes/job_order.yaml | 5 ++ src/Controller/JobOrderController.php | 9 +++ src/Ramcar/JOCancelReasons.php | 26 +++++++ .../JobOrderHandler/ResqJobOrderHandler.php | 1 + templates/job-order/form.html.twig | 78 ++++++++++--------- 5 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 src/Ramcar/JOCancelReasons.php diff --git a/config/routes/job_order.yaml b/config/routes/job_order.yaml index f31dd94b..621195b1 100644 --- a/config/routes/job_order.yaml +++ b/config/routes/job_order.yaml @@ -257,3 +257,8 @@ jo_fulfill_cancel_submit: path: /job-order/fulfillcancel/{id} controller: App\Controller\JobOrderController::fulfillCancelSubmit methods: [POST] + +jo_cancel_reasons: + path: /ajax/jo_cancel_reasons + controller: App\Controller\JobOrderController::cancelReasons + methods: [GET] diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 11d761eb..a5e6883e 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -6,6 +6,7 @@ use App\Ramcar\JOStatus; use App\Ramcar\InvoiceCriteria; use App\Ramcar\CMBServiceType; use App\Ramcar\ServiceType; +use App\Ramcar\JOCancelReasons; use App\Entity\CustomerVehicle; use App\Entity\Promo; @@ -1177,6 +1178,14 @@ class JobOrderController extends Controller ]); } + // ajax call + public function cancelReasons() + { + error_log('start cancel_reasons'); + return $this->json([ + 'cancel_reasons' => JOCancelReasons::getCollection(), + ]); + } /** * @Menu(selected="jo_autoassign") diff --git a/src/Ramcar/JOCancelReasons.php b/src/Ramcar/JOCancelReasons.php new file mode 100644 index 00000000..b5a7a99c --- /dev/null +++ b/src/Ramcar/JOCancelReasons.php @@ -0,0 +1,26 @@ + 'Wrong Battery', + 'customer_no_show' => 'Customer No Show', + 'reschedule' => 'Reschedule', + 'location_change' => 'Change Location', + 'battery_working' => 'Battery is Already Working', + 'late_delivery' => 'Late Delivery', + 'customer_bought_new_battery' => 'Customer Already Bought New Battery from Nearby Outlet', + 'battery_no_stock' => 'No Stock of Battery', + ]; +} diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 9c8fbd1e..a6c841ca 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -954,6 +954,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface throw new NotFoundHttpException('The item does not exist'); $cancel_reason = $req->request->get('cancel_reason'); + error_log($cancel_reason); $obj->cancel($cancel_reason); // the event diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 37857d15..25027fdc 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -1746,44 +1746,50 @@ $(function() { // cancel job order $(".btn-cancel-job-order").click(function(e) { - var url = $(this).prop('href'); + var url = $(this).prop('href'); - e.preventDefault(); + e.preventDefault(); - swal({ - title: 'Cancel Job Order', - html: 'Please enter the reason for cancellation of this job order:', - input: 'textarea', - inputClass: 'form-control', - type: 'warning', - showCancelButton: true, - width: '40rem', - preConfirm: (reason) => { - if (!reason) { - swal.showValidationError( - 'Reason for cancellation is required.' - ) - } - } - }).then((reason) => { - $.ajax({ - method: "DELETE", - url: url, - data: { - 'cancel_reason': reason.value - } - }).done(function(response) { - swal({ - title: 'Done!', - text: response.success, - type: 'success', - onClose: function() { - window.location.href = "{{ return_url }}"; - } - }); - }); - }); - }); + var inputOptionsPromise = new Promise(function(resolve) { + // get your data and pass it to resolve() + $.getJSON("{{ url('jo_cancel_reasons') }}", function(data) { + resolve(data.cancel_reasons) + }); + }); + + swal({ + title: 'Cancel Job Order', + html: 'Please select the reason for cancellation of this job order:', + input: 'select', + inputOptions: inputOptionsPromise, + type: 'warning', + showCancelButton: true, + width: '40rem', + inputValidator: (value) => { + return new Promise((resolve) => { + console.log(value) + resolve() + }) + } + }).then((result) => { + $.ajax({ + method: "DELETE", + url: url, + data: { + 'cancel_reason': result.value + } + }).done(function(response) { + swal({ + title: 'Done!', + text: response.success, + type: 'success', + onClose: function() { + window.location.href = "{{ return_url }}"; + } + }); + }); + }); + }); // fulfill cancelled job order $(".btn-fulfill-cancel-job-order").click(function(e) { From a526b7bee5dacc9f15c38124ae27fd6e0f73275c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Aug 2020 02:27:44 +0000 Subject: [PATCH 11/14] Fix issue when user cancels the cancellation. #449 --- src/Controller/JobOrderController.php | 1 - templates/job-order/form.html.twig | 32 ++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index a5e6883e..11446515 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -1181,7 +1181,6 @@ class JobOrderController extends Controller // ajax call public function cancelReasons() { - error_log('start cancel_reasons'); return $this->json([ 'cancel_reasons' => JOCancelReasons::getCollection(), ]); diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 25027fdc..d94b1305 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -1764,30 +1764,32 @@ $(function() { inputOptions: inputOptionsPromise, type: 'warning', showCancelButton: true, + closeOnCancel: true, width: '40rem', inputValidator: (value) => { return new Promise((resolve) => { - console.log(value) resolve() }) } }).then((result) => { - $.ajax({ - method: "DELETE", - url: url, - data: { - 'cancel_reason': result.value - } - }).done(function(response) { - swal({ - title: 'Done!', - text: response.success, - type: 'success', - onClose: function() { - window.location.href = "{{ return_url }}"; + if (result.value) { + $.ajax({ + method: "DELETE", + url: url, + data: { + 'cancel_reason': result.value } + }).done(function(response) { + swal({ + title: 'Done!', + text: response.success, + type: 'success', + onClose: function() { + window.location.href = "{{ return_url }}"; + } + }); }); - }); + } }); }); From 78d0f4b1509e83bd5c7f725741e4c9ad8a94e04c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Aug 2020 03:32:51 +0000 Subject: [PATCH 12/14] Change text field to dropdown for reasons why customer will not wait. #454 --- .../JobOrderHandler/ResqJobOrderHandler.php | 65 +++++++++++-------- templates/job-order/form.html.twig | 6 +- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index a6c841ca..ad34276a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -37,6 +37,7 @@ use App\Ramcar\ModeOfPayment; use App\Ramcar\TransactionOrigin; use App\Ramcar\FacilitatedType; use App\Ramcar\JORejectionReason; +use App\Ramcar\CustomerNotWaitReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; @@ -326,9 +327,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); // TODO: check status before saving since JO might already // have a status that needs to be retained @@ -361,7 +363,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setModeOfPayment($req->request->get('mode_of_payment')) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); // check if user is null, meaning call to create came from API if ($user != null) @@ -458,9 +460,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); if (empty($error_array)) { @@ -488,7 +491,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setModeOfPayment($req->request->get('mode_of_payment')) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); // did they change invoice? $invoice_items = $req->request->get('invoice_items', []); @@ -625,9 +628,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); if (empty($error_array)) { @@ -651,7 +655,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setHub($hub) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); // validate $errors = $this->validator->validate($obj); @@ -731,9 +735,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); // get current user $user = $this->security->getUser(); @@ -758,7 +763,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setRider($rider) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); if ($user != null) { @@ -827,9 +832,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); if (empty($error_array)) { // coordinates @@ -848,7 +854,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setDeliveryAddress($req->request->get('delivery_address')) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); // validate $errors = $this->validator->validate($obj); @@ -1025,9 +1031,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); if (empty($error_array)) { @@ -1059,7 +1066,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->clearRider() ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); if ($user != null) { @@ -1239,9 +1246,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); - $reason = $req->request->get('no_wait_reason'); - if ((!($will_wait)) && (empty($reason))) - $error_array['no_wait_reason'] = 'Reason is needed.'; + if ($will_wait) + $reason = ''; + else + $reason = $req->request->get('no_wait_reason'); if (empty($error_array)) { // rider mqtt event @@ -1272,7 +1280,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setRider($rider) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($req->request->get('no_wait_reason')); + ->setReasonsNotWait($reason); if ($user != null) { @@ -2544,6 +2552,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $params['facilitated_types'] = FacilitatedType::getCollection(); $params['facilitated_hubs'] = $fac_hubs; $params['sources'] = TransactionOrigin::getCollection(); + $params['no_wait_reasons'] = CustomerNotWaitReason::getCollection(); } protected function initFormTags(&$params) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index d94b1305..95dae4e0 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -300,7 +300,11 @@
- +
From 21c1535e893d64c6eb0b630653a83d7bcbb5b80e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Aug 2020 03:45:23 +0000 Subject: [PATCH 13/14] Add Lazada to Transaction Origin. #455 --- src/Ramcar/TransactionOrigin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Ramcar/TransactionOrigin.php b/src/Ramcar/TransactionOrigin.php index c4d69ad2..8d4c12aa 100644 --- a/src/Ramcar/TransactionOrigin.php +++ b/src/Ramcar/TransactionOrigin.php @@ -10,6 +10,7 @@ class TransactionOrigin extends NameValue const VIP = 'vip'; const MOBILE_APP = 'mobile_app'; const WALK_IN = 'walk_in'; + const LAZADA = 'lazada'; // TODO: for now, resq also gets the walk-in option const COLLECTION = [ @@ -19,5 +20,6 @@ class TransactionOrigin extends NameValue 'vip' => 'VIP', 'mobile_app' => 'Mobile App', 'walk_in' => 'Walk-in', + 'lazada' => 'Lazada', ]; } From 117974d2cba7090663f5264c621a08500cdffdc3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 4 Aug 2020 08:00:21 +0000 Subject: [PATCH 14/14] Add CustomerNotWaitReason. #453 --- src/Ramcar/CustomerNotWaitReason.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/Ramcar/CustomerNotWaitReason.php diff --git a/src/Ramcar/CustomerNotWaitReason.php b/src/Ramcar/CustomerNotWaitReason.php new file mode 100644 index 00000000..142723b2 --- /dev/null +++ b/src/Ramcar/CustomerNotWaitReason.php @@ -0,0 +1,16 @@ + 'Emergency', + 'use_vehicle_now' => 'Need to Use Vehicle Now', + 'with_appointment' => 'With Appointment', + ]; +}