From ac91960bd7140b4c1aba729e70f21cfa7b6deac9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 14 Feb 2020 03:38:37 +0000 Subject: [PATCH] Add mobile phone validation for JO when new customer is created. #340 --- .../CustomerHandler/CMBCustomerHandler.php | 2 +- .../JobOrderHandler/CMBJobOrderHandler.php | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index f66a8e30..371f674b 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -687,7 +687,7 @@ class CMBCustomerHandler implements CustomerHandlerInterface } } - protected function validateMobileNumber($mobile_number) + public function validateMobileNumber($mobile_number) { if (empty($mobile_number)) return true; diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 44714f44..a2727fea 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -42,6 +42,7 @@ use App\Ramcar\JORejectionReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; use App\Service\RiderAssignmentHandlerInterface; +use App\Service\CustomerHandlerInterface; use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\APNSClient; @@ -66,13 +67,15 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface protected $rah; protected $country_code; protected $wh; + protected $cust_handler; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, - string $country_code, WarrantyHandler $wh) + string $country_code, WarrantyHandler $wh, + CustomerHandlerInterface $cust_handler) { $this->em = $em; $this->ic = $ic; @@ -82,6 +85,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->rah = $rah; $this->country_code = $country_code; $this->wh = $wh; + $this->cust_handler = $cust_handler; $this->loadTemplates(); } @@ -416,8 +420,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['customer_customer_notes'] = 'Customer notes cannot be null.'; } - $new_cust = new Customer(); - $new_cv = new CustomerVehicle(); + // validate mobile phone + $valid_mobile = $this->cust_handler->validateMobileNumber($req->request->get('customer_phone_mobile')); + if (!($valid_mobile)) + $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); @@ -426,8 +432,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['cv_mfg'] = 'Invalid manufacturer specified.'; $error_array['cv_make'] = 'Invalid make specified.'; } - else + if (empty($error_array)) { + $new_cust = new Customer(); + $new_cv = new CustomerVehicle(); $new_cust->setLastName($req->request->get('customer_last_name')) ->setFirstName($req->request->get('customer_first_name')) @@ -918,7 +926,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // create the warranty if new battery only if ($this->checkIfNewBattery($obj)) { - $serial = $req->request->get('warranty_code') ; + if (empty($req->request->get('warranty_code'))) + $serial = null; + else + $serial = $req->request->get('warranty_code'); + $warranty_class = $obj->getWarrantyClass(); $first_name = $obj->getCustomer()->getFirstName(); $last_name = $obj->getCustomer()->getLastName(); @@ -2382,8 +2394,10 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['customer_customer_notes'] = 'Customer notes cannot be null.'; } - $new_cust = new Customer(); - $new_cv = new CustomerVehicle(); + // validate mobile phone + $valid_mobile = $this->cust_handler->validateMobileNumber($req->request->get('customer_phone_mobile')); + if (!($valid_mobile)) + $error_array['customer_phone_mobile'] = 'Invalid mobile phone number.'; // find the vehicle using vid $new_vehicle = $em->getRepository(Vehicle::class)->find($req->request->get('vid')); @@ -2392,8 +2406,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $error_array['cv_mfg'] = 'Invalid manufacturer specified.'; $error_array['cv_make'] = 'Invalid make specified.'; } - else + + if (empty($error_array)) { + $new_cust = new Customer(); + $new_cv = new CustomerVehicle(); $new_cust->setLastName($req->request->get('customer_last_name')) ->setFirstName($req->request->get('customer_first_name')) @@ -2564,7 +2581,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // create the warranty if new battery only if ($this->checkIfNewBattery($jo)) { - $serial = $req->request->get('warranty_code') ; + if (empty($req->request->get('warranty_code'))) + $serial = null; + else + $serial = $req->request->get('warranty_code'); + $warranty_class = $jo->getWarrantyClass(); $first_name = $jo->getCustomer()->getFirstName(); $last_name = $jo->getCustomer()->getLastName();