From 532df141edbe4f3d184982fad9d27ce67a3065b5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 09:01:44 +0000 Subject: [PATCH 1/2] Add customer source when creating a new customer. #548 --- .../CreateCustomerFromWarrantyCommand.php | 3 ++- src/Command/ImportCustomerCommand.php | 3 ++- src/Controller/APIController.php | 4 ++++ src/Controller/CAPI/CustomerController.php | 11 ++++++++++- .../CAPI/CustomerWarrantyController.php | 4 +++- src/Controller/CAPI/WarrantyController.php | 6 ++++-- src/Ramcar/CustomerSource.php | 16 ++++++++++++++++ .../CustomerHandler/ResqCustomerHandler.php | 4 ++++ 8 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/Ramcar/CustomerSource.php diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 416ee514..203fac6f 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -216,7 +216,8 @@ class CreateCustomerFromWarrantyCommand extends Command $new_cust = new Customer(); $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) - ->setPhoneMobile($w_mobile_num); + ->setPhoneMobile($w_mobile_num) + ->setCreateSource('CMB_CreateFromCustomerWarranty'); $this->em->persist($new_cust); diff --git a/src/Command/ImportCustomerCommand.php b/src/Command/ImportCustomerCommand.php index e2c55832..562c2df3 100644 --- a/src/Command/ImportCustomerCommand.php +++ b/src/Command/ImportCustomerCommand.php @@ -418,7 +418,8 @@ class ImportCustomerCommand extends Command $fields[self::F_OFFICE_PHONE], $fields[self::F_FAX], $fields[self::F_EMAIL], - isset($fields[self::F_NOTES]) ? $fields[self::F_NOTES] : '' + isset($fields[self::F_NOTES]) ? $fields[self::F_NOTES] : '', + 'CMB_ImportCustomerCommand' ]; $cust_row = str_replace('\\', '\\\\', implode('|', $cust_fields)) . "\n"; fputs($cust_file, $cust_row); diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index a1623a09..f6d764cd 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -29,6 +29,7 @@ use App\Ramcar\JOEventType; use App\Ramcar\AdvanceOrderSlot; use App\Ramcar\AutoAssignStatus; use App\Ramcar\WarrantySource; +use App\Ramcar\CustomerSource; use App\Service\InvoiceGeneratorInterface; use App\Service\RisingTideGateway; @@ -416,6 +417,9 @@ class APIController extends Controller implements LoggedController if ($cust == null) { $cust = new Customer(); + + // set customer source + $cust->setCreateSource(CustomerSource::MOBILE); $em->persist($cust); $this->session->setCustomer($cust); diff --git a/src/Controller/CAPI/CustomerController.php b/src/Controller/CAPI/CustomerController.php index 55aae2bd..36dbba24 100644 --- a/src/Controller/CAPI/CustomerController.php +++ b/src/Controller/CAPI/CustomerController.php @@ -15,6 +15,8 @@ use App\Entity\Customer; use App\Entity\CustomerVehicle; use App\Entity\Vehicle; +use App\Ramcar\CustomerSource; + use Catalyst\APIBundle\Access\Generator as ACLGenerator; class CustomerController extends APIController @@ -154,10 +156,17 @@ class CustomerController extends APIController else { // customer not found + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $user_id = $_SERVER['HTTP_X_CATA_API_KEY']; + $username = $this->getUser()->getName(); + $source = 'CAPI_USER_' . $username; + $new_cust = new Customer(); $new_cust->setFirstName($first_name) ->setLastName($last_name) - ->setPhoneMobile($mobile_number); + ->setPhoneMobile($mobile_number) + ->setCreateSource($source); $em->persist($new_cust); diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 6e183cc0..0c1c869e 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -106,6 +106,7 @@ class CustomerWarrantyController extends APIController 'serial' => $serial, ]; $action = 'check'; + // TODO: we need to modify this later. $source = WarrantySource::CAPI; // check required parameters @@ -491,7 +492,8 @@ class CustomerWarrantyController extends APIController ->setEmail($req->request->get('email')) ->setCreateSource('web_warranty') ->setPrivacyPromo($priv_promo) - ->setPhoneMobile($req->request->get('contact_num')); + ->setPhoneMobile($req->request->get('contact_num')) + ->setCreateSource($source); $em->persist($cust); } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index c0cd8aa8..4db8051c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -728,10 +728,12 @@ class WarrantyController extends APIController $w_last_name = $warranty->getLastName(); $new_cust = new Customer(); - // TODO: add customer source + // add customer source + $cust_source = $warranty->getCreateSource(); $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) - ->setPhoneMobile($w_mobile_num); + ->setPhoneMobile($w_mobile_num) + ->setCreateSource($cust_source); $em->persist($new_cust); diff --git a/src/Ramcar/CustomerSource.php b/src/Ramcar/CustomerSource.php new file mode 100644 index 00000000..5acfa41d --- /dev/null +++ b/src/Ramcar/CustomerSource.php @@ -0,0 +1,16 @@ + 'Mobile API', + 'admin_panel' => 'Admin Panel', + 'legacy' => 'Legacy', + ]; +} diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 1554a288..f8685801 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -15,6 +15,7 @@ use App\Ramcar\CustomerClassification; use App\Ramcar\FuelType; use App\Ramcar\VehicleStatusCondition; use App\Ramcar\CrudException; +use App\Ramcar\CustomerSource; use App\Entity\Customer; use App\Entity\CustomerVehicle; @@ -189,6 +190,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface $this->setObject($row, $req); + // set customer source only when new customer + $row->setCreateSource(CustomerSource::ADMIN_PANEL); + // custom validation for vehicles $vehicles = json_decode($req->request->get('vehicles')); From 2b356194bb1cc423fae0bd93037ca33d18d642ad Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 09:04:57 +0000 Subject: [PATCH 2/2] Fix typo. Remove not needed packages. #548 --- src/Command/CreateCustomerFromWarrantyCommand.php | 2 +- src/Controller/CAPI/CustomerController.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 203fac6f..5ffe3a46 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -217,7 +217,7 @@ class CreateCustomerFromWarrantyCommand extends Command $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) ->setPhoneMobile($w_mobile_num) - ->setCreateSource('CMB_CreateFromCustomerWarranty'); + ->setCreateSource('CMB_CreateCustomerFromWarranty'); $this->em->persist($new_cust); diff --git a/src/Controller/CAPI/CustomerController.php b/src/Controller/CAPI/CustomerController.php index 36dbba24..9148321e 100644 --- a/src/Controller/CAPI/CustomerController.php +++ b/src/Controller/CAPI/CustomerController.php @@ -15,8 +15,6 @@ use App\Entity\Customer; use App\Entity\CustomerVehicle; use App\Entity\Vehicle; -use App\Ramcar\CustomerSource; - use Catalyst\APIBundle\Access\Generator as ACLGenerator; class CustomerController extends APIController