From 505177360ee463a3dd4518dba20d304aa7adac50 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 08:58:41 +0000 Subject: [PATCH 01/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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', + ]; +} From fb8dabc269e8a8adc023715d7753a1c0eac9b324 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 7 Aug 2020 07:05:42 +0000 Subject: [PATCH 15/39] Return only compatible batteries for customer vehicle. #461 --- src/Controller/VehicleController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index 7c388062..1a801322 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -511,6 +511,7 @@ class VehicleController extends Controller } // add all other batteries, because they want options + /* foreach ($all_batts as $battery) { // if we already listed it @@ -528,6 +529,7 @@ class VehicleController extends Controller 'warr_commercial' => $battery->getWarrantyCommercial(), ]; } + */ /* // NOTE: no need to order by price for control center / only for app From 1f39ab3ccfd358690915e70c4554e2887a72b7b0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 7 Aug 2020 08:54:16 +0000 Subject: [PATCH 16/39] Add list of no trade in reasons. #462 --- src/Ramcar/NoTradeInReason.php | 20 ++++++++++++++++++++ templates/job-order/form.html.twig | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Ramcar/NoTradeInReason.php diff --git a/src/Ramcar/NoTradeInReason.php b/src/Ramcar/NoTradeInReason.php new file mode 100644 index 00000000..aeea695b --- /dev/null +++ b/src/Ramcar/NoTradeInReason.php @@ -0,0 +1,20 @@ + 'No existing battery', + 'sell_other_shop' => 'Sell to other shop', + 'used_as_spare_battery' => 'Used as spare battery', + 'return_battery_company' => 'Need to return battery to company', + 'low_trade_in_value' => 'Trade in value is low', + ]; +} diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index bba70b39..6f442e20 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -439,6 +439,28 @@
+
+
+
+ +
+ +
+
+
+
+
+ + + +
+
+
From 25b96e8a146f3e51b6e7a11be4e319c309ffa3c7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 10 Aug 2020 03:28:40 +0000 Subject: [PATCH 17/39] Fix error when user reassigns hub. #453 --- src/Service/JobOrderHandler/ResqJobOrderHandler.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index ad34276a..5e8eb2be 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1029,6 +1029,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface if (empty($req->request->get('landmark'))) $error_array['landmark'] = 'Landmark is required.'; + error_log($req->request->get('landmark')); + // check if customer is not willing to wait $will_wait = $req->request->get('flag_will_wait'); if ($will_wait) @@ -1063,10 +1065,10 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setTier2Notes($req->request->get('tier2_notes')) ->setDeliveryAddress($req->request->get('delivery_address')) ->setHub($hub) - ->clearRider() ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($reason); + ->setReasonsNotWait($reason) + ->clearRider(); if ($user != null) { From e8220f428225f3a4606b808b80ed6a02106194b7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 10 Aug 2020 07:51:37 +0000 Subject: [PATCH 18/39] Add no trade in reason to form and JO entity. #462 --- src/Entity/JobOrder.php | 17 +++++++ .../JobOrderHandler/ResqJobOrderHandler.php | 44 +++++++++++++++++-- templates/job-order/form.html.twig | 34 +++++++------- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 6309dc6d..744d8d98 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -346,6 +346,12 @@ class JobOrder */ protected $reasons_not_waiting; + // reason for not trading in battery + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $no_trade_in_reason; + public function __construct() { $this->date_create = new DateTime(); @@ -997,4 +1003,15 @@ class JobOrder { return $this->reasons_not_waiting; } + + public function setNoTradeInReason($reason) + { + $this->no_trade_in_reason = $reason; + return $this; + } + + public function getNoTradeInReason() + { + return $this->no_trade_in_reason; + } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 5e8eb2be..cf556136 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -38,6 +38,7 @@ use App\Ramcar\TransactionOrigin; use App\Ramcar\FacilitatedType; use App\Ramcar\JORejectionReason; use App\Ramcar\CustomerNotWaitReason; +use App\Ramcar\NoTradeInReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; @@ -332,6 +333,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface else $reason = $req->request->get('no_wait_reason'); + // check if trade in + $is_trade_in = $req->request->get('invoice_trade_in_type'); + $no_trade_in_reason = ''; + if (empty($is_trade_in)) + { + $no_trade_in_reason = $req->request->get('no_trade_in_reason'); + + if (empty($no_trade_in_reason)) + $error_array['no_trade_in_reason'] = 'No trade in reason required.'; + } + // TODO: check status before saving since JO might already // have a status that needs to be retained @@ -363,7 +375,8 @@ 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($reason); + ->setReasonsNotWait($reason) + ->setNoTradeInReason($no_trade_in_reason); // check if user is null, meaning call to create came from API if ($user != null) @@ -465,6 +478,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface else $reason = $req->request->get('no_wait_reason'); + // check if trade in + $is_trade_in = $req->request->get('invoice_trade_in_type'); + $no_trade_in_reason = ''; + if (empty($is_trade_in)) + { + $no_trade_in_reason = $req->request->get('no_trade_in_reason'); + + if (empty($no_trade_in_reason)) + $error_array['no_trade_in_reason'] = 'No trade in reason required.'; + } + if (empty($error_array)) { // get current user @@ -491,7 +515,8 @@ 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($reason); + ->setReasonsNotWait($reason) + ->setNoTradeInReason($no_trade_in_reason); // did they change invoice? $invoice_items = $req->request->get('invoice_items', []); @@ -837,6 +862,17 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface else $reason = $req->request->get('no_wait_reason'); + // check if trade in + $is_trade_in = $req->request->get('invoice_trade_in_type'); + $no_trade_in_reason = ''; + if (empty($is_trade_in)) + { + $no_trade_in_reason = $req->request->get('no_trade_in_reason'); + + if (empty($no_trade_in_reason)) + $error_array['no_trade_in_reason'] = 'No trade in reason required.'; + } + if (empty($error_array)) { // coordinates $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); @@ -854,7 +890,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setDeliveryAddress($req->request->get('delivery_address')) ->setLandmark($req->request->get('landmark')) ->setWillingToWait($req->request->get('flag_will_wait', false)) - ->setReasonsNotWait($reason); + ->setReasonsNotWait($reason) + ->setNoTradeInReason($no_trade_in_reason); // validate $errors = $this->validator->validate($obj); @@ -2555,6 +2592,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $params['facilitated_hubs'] = $fac_hubs; $params['sources'] = TransactionOrigin::getCollection(); $params['no_wait_reasons'] = CustomerNotWaitReason::getCollection(); + $params['no_trade_in_reasons'] = NoTradeInReason::getCollection(); } protected function initFormTags(&$params) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 535af27d..10d138eb 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -308,6 +308,7 @@
+
@@ -455,20 +456,6 @@
-
-
-
- -
- -
-
-
@@ -564,20 +551,31 @@
-
+
- {% for key, type in trade_in_types %} {% endfor %}
-
+
+ + + +
+ +
-
+
- {# {% if is_granted('customer.dpa') %} #} + {% if is_granted('customer.dpa') %} - {# {% endif %} #} + {% endif %}
diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 1ea6d675..b712ad4e 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -146,18 +146,20 @@
-
-
- - - -
-
- - - -
-
+
+
+ + + +
+
+ {% if is_granted('customer.dpa') %} + + + + {% endif %} +
+
From 7c49bd9f0ab21a45ce49e3ac73193b220d28291c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 22 Sep 2020 11:17:25 +0000 Subject: [PATCH 35/39] Add ImportSAPDeltaCommand. #504 --- src/Command/ImportSAPDeltaCommand.php | 325 ++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 src/Command/ImportSAPDeltaCommand.php diff --git a/src/Command/ImportSAPDeltaCommand.php b/src/Command/ImportSAPDeltaCommand.php new file mode 100644 index 00000000..151e033c --- /dev/null +++ b/src/Command/ImportSAPDeltaCommand.php @@ -0,0 +1,325 @@ +em = $em; + $this->initSAPBatteryHash(); + $this->initSAPBatterySizeHash(); + $this->initSAPBatteryBrandHash(); + + parent::__construct(); + } + + protected function configure() + { + $this->setName('sap_battery:delta') + ->setDescription('Update SAP battery table with new SAP battery data.') + ->setHelp('Creates SAP battery data entries from CSV file.') + ->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.') + ->addArgument('output_file', InputArgument::REQUIRED, 'Path to the output CSV file.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $csv_file = $input->getArgument('file'); + $report_file = $input->getArgument('output_file'); + + // CSV column order: + // 0 - brand + // 1 - sku + // 2 - size + + // attempt to open file + try + { + $fh = fopen($csv_file, "r"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $csv_file . '" could not be read.'); + } + + // get entity manager + $em = $this->em; + + // loop through the rows + $row_num = 0; + error_log('Processing sap battery csv file...'); + $existing_brands = []; + $existing_sizes = []; + $existing_batteries = []; + $added_brands = []; + $added_sizes = []; + $added_batteries = []; + while (($fields = fgetcsv($fh)) !== false) + { + // data starts at row 2 + if ($row_num < 2) + { + $row_num++; + continue; + } + + // check if blank row + if (strlen(trim($fields[0])) == 0) + continue; + + // clean up fields + $clean_brand = $this->normalizeName(trim($fields[0])); + $clean_sku = $this->normalizeName(trim($fields[1])); + $clean_size = $this->normalizeName(trim($fields[2])); + + // check if sap battery code already exists + if (!isset($this->sap_battery_hash[$clean_sku])) + { + // check if brand in system + $sap_brand = null; + if (!isset($this->sap_battery_brand_hash[$clean_brand])) + { + // add brand + $sap_brand = new SAPBatteryBrand(); + $sap_brand->setName($clean_brand); + + $em->persist($sap_brand); + + // add to list of added brands + $added_brands[$clean_brand] = $clean_brand; + + // add to hash + $this->sap_battery_brand_hash[$clean_brand] = $sap_brand; + } + else + { + // get the brand + $sap_brand = $this->sap_battery_brand_hash[$clean_brand]; + + // need to check if this is in added_brands because the hash contains + // existing + added. What we need is the list of existing only + if (!isset($added_brands[$clean_brand])) + { + // add to list of existing brands + $existing_brands[$clean_brand] = $sap_brand; + } + } + + // check if size in system + $sap_size = null; + if (!isset($this->sap_battery_size_hash[$clean_size])) + { + // add size + $sap_size = new SAPBatterySize(); + $sap_size->setName($clean_size); + + $em->persist($sap_size); + + // add to list of added sizes + $added_sizes[$clean_size] = $clean_size; + + // add to hash + $this->sap_battery_size_hash[$clean_size] = $sap_size; + } + else + { + // get the size + $sap_size = $this->sap_battery_size_hash[$clean_size]; + + // need to check if this is in added_sizes because the hash contains + // existing + added. What we need is the list of existing only + if (!isset($added_sizes[$clean_size])) + { + // add to list of existing sizes + $existing_sizes[$clean_size] = $sap_size; + } + } + + // add the sap_battery + // create sap battery entry + $sap_battery = new SAPBattery(); + $sap_battery->setID($clean_sku) + ->setSize($sap_size) + ->setBrand($sap_brand); + + $em->persist($sap_battery); + + // add to list of added batteries + $added_batteries[$clean_sku] = $clean_sku; + + // add to hash + $this->sap_battery_hash[$clean_sku] = $sap_battery; + } + else + { + // TODO: for now, assume that the brand and size in system == brand and size in csv file + // need to check if this is in added_batteries because the hash contains + // existing + added. What we need is the list of existing only + if (!isset($added_batteries[$clean_sku])) + { + // add to list of existing batteries + $existing_batteries[$clean_sku] = $this->sap_battery_hash[$clean_sku]; + } + } + + $row_num++; + + } + + $em->flush(); + + // need to output the list of added and not added data + $this->writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, + $existing_brands, $existing_sizes, $existing_batteries); + + return 0; + } + + protected function initSAPBatteryHash() + { + $this->sap_battery_hash = []; + + $batts = $this->em->getRepository(SAPBattery::class)->findAll(); + foreach ($batts as $batt) + { + $id = $this->normalizeName($batt->getID()); + $this->sap_battery_hash[$id] = $batt; + } + } + + protected function initSAPBatterySizeHash() + { + $this->sap_battery_size_hash = []; + + $sizes = $this->em->getRepository(SAPBatterySize::class)->findAll(); + foreach ($sizes as $size) + { + $name = $this->normalizeName($size->getName()); + $this->sap_battery_size_hash[$name] = $size; + } + } + + protected function initSAPBatteryBrandHash() + { + $this->sap_battery_brand_hash = []; + + $brands = $this->em->getRepository(SAPBatteryBrand::class)->findAll(); + foreach ($brands as $brand) + { + $name = $this->normalizeName($brand->getName()); + $this->sap_battery_brand_hash[$name] = $brand; + } + } + + protected function writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, + $existing_brands, $existing_sizes, $existing_batteries) + { + try + { + $fh = fopen($report_file, "w"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $report_file . '" could be opened.'); + } + + fputs($fh, 'Total brands added: ' . count($added_brands) . "\n"); + fputs($fh, 'Total sizes added: ' . count($added_sizes) . "\n"); + fputs($fh, 'Total batteries added: ' . count($added_batteries) . "\n"); + + // write the added batteries + // check the existing brands array for the added ones + $not_added_batteries = []; + fputs($fh, 'Added Batteries: ' . "\n"); + foreach($added_batteries as $added_battery) + { + fputs($fh, $added_battery, strlen($added_battery)); + fputs($fh, "\n"); + + if (isset($existing_batteries[$added_battery])) + { + $not_added_batteries[] = $added_battery; + } + } + + // write the added brands + // check the existing arrays for the added ones + $not_added_brands = []; + fputs($fh, 'Added Brands: ' . "\n"); + foreach ($added_brands as $added_brand) + { + fputs($fh, $added_brand, strlen($added_brand)); + fputs($fh, "\n"); + + if (isset($existing_brands[$added_brand])) + { + $not_added_brands[] = $added_brand; + } + } + + // write the added sizes + // check the existing array for the added ones + $not_added_sizes = []; + fputs($fh, 'Added Sizes: ' . "\n"); + foreach ($added_sizes as $added_size) + { + fputs($fh, $added_size, strlen($added_size)); + fputs($fh, "\n"); + + if (isset($existing_sizes[$added_size])) + { + $not_added_sizes[] = $added_size; + } + } + + // write the not added batteries + fputs($fh, 'Batteries already in system: ' . "\n"); + foreach($not_added_batteries as $not_added_battery) + { + fputs($fh, $not_added_battery, strlen($not_added_battery)); + fputs($fh, "\n"); + } + + // write the not added brands + fputs($fh, 'Brands already in system: ' . "\n"); + foreach($not_added_brands as $not_added_brand) + { + fputs($fh, $not_added_brand, strlen($not_added_brand)); + fputs($fh, "\n"); + } + + // write the not added sizes + fputs($fh, 'Sizes already in system: ' . "\n"); + foreach($not_added_sizes as $not_added_size) + { + fputs($fh, $not_added_size, strlen($not_added_size)); + fputs($fh, "\n"); + } + + fclose($fh); + } + + protected function normalizeName($name) + { + $normalized_key = trim(strtoupper($name)); + + return $normalized_key; + } +} From beee87c3b46bd4ce890eb30ab2ab5e61c34e1ede Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 23 Sep 2020 04:47:15 +0000 Subject: [PATCH 36/39] Modify the ImportSAPDeltaCommand to make import checking easier. #504 --- src/Command/ImportSAPDeltaCommand.php | 52 +++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Command/ImportSAPDeltaCommand.php b/src/Command/ImportSAPDeltaCommand.php index 151e033c..aeea6366 100644 --- a/src/Command/ImportSAPDeltaCommand.php +++ b/src/Command/ImportSAPDeltaCommand.php @@ -71,6 +71,7 @@ class ImportSAPDeltaCommand extends Command $added_brands = []; $added_sizes = []; $added_batteries = []; + $total_processed = 0; while (($fields = fgetcsv($fh)) !== false) { // data starts at row 2 @@ -105,6 +106,8 @@ class ImportSAPDeltaCommand extends Command // add to list of added brands $added_brands[$clean_brand] = $clean_brand; + //$output->writeln('Adding brand: ' . $clean_brand); + // add to hash $this->sap_battery_brand_hash[$clean_brand] = $sap_brand; } @@ -118,7 +121,8 @@ class ImportSAPDeltaCommand extends Command if (!isset($added_brands[$clean_brand])) { // add to list of existing brands - $existing_brands[$clean_brand] = $sap_brand; + //$output->writeln('Brand already in db ' . $clean_brand); + $existing_brands[$clean_brand] = $clean_brand; } } @@ -135,6 +139,8 @@ class ImportSAPDeltaCommand extends Command // add to list of added sizes $added_sizes[$clean_size] = $clean_size; + //$output->writeln('Adding size: ' . $clean_size); + // add to hash $this->sap_battery_size_hash[$clean_size] = $sap_size; } @@ -148,7 +154,8 @@ class ImportSAPDeltaCommand extends Command if (!isset($added_sizes[$clean_size])) { // add to list of existing sizes - $existing_sizes[$clean_size] = $sap_size; + //$output->writeln('Size already in db ' . $clean_size); + $existing_sizes[$clean_size] = $clean_size; } } @@ -164,6 +171,8 @@ class ImportSAPDeltaCommand extends Command // add to list of added batteries $added_batteries[$clean_sku] = $clean_sku; + //$output->writeln('Adding battery: ' . $clean_sku); + // add to hash $this->sap_battery_hash[$clean_sku] = $sap_battery; } @@ -175,10 +184,16 @@ class ImportSAPDeltaCommand extends Command if (!isset($added_batteries[$clean_sku])) { // add to list of existing batteries + //$output->writeln('Battery already in db ' . $clean_sku); $existing_batteries[$clean_sku] = $this->sap_battery_hash[$clean_sku]; + if (!isset($existing_brands[$clean_brand])) + $existing_brands[$clean_brand] = $clean_brand; + if (!isset($existing_sizes[$clean_size])) + $existing_sizes[$clean_size] = $clean_size; } } + $total_processed++; $row_num++; } @@ -187,7 +202,7 @@ class ImportSAPDeltaCommand extends Command // need to output the list of added and not added data $this->writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, - $existing_brands, $existing_sizes, $existing_batteries); + $existing_brands, $existing_sizes, $existing_batteries, $total_processed); return 0; } @@ -229,7 +244,7 @@ class ImportSAPDeltaCommand extends Command } protected function writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, - $existing_brands, $existing_sizes, $existing_batteries) + $existing_brands, $existing_sizes, $existing_batteries, $total_processed) { try { @@ -240,10 +255,16 @@ class ImportSAPDeltaCommand extends Command throw new Exception('The file "' . $report_file . '" could be opened.'); } + fputs($fh, 'Total entries processed: ' . $total_processed . "\n"); + fputs($fh, 'Total brands added: ' . count($added_brands) . "\n"); fputs($fh, 'Total sizes added: ' . count($added_sizes) . "\n"); fputs($fh, 'Total batteries added: ' . count($added_batteries) . "\n"); + fputs($fh, 'Total number of brands in csv file that are in the system: ' . count($existing_brands) . "\n"); + fputs($fh, 'Total number of sizes in csv file that are in the system: ' . count($existing_sizes) . "\n"); + fputs($fh, 'Total number of batteries in csv file that are in the system: ' . count($existing_batteries) . "\n"); + // write the added batteries // check the existing brands array for the added ones $not_added_batteries = []; @@ -252,11 +273,6 @@ class ImportSAPDeltaCommand extends Command { fputs($fh, $added_battery, strlen($added_battery)); fputs($fh, "\n"); - - if (isset($existing_batteries[$added_battery])) - { - $not_added_batteries[] = $added_battery; - } } // write the added brands @@ -267,11 +283,6 @@ class ImportSAPDeltaCommand extends Command { fputs($fh, $added_brand, strlen($added_brand)); fputs($fh, "\n"); - - if (isset($existing_brands[$added_brand])) - { - $not_added_brands[] = $added_brand; - } } // write the added sizes @@ -282,24 +293,19 @@ class ImportSAPDeltaCommand extends Command { fputs($fh, $added_size, strlen($added_size)); fputs($fh, "\n"); - - if (isset($existing_sizes[$added_size])) - { - $not_added_sizes[] = $added_size; - } } // write the not added batteries fputs($fh, 'Batteries already in system: ' . "\n"); - foreach($not_added_batteries as $not_added_battery) + foreach($existing_batteries as $not_added_battery) { - fputs($fh, $not_added_battery, strlen($not_added_battery)); + fputs($fh, $not_added_battery->getID(), strlen($not_added_battery->getID())); fputs($fh, "\n"); } // write the not added brands fputs($fh, 'Brands already in system: ' . "\n"); - foreach($not_added_brands as $not_added_brand) + foreach($existing_brands as $not_added_brand) { fputs($fh, $not_added_brand, strlen($not_added_brand)); fputs($fh, "\n"); @@ -307,7 +313,7 @@ class ImportSAPDeltaCommand extends Command // write the not added sizes fputs($fh, 'Sizes already in system: ' . "\n"); - foreach($not_added_sizes as $not_added_size) + foreach($existing_sizes as $not_added_size) { fputs($fh, $not_added_size, strlen($not_added_size)); fputs($fh, "\n"); From 7107c57eb60ac12ffc9a0fc743d5e2b1b6bbd4f3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 25 Sep 2020 09:58:07 +0000 Subject: [PATCH 37/39] Create command to import SAP information. #504 --- src/Command/ImportSAPMasterCommand.php | 256 +++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 src/Command/ImportSAPMasterCommand.php diff --git a/src/Command/ImportSAPMasterCommand.php b/src/Command/ImportSAPMasterCommand.php new file mode 100644 index 00000000..9e266c2b --- /dev/null +++ b/src/Command/ImportSAPMasterCommand.php @@ -0,0 +1,256 @@ +em = $em; + $this->initSAPBatteryHash(); + $this->initSAPBatterySizeHash(); + $this->initSAPBatteryBrandHash(); + + parent::__construct(); + } + + protected function configure() + { + $this->setName('sap_battery:master') + ->setDescription('Import SAP battery master list.') + ->setHelp('Creates SAP battery, SAP battery brands, and SAP battery sizes from CSV file.') + ->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.') + ->addArgument('output_file', InputArgument::REQUIRED, 'Path to the output CSV file.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $csv_file = $input->getArgument('file'); + $report_file = $input->getArgument('output_file'); + + // CSV column order: + // 0 - brand + // 1 - sku + // 2 - size + + // attempt to open file + try + { + $fh = fopen($csv_file, "r"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $csv_file . '" could not be read.'); + } + + // get entity manager + $em = $this->em; + // loop through the rows + $row_num = 0; + error_log('Processing sap battery csv file...'); + $added_brands = []; + $added_sizes = []; + $added_batteries = []; + $repeat_brands = []; + $repeat_sizes = []; + $repeat_batteries = []; + $total_processed = 0; + while (($fields = fgetcsv($fh)) !== false) + { + // data starts at row 2 + if ($row_num < 2) + { + $row_num++; + continue; + } + + // check if blank row + if (strlen(trim($fields[0])) == 0) + continue; + + // clean up fields + $clean_brand = $this->normalizeName(trim($fields[0])); + $clean_sku = $this->normalizeName(trim($fields[1])); + $clean_size = $this->normalizeName(trim($fields[2])); + + // check if brand in system + $sap_brand = null; + if (!isset($this->sap_battery_brand_hash[$clean_brand])) + { + // add brand + $sap_brand = new SAPBatteryBrand(); + $sap_brand->setName($clean_brand); + + $em->persist($sap_brand); + + // add to list of added brands + $added_brands[$clean_brand] = $clean_brand; + + //$output->writeln('Adding brand: ' . $clean_brand); + + // add to hash + $this->sap_battery_brand_hash[$clean_brand] = $sap_brand; + } + else + { + // get the brand + $sap_brand = $this->sap_battery_brand_hash[$clean_brand]; + + // repeat brand so no need to add but still need to count + $repeat_brands[] = $clean_brand; + } + + // check if size in system + $sap_size = null; + if (!isset($this->sap_battery_size_hash[$clean_size])) + { + // add size + $sap_size = new SAPBatterySize(); + $sap_size->setName($clean_size); + + $em->persist($sap_size); + + // add to list of added sizes + $added_sizes[$clean_size] = $clean_size; + + //$output->writeln('Adding size: ' . $clean_size); + + // add to hash + $this->sap_battery_size_hash[$clean_size] = $sap_size; + } + else + { + // get the size + $sap_size = $this->sap_battery_size_hash[$clean_size]; + + // repeat size so no need to add to system but still need to count + $repeat_sizes[] = $clean_size; + } + + // check if sap battery code already exists + if (!isset($this->sap_battery_hash[$clean_sku])) + { + // add the sap_battery + // create sap battery entry + $sap_battery = new SAPBattery(); + $sap_battery->setID($clean_sku) + ->setSize($sap_size) + ->setBrand($sap_brand); + + $em->persist($sap_battery); + + // add to list of added batteries + $added_batteries[$clean_sku] = $clean_sku; + + //$output->writeln('Adding battery: ' . $clean_sku); + + // add to hash + $this->sap_battery_hash[$clean_sku] = $sap_battery; + } + else + { + $repeat_batteries[] = $clean_sku; + } + + $total_processed++; + $row_num++; + } + + $em->flush(); + + // need to output the list of added and not added data + $this->writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, $total_processed, + $repeat_brands, $repeat_sizes, $repeat_batteries); + + return 0; + } + + protected function initSAPBatteryHash() + { + $this->sap_battery_hash = []; + + $batts = $this->em->getRepository(SAPBattery::class)->findAll(); + foreach ($batts as $batt) + { + $id = $this->normalizeName($batt->getID()); + $this->sap_battery_hash[$id] = $batt; + } + } + + protected function initSAPBatterySizeHash() + { + $this->sap_battery_size_hash = []; + + $sizes = $this->em->getRepository(SAPBatterySize::class)->findAll(); + foreach ($sizes as $size) + { + $name = $this->normalizeName($size->getName()); + $this->sap_battery_size_hash[$name] = $size; + } + } + + protected function initSAPBatteryBrandHash() + { + $this->sap_battery_brand_hash = []; + + $brands = $this->em->getRepository(SAPBatteryBrand::class)->findAll(); + foreach ($brands as $brand) + { + $name = $this->normalizeName($brand->getName()); + $this->sap_battery_brand_hash[$name] = $brand; + } + } + + protected function writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, $total_processed, + $repeat_brands, $repeat_sizes, $repeat_batteries) + { + try + { + $fh = fopen($report_file, "w"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $report_file . '" could be opened.'); + } + + fputs($fh, 'Total entries processed: ' . $total_processed . "\n"); + + fputs($fh, 'Total brands added: ' . count($added_brands) . "\n"); + fputs($fh, 'Total sizes added: ' . count($added_sizes) . "\n"); + fputs($fh, 'Total batteries added: ' . count($added_batteries) . "\n"); + + fputs($fh, 'Repeat brands: ' . count($repeat_brands) . "\n"); + fputs($fh, 'Repeat sizes: ' . count($repeat_sizes) . "\n"); + fputs($fh, 'Repeat batteries: ' . count($repeat_batteries) . "\n"); + + foreach ($repeat_batteries as $repeat_battery) + { + fputs($fh, 'Duplicate SKU: ' . $repeat_battery . "\n"); + } + + } + + protected function normalizeName($name) + { + $normalized_key = trim(strtoupper($name)); + + return $normalized_key; + } + +} From ae5ccb40f2a6a0150e7cd00419001594b5aed328 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 28 Sep 2020 07:52:00 +0000 Subject: [PATCH 38/39] Add date_create to Customer. #513 --- src/Entity/Customer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 9ba043c9..281c9fa9 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -6,6 +6,8 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\Validator\Constraints as Assert; +use DateTime; + use App\Ramcar\CustomerClassification; /** @@ -184,6 +186,12 @@ class Customer */ protected $flag_dpa_consent; + // date customer was created + /** + * @ORM\Column(type="datetime") + */ + protected $date_create; + public function __construct() { $this->numbers = new ArrayCollection(); @@ -214,6 +222,8 @@ class Customer $this->flag_promo_email = false; $this->flag_promo_sms = false; $this->flag_dpa_consent = false; + + $this->date_create = new DateTime(); } public function getID() From 2d0b539f092b441aa7ea7094df099fb65343c9fa Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 28 Sep 2020 08:08:11 +0000 Subject: [PATCH 39/39] Add sql script to update date_create to current date for Customer. #513 --- initial_sql/sql_update_customer_date_create.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 initial_sql/sql_update_customer_date_create.sql diff --git a/initial_sql/sql_update_customer_date_create.sql b/initial_sql/sql_update_customer_date_create.sql new file mode 100644 index 00000000..50102db3 --- /dev/null +++ b/initial_sql/sql_update_customer_date_create.sql @@ -0,0 +1,2 @@ +UPDATE customer SET date_create=NOW() WHERE date_create="0000-00-00 00:00:00"; +