From 31f43aea39bd3f796c65461e09ee6ad65b9f3c30 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 04:11:27 +0000 Subject: [PATCH 1/2] Add warranty source to Warranty and when creating warranty. #579 --- .../GenerateWarrantyFromJobOrderCommand.php | 5 +++-- src/Controller/APIController.php | 3 +++ .../CAPI/CustomerWarrantyController.php | 3 +++ src/Controller/CAPI/WarrantyController.php | 6 ++++-- src/Controller/WarrantyController.php | 3 ++- src/Entity/Warranty.php | 18 ++++++++++++++++++ src/Service/WarrantyHandler.php | 3 ++- 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Command/GenerateWarrantyFromJobOrderCommand.php b/src/Command/GenerateWarrantyFromJobOrderCommand.php index 1e8e391a..381823d8 100644 --- a/src/Command/GenerateWarrantyFromJobOrderCommand.php +++ b/src/Command/GenerateWarrantyFromJobOrderCommand.php @@ -210,9 +210,10 @@ class GenerateWarrantyFromJobOrderCommand extends Command $values = '(' . $bty_model_id . ',' . $bty_size_id . ',NULL,\'' . $warranty_class . '\',\'' . $cleaned_plate_number . '\',\'' . WarrantyStatus::ACTIVE . '\',\'' . $date_create . '\',\'' . $date_purchase . '\',\'' . $date_expire . '\',NULL,' - . $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\',' . 0 . ',NULL' . ');'; + . $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\',' . 0 . ',NULL,\'' + . WarrantySource::COMMAND .'\');'; - $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n"; + $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy,create_source) VALUES ' . $values . "\n"; echo $sql_statement; diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 6c275ead..a1623a09 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3151,6 +3151,9 @@ class APIController extends Controller implements LoggedController { $warr = new Warranty(); $sms_msg = $trans->trans('warranty_register_confirm'); + + // set warranty source + $warr->setCreateSource($source); } // get sap battery diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index e0c74f22..1b306cf6 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -425,6 +425,9 @@ class CustomerWarrantyController extends APIController { $warr = new Warranty(); $sms_message = $trans->trans('warranty_register_confirm'); + + // set warranty's create source + $warr->setCreateSource($source); } error_log('sap battery check'); diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 72eb1785..f5386d55 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -275,7 +275,8 @@ class WarrantyController extends APIController ->setSAPBattery($batt) ->setDatePurchase($date_pur) ->setDateClaim(null) - ->setDateExpire($date_expire); + ->setDateExpire($date_expire) + ->setCreateSource($source); try { @@ -370,7 +371,8 @@ class WarrantyController extends APIController ->setDatePurchase($warr->getDatePurchase()) ->setDateClaim(null) ->setDateExpire($warr->getDateExpire()) - ->setClaimedFrom($warr); + ->setClaimedFrom($warr) + ->setCreateSource($source); $em->persist($new_warr); diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index d7ab6eb7..af75e3b2 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -176,7 +176,8 @@ class WarrantyController extends Controller ->setMobileNumber($req->request->get('mobile_number')) ->setDatePurchase($date_purchase) ->setClaimedFrom($req->request->get('claim_from')) - ->setStatus($req->request->get('status')); + ->setStatus($req->request->get('status')) + ->setCreateSource(WarrantySource::ADMIN_PANEL); if ($date_claim) { diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index a814856b..5d45e806 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -232,6 +232,11 @@ class Warranty */ protected $municipality_id; + /** + * @ORM\Column(type="string", length=80, options={"default": "legacy"}) + */ + protected $create_source; + public function __construct() { $this->date_create = new DateTime(); @@ -242,6 +247,7 @@ class Warranty $this->email = ''; $this->odometer = 0; $this->flag_validated = false; + $this->create_source = 'unknown'; } public function getID() @@ -658,4 +664,16 @@ class Warranty { return $this->municipality_id; } + + public function setCreateSource($source) + { + $this->create_source = $source; + return $this; + } + + public function getCreateSource() + { + return $this->create_source; + } + } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index aadb8eac..8d84e8f6 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -93,7 +93,8 @@ class WarrantyHandler ->setLastName($last_name) ->setMobileNumber($mobile_number) ->setDatePurchase($date_purchase) - ->setWarrantyClass($warranty_class); + ->setWarrantyClass($warranty_class) + ->setCreateSource($source); $this->em->persist($warranty); $this->em->flush(); From 3937b73454f3a72a2e96b86c029eb34a209c7850 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 07:20:02 +0000 Subject: [PATCH 2/2] Add api user name to create source for warranty and warranty_api_log. #579 --- .../CAPI/CustomerWarrantyController.php | 19 ++++++++++++- src/Controller/CAPI/WarrantyController.php | 28 +++++++++++++++++-- src/Ramcar/WarrantySource.php | 2 ++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 1b306cf6..3a7c699a 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelInterface; @@ -315,7 +317,11 @@ class CustomerWarrantyController extends APIController 'invoice' => $req->request->get('invoice'), ]; $action = 'create/update'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; error_log('SOURCE: ' . $source); @@ -582,4 +588,15 @@ class CustomerWarrantyController extends APIController $rt->sendSMS($clean_num, 'MOTOLITE', $message); } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index f5386d55..2dc0d837 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Doctrine\ORM\Query; @@ -191,7 +193,12 @@ class WarrantyController extends APIController 'mobile_number' => $mnum, ]; $action = 'create'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + + $source = 'CAPI_USER_' . $username; $msg = $this->checkRequiredParameters($req, $params); error_log('msg - ' . $msg); @@ -322,7 +329,12 @@ class WarrantyController extends APIController 'id' => $id, ]; $action = 'claim'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; + $msg = $this->checkRequiredParameters($req, $params); if ($msg) @@ -777,4 +789,16 @@ class WarrantyController extends APIController return $customers; } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } + } diff --git a/src/Ramcar/WarrantySource.php b/src/Ramcar/WarrantySource.php index 3c16ee89..be9c47e1 100644 --- a/src/Ramcar/WarrantySource.php +++ b/src/Ramcar/WarrantySource.php @@ -10,6 +10,7 @@ class WarrantySource extends NameValue const BULK_UPLOAD = 'bulk_upload'; const MOBILE = 'mobile'; const COMMAND = 'command'; + const UNKNOWN = 'unknown'; const COLLECTION = [ 'capi' => 'Third Party API', @@ -18,6 +19,7 @@ class WarrantySource extends NameValue 'bulk_upload' => 'Bulk Upload', 'mobile' => 'Mobile API', 'command' => 'Command', + 'unknown' => 'Unknown', ]; }