From 6daba0d3052d1f7848f7c63f39d88f1ef51b87fc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 29 Nov 2019 03:41:34 +0000 Subject: [PATCH 01/23] Add command to compute expiry date for warranty. #280 --- .../ComputeWarrantyExpiryDateCommand.php | 108 ++++++++++++++++++ .../CreateCustomerFromWarrantyCommand.php | 1 - 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/Command/ComputeWarrantyExpiryDateCommand.php diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php new file mode 100644 index 00000000..4d547d3d --- /dev/null +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -0,0 +1,108 @@ +em = $em; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('warranty:computeexpirydate') + ->setDescription('Compute expiry date for existing warranties.') + ->setHelp('Comput expiry date for existing warranties.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $warr_q = $this->em->createQuery('select w from App\Entity\Warranty w where w.date_expire is null'); + $warranties = $warr_q->iterate(); + + foreach($warranties as $row) + { + $warr = $row[0]; + + error_log('Processing warranty for ' . $warr->getID()); + + $date_purchase = $warr->getDatePurchase(); + $warr_period = $this->getWarrantyPeriod($warr); + if ($warr_period != null) + { + $expiry_date = $this->computeDateExpire($date_purchase, $warr_period); + + // save expiry date + } + } + + } + + protected function getWarrantyPeriod($warr) + { + $batt_model = $warr->getBatteryModel(); + + $warranty_class = $warr->getWarrantyClass(); + $warr_period = ''; + + if (($batt_model == null) || + (empty($warranty_class))) + + { + return null; + } + + if ($batt_model != null) + { + $batteries = $batt_model->getBatteries(); + foreach($batteries as $battery) + { + // check warranty class to get warranty period + if ($warranty_class == WarrantyClass::WTY_PRIVATE) + { + $warr_period = $battery->getWarrantyPrivate(); + error_log('Warranty Period for Private: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) + { + $warr_period = $battery->getWarrantyCommercial(); + error_log('Warranty Period for Commercial: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_TNV) + { + $warr_period = $battery->getWarrantyTnv(); + error_log('Warranty Period for TNV: ' . $warr_period); + } + } + } + + return $warr_period; + } + + protected function computeDateExpire($date_create, $warranty_period) + { + $expire_date = clone $date_create; + $expire_date->add(new DateInterval('P'.$warranty_period.'M')); + return $expire_date; + } + +} diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 91ae38d1..e644fc06 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -7,7 +7,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Dotenv\Dotenv; use Doctrine\Common\Persistence\ObjectManager; From ced729241387b980c113c410718fe3312794f284 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Dec 2019 08:19:21 +0000 Subject: [PATCH 02/23] Add customer and customer vehicle when warranty is registered via API. #285 --- .../api-bundle/Command/TestAPICommand.php | 10 +- config/services.yaml | 1 + src/Controller/CAPI/WarrantyController.php | 158 +++++++++++++++++- 3 files changed, 166 insertions(+), 3 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index d32097fe..46a4ef0a 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -53,12 +53,18 @@ class TestAPICommand extends Command 'date_expire' => '20191001', 'first_name' => 'First', 'last_name' => 'Last', - 'mobile_number' => '12345678910', + 'mobile_number' => '09231234567', ]; $api->post('/capi/warranties', $params); // get all warranties - $api->get('/capi/warranties'); + $params = [ + 'order' => 'DESC', + 'limit' => '5', + 'start' => '1', + ]; + + $api->get('/capi/warranties', $params); // warranty find diff --git a/config/services.yaml b/config/services.yaml index 42044b7d..47daf34d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -10,6 +10,7 @@ parameters: api_access_key: 'api_access_keys' app_acl_file: 'acl.yaml' app_access_key: 'access_keys' + cvu_brand_id: "%env(CVU_BRAND_ID)%" services: # default configuration for services in *this* file diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index d76afffc..83ecf74a 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -17,10 +17,16 @@ use App\Entity\SAPBattery; use App\Entity\SAPBatterySize; use App\Entity\SAPBatteryBrand; use App\Entity\PrivacyPolicy; +use App\Entity\Customer; +use App\Entity\CustomerVehicle; +use App\Entity\Vehicle; use App\Ramcar\NameValue; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; +use App\Ramcar\FuelType; +use App\Ramcar\VehicleStatusCondition; + use DateTime; use Catalyst\APIBundle\Access\Generator as ACLGenerator; @@ -226,6 +232,9 @@ class WarrantyController extends APIController try { $em->persist($warr); + + $this->getCustomerFromMobile($em, $warr); + $em->flush(); } catch (UniqueConstraintViolationException $e) @@ -488,9 +497,156 @@ class WarrantyController extends APIController } $em->persist($warr); - $em->flush(); return new APIResponse(true, 'Privacy policy for warranty set successfully.'); } + + protected function getCustomerFromMobile($em, $warranty) + { + $w_mobile = $warranty->getMobileNumber(); + if (empty($w_mobile)) + { + return null; + } + + // set values for new customer vehicle + $w_plate_number = $this->cleanPlateNumber($warranty->getPlateNumber()); + + $cust_found = false; + + $w_mobile_num = trim($w_mobile); + + // does it fit our 09XXXXXXXXX pattern? + if (preg_match('/^09[0-9]{9}$/', $w_mobile_num)) + { + // remove first '0' + $w_mobile_num = substr($w_mobile_num, 1); + error_log("CONVERTED TO $w_mobile_num"); + } + + // does it fit our 9XXXXXXXXX pattern? + if (!preg_match('/^9[0-9]{9}$/', $w_mobile_num)) + return null; + + /* + // min length 2 + // TODO: we need to check proper phone number format + // format should be '9XXXXXXXXX' + // TODO: if format doesn't fit and there's a 0 or 63 prefix, we should be able to detect and convert + if (strlen($w_mobile_num <= 2)) + continue; + */ + + $customers = $this->findCustomerByNumber($em, $w_mobile_num); + + if (!empty($customers)) + { + error_log('found customer for ' . $w_mobile_num); + foreach ($customers as $customer) + { + // get customer vehicles for customer + $c_vehicles = $customer->getVehicles(); + + $cv_found = false; + if (!empty($c_vehicles)) + { + // check if plate number of customer vehicle matches warranty plate number + foreach ($c_vehicles as $c_vehicle) + { + $clean_cv_plate = $this->cleanPlateNumber($c_vehicle->getPlateNumber()); + + // check if it's already there + if ($clean_cv_plate == $w_plate_number) + { + // customer and customer vehicle already exists + $cv_found = true; + break; + } + } + + } + + // if there was a customer vehicle matched + if ($cv_found) + { + // vehicle found, do nothing. + error_log('vehicle found - ' . $w_plate_number); + } + else + { + // customer exists but not customer vehicle + // add customer vehicle to existing customer with unknown manufacturer and make + error_log('new vehicle - ' . $w_plate_number); + $this->createCustomerVehicle($em, $customer, $this->getDefaultVehicle($em), $w_plate_number); + } + } + } + // customer not found + else + { + error_log('NEW customer and vehicle - ' . $w_plate_number); + // customer not found, add customer and customer vehicle + // get warranty first name, last name + $w_first_name = $warranty->getFirstName(); + $w_last_name = $warranty->getLastName(); + + $new_cust = new Customer(); + $new_cust->setFirstName($w_first_name) + ->setLastName($w_last_name) + ->setPhoneMobile($w_mobile_num); + + $em->persist($new_cust); + + $this->createCustomerVehicle($em, $new_cust, $this->getDefaultVehicle($em), $w_plate_number); + } + + $em->flush(); + $em->clear(); + } + + protected function getDefaultVehicle($em) + { + // get default vehicle + $cvu_brand_id = $this->getParameter('cvu_brand_id'); + $default_vehicle = $em->getRepository(Vehicle::class)->find($cvu_brand_id); + if ($default_vehicle == null) + { + $output->writeln("Need to add vehicle with default values."); + return null; + } + + return $default_vehicle; + } + + + protected function cleanPlateNumber($plate) + { + // remove spaces and make upper case + return strtoupper(str_replace(' ', '', $plate)); + } + + protected function createCustomerVehicle($em, Customer $cust, $vehicle, $plate_number) + { + $new_cv = new CustomerVehicle(); + + $new_cv->setCustomer($cust) + ->setPlateNumber($plate_number) + ->setStatusCondition(VehicleStatusCondition::BRAND_NEW) + ->setModelYear('') + ->setColor('') + ->setFuelType(FuelType::GAS) + ->setHasMotoliteBattery(true) + ->setVehicle($vehicle); + + $em->persist($new_cv); + } + + + protected function findCustomerByNumber($em, $number) + { + $customers = $em->getRepository(Customer::class)->findBy(['phone_mobile' => $number]); + return $customers; + } + } From 243d238ad7c495d33435c7dea26313597cf28ca8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 11 Dec 2019 08:43:15 +0000 Subject: [PATCH 03/23] Finish command to compute expiration date for existing warranties. #280 --- .../ComputeWarrantyExpiryDateCommand.php | 77 ++++++++++++------- src/Entity/BatteryModel.php | 1 + src/Entity/BatterySize.php | 1 + 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index 4d547d3d..c2af16b2 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Doctrine\Common\Persistence\ObjectManager; use App\Entity\Warranty; +use App\Entity\Battery; use App\Ramcar\WarrantyClass; @@ -31,7 +32,7 @@ class ComputeWarrantyExpiryDateCommand extends Command { $this->setName('warranty:computeexpirydate') ->setDescription('Compute expiry date for existing warranties.') - ->setHelp('Comput expiry date for existing warranties.'); + ->setHelp('Compute expiry date for existing warranties.'); } protected function execute(InputInterface $input, OutputInterface $output) @@ -50,9 +51,18 @@ class ComputeWarrantyExpiryDateCommand extends Command if ($warr_period != null) { $expiry_date = $this->computeDateExpire($date_purchase, $warr_period); - - // save expiry date } + else + { + $expiry_date = $date_purchase; + } + + // save expiry date + $warr->setDateExpire($expiry_date); + + $this->em->persist($warr); + $this->em->flush(); + $this->em->clear(); } } @@ -60,38 +70,53 @@ class ComputeWarrantyExpiryDateCommand extends Command protected function getWarrantyPeriod($warr) { $batt_model = $warr->getBatteryModel(); + $batt_size = $warr->getBatterySize(); $warranty_class = $warr->getWarrantyClass(); - $warr_period = ''; + $warr_period = 0; - if (($batt_model == null) || - (empty($warranty_class))) - + if ($batt_model == null) { + error_log('Battery model is null for warranty id ' . $warr->getID()); + return null; + } + if ($batt_size == null) + { + error_log('Battery size is null for warranty id ' . $warr->getID()); + return null; + } + if (empty($warranty_class)) + { + error_log('Warranty class is empty for warranty id ' . $warr->getID()); + return null; + } + + // find batttery using model and size + $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); + + if (empty($batteries)) + { + error_log('Battery not found for warranty id ' . $warr->getID()); return null; } - if ($batt_model != null) + foreach($batteries as $battery) { - $batteries = $batt_model->getBatteries(); - foreach($batteries as $battery) + // check warranty class to get warranty period + if ($warranty_class == WarrantyClass::WTY_PRIVATE) + { + $warr_period = $battery->getWarrantyPrivate(); + error_log('Warranty Period for Private: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) { - // check warranty class to get warranty period - if ($warranty_class == WarrantyClass::WTY_PRIVATE) - { - $warr_period = $battery->getWarrantyPrivate(); - error_log('Warranty Period for Private: ' . $warr_period); - } - if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) - { - $warr_period = $battery->getWarrantyCommercial(); - error_log('Warranty Period for Commercial: ' . $warr_period); - } - if ($warranty_class == WarrantyClass::WTY_TNV) - { - $warr_period = $battery->getWarrantyTnv(); - error_log('Warranty Period for TNV: ' . $warr_period); - } + $warr_period = $battery->getWarrantyCommercial(); + error_log('Warranty Period for Commercial: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_TNV) + { + $warr_period = $battery->getWarrantyTnv(); + error_log('Warranty Period for TNV: ' . $warr_period); } } diff --git a/src/Entity/BatteryModel.php b/src/Entity/BatteryModel.php index 86f3b666..b516e8a6 100644 --- a/src/Entity/BatteryModel.php +++ b/src/Entity/BatteryModel.php @@ -68,6 +68,7 @@ class BatteryModel public function getBatteries() { + // TODO: fix this to be a proper getter function // has to return set of strings because symfony is trying to move away from role objects $str_batteries = []; foreach ($this->batteries as $battery) diff --git a/src/Entity/BatterySize.php b/src/Entity/BatterySize.php index 021e115c..9fff4d44 100644 --- a/src/Entity/BatterySize.php +++ b/src/Entity/BatterySize.php @@ -89,6 +89,7 @@ class BatterySize public function getBatteries() { + // TODO: fix this to be a proper getter function // has to return set of strings because symfony is trying to move away from role objects $str_batteries = []; foreach ($this->batteries as $battery) From c1203368c04a22acf533bfaefe2cb3a7ebb83a7e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 12 Dec 2019 08:33:29 +0000 Subject: [PATCH 04/23] Use SKU to find the battery first. #280 --- .../ComputeWarrantyExpiryDateCommand.php | 68 ++++++++++++++----- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index c2af16b2..7f206cc5 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -48,6 +48,7 @@ class ComputeWarrantyExpiryDateCommand extends Command $date_purchase = $warr->getDatePurchase(); $warr_period = $this->getWarrantyPeriod($warr); + if ($warr_period != null) { $expiry_date = $this->computeDateExpire($date_purchase, $warr_period); @@ -69,30 +70,44 @@ class ComputeWarrantyExpiryDateCommand extends Command protected function getWarrantyPeriod($warr) { + // find battery via sku/sap battery first + // if sku is null, use battery model and battery size to find battery + // if all three are null, do nothing + + $batteries = null; + + $sap_battery = $warr->getSAPBattery(); $batt_model = $warr->getBatteryModel(); $batt_size = $warr->getBatterySize(); - $warranty_class = $warr->getWarrantyClass(); - $warr_period = 0; - if ($batt_model == null) - { - error_log('Battery model is null for warranty id ' . $warr->getID()); - return null; - } - if ($batt_size == null) - { - error_log('Battery size is null for warranty id ' . $warr->getID()); - return null; - } if (empty($warranty_class)) { error_log('Warranty class is empty for warranty id ' . $warr->getID()); return null; } - - // find batttery using model and size - $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); + + if ($sap_battery != null) + { + // get the battery linked to SAP Battery using sap_battery id + $batteries = $this->em->getRepository(Battery::class)->findBy(['sap_code' => $sap_battery->getID()]); + } + else + { + if ($batt_model == null) + { + error_log('Battery model is null for warranty id ' . $warr->getID()); + return null; + } + if ($batt_size == null) + { + error_log('Battery size is null for warranty id ' . $warr->getID()); + return null; + } + + // find battery using battery model and battery size + $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); + } if (empty($batteries)) { @@ -100,8 +115,13 @@ class ComputeWarrantyExpiryDateCommand extends Command return null; } - foreach($batteries as $battery) + // set to -1 to show that we haven't set a warranty period yet + // cannot set initial value to 0 because warranty tnv can be 0 + $least_warranty = -1; + $warr_period = 0; + foreach ($batteries as $battery) { + // if multiple batteries, get the smallest warranty period // check warranty class to get warranty period if ($warranty_class == WarrantyClass::WTY_PRIVATE) { @@ -118,9 +138,22 @@ class ComputeWarrantyExpiryDateCommand extends Command $warr_period = $battery->getWarrantyTnv(); error_log('Warranty Period for TNV: ' . $warr_period); } + + if ($least_warranty < 0) + { + // set least warranty to the first obtained warranty period + $least_warranty = $warr_period; + } + + if ($least_warranty > $warr_period) + { + $least_warranty = $warr_period; + } } - return $warr_period; + $warranty_period = $least_warranty; + + return $warranty_period; } protected function computeDateExpire($date_create, $warranty_period) @@ -129,5 +162,4 @@ class ComputeWarrantyExpiryDateCommand extends Command $expire_date->add(new DateInterval('P'.$warranty_period.'M')); return $expire_date; } - } From e62c3dc0971e4228efa20ca29b274dbf9a154b73 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 13 Dec 2019 09:38:26 +0000 Subject: [PATCH 05/23] Add checking for serial and plate number. #288 --- src/Controller/WarrantyController.php | 164 ++++++++++++++++++++------ 1 file changed, 128 insertions(+), 36 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index ede93334..2adf0abb 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -469,11 +469,13 @@ class WarrantyController extends Controller $first_name = trim($fields[0]); $last_name = trim($fields[1]); $mobile_number = trim($fields[4]); - $plate_number = trim($fields[9]); + $plate = trim($fields[9]); $serial = trim($fields[10]); $purchase_date = trim($fields[12]); $battery_id = trim($fields[16]); + $plate_number = $this->cleanPlateNumber($plate); + // check if purchase_date or plate_number or serial is empty or if // purchase date is valid $date_purchase = DateTime::createFromFormat('d-M-y', $purchase_date); @@ -521,53 +523,137 @@ class WarrantyController extends Controller } else { - - // new warranty - $warranty = new Warranty(); - - // get the battery purchased - // check battery first. If not found, check sap_battery - $battery = $em->getRepository(Battery::class)->find($battery_id); - if ($battery != null) + // additional validation + // check if serial number and plate number already exists + $warr_results = $em->getRepository(Warranty::class)->findBy(['serial' => $serial, 'plate_number' => $plate_number]); + if (!empty($warr_results)) { - // get the battery model and battery size - $model_id = $battery->getModel()->getID(); - $size_id = $battery->getSize()->getID(); - - $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); - $bty_size = $em->getRepository(BatterySize::class)->find($size_id); - - if ($bty_model != null) + foreach($warr_results as $warr) { - $warranty->setBatteryModel($bty_model); - } + // check if details are complete + if (empty($warr->getFirstName())) + { + if (!empty($first_name)) + { + $warr->setFirstName($first_name); + } + } + if (empty($warr->getLastName())) + { + if (!empty($last_name)) + { + $warr->setLastName($last_name); + } + } + if (empty($warr->getMobileNumber())) + { + if (!empty($mobile_number)) + { + $warr->setMobileNumber($mobile_number); + } + } + if ((empty($warr->getBatteryModel())) || + (empty($warr->getBatterySize()))) + { + if (!empty($battery_id)) + { + // find battery + $battery = $em->getRepository(Battery::class)->find($battery_id); + if (!empty($battery)) + { + // get the battery model and battery size + $model_id = $battery->getModel()->getID(); + $size_id = $battery->getSize()->getID(); - if ($bty_size != null) - { - $warranty->setBatterySize($bty_size); + $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); + $bty_size = $em->getRepository(BatterySize::class)->find($size_id); + + if ($bty_model != null) + { + $warr->setBatteryModel($bty_model); + } + if ($bty_size != null) + { + $warr->setBatterySize($bty_size); + } + $sap_code = $battery->getSAPCode(); + if (!empty($sap_code)) + { + // find sap battery + $sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code); + if (!empty($sap_batt)) + { + $warr->setSAPBattery($sap_batt); + } + } + } + } + } + if (empty($warr->getDatePurchase())) + { + if (!empty($date_purchase)) + { + $warr->setDatePurchase($date_purchase); + } + } + + // TODO: compute expiry date + $em->persist($warr); + $em->flush(); } } else { - // find battery in sap_battery - $battery = $em->getRepository(SAPBattery::class)->find($battery_id); + // new warranty + $warranty = new Warranty(); + + // get the battery purchased + // check battery first. If not found, check sap_battery + $battery = $em->getRepository(Battery::class)->find($battery_id); if ($battery != null) { - // battery is SAPBattery - $warranty->setSAPBattery($battery); + // get the battery model and battery size + $model_id = $battery->getModel()->getID(); + $size_id = $battery->getSize()->getID(); + + $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); + $bty_size = $em->getRepository(BatterySize::class)->find($size_id); + + if ($bty_model != null) + { + $warranty->setBatteryModel($bty_model); + } + + if ($bty_size != null) + { + $warranty->setBatterySize($bty_size); + } } + else + { + // find battery in sap_battery + $battery = $em->getRepository(SAPBattery::class)->find($battery_id); + if ($battery != null) + { + // battery is SAPBattery + $warranty->setSAPBattery($battery); + } + } + + // TODO: compute expiry date + + // set and save values + $warranty->setSerial($serial) + ->setPlateNumber($plate_number) + ->setFirstName($first_name) + ->setLastName($last_name) + ->setMobileNumber($mobile_number) + ->setDatePurchase($date_purchase); + + $em->persist($warranty); + $em->flush(); } - // set and save values - $warranty->setSerial($serial) - ->setPlateNumber($plate_number) - ->setFirstName($first_name) - ->setLastName($last_name) - ->setMobileNumber($mobile_number) - ->setDatePurchase($date_purchase); - - $em->persist($warranty); - $em->flush(); } $row_num++; @@ -595,4 +681,10 @@ class WarrantyController extends Controller ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); } } + + protected function cleanPlateNumber($plate) + { + // remove spaces and make upper case + return strtoupper(str_replace(' ', '', $plate)); + } } From 9c9018171ee69e1bfb5f8c9ee241d68743d64e2c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 04:05:04 +0000 Subject: [PATCH 06/23] Add quick registration test for CAPI. #288 --- .../api-bundle/Command/TestAPICommand.php | 34 +++++++++++-------- src/Controller/WarrantyController.php | 3 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index d32097fe..71497c70 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -55,14 +55,20 @@ class TestAPICommand extends Command 'last_name' => 'Last', 'mobile_number' => '12345678910', ]; - $api->post('/capi/warranties', $params); + //$api->post('/capi/warranties', $params); // get all warranties - $api->get('/capi/warranties'); + $params = [ + 'order' => 'DESC', + 'limit' => '5', + 'start' => '1', + ]; + + $api->get('/capi/warranties', $params); // warranty find - $api->get('/capi/warranties/' . $serial); + //$api->get('/capi/warranties/' . $serial); // warranty update $id = 86811; @@ -77,7 +83,7 @@ class TestAPICommand extends Command 'last_name' => 'Last', 'mobile_number' => '123456789111', ]; - $api->post('/capi/warranties/'. $id, $params); + //$api->post('/capi/warranties/'. $id, $params); // warranty set privacy policy $id = 86811; @@ -85,7 +91,7 @@ class TestAPICommand extends Command $params = [ 'privacy_policy_id' => $policy_id, ]; - $api->post('/capi/warranties/' . $id .'/privacypolicy', $params); + //$api->post('/capi/warranties/' . $id .'/privacypolicy', $params); // warranty claim $id = 86811; @@ -93,27 +99,27 @@ class TestAPICommand extends Command $params = [ 'serial' => $serial, ]; - $api->post('/capi/warranties/' . $id . '/claim', $params); + //$api->post('/capi/warranties/' . $id . '/claim', $params); // warranty cancel $id = 86811; - $api->get('/capi/warranties/' . $id . '/cancel'); + //$api->get('/capi/warranties/' . $id . '/cancel'); // plate warranty - $api->get('/capi/plates/' . $plate_num . '/warranties'); + //$api->get('/capi/plates/' . $plate_num . '/warranties'); // warranty delete $id = 86811; - $api->post('/capi/warranties/' . $id . '/delete'); + //$api->post('/capi/warranties/' . $id . '/delete'); // battery - $api->get('/capi/battery_brands'); - $api->get('/capi/battery_sizes'); - $api->get('/capi/batteries'); + //$api->get('/capi/battery_brands'); + //$api->get('/capi/battery_sizes'); + //$api->get('/capi/batteries'); // vehicle - $api->get('/capi/vehicle_manufacturers'); - $api->get('/capi/vehicles'); + //$api->get('/capi/vehicle_manufacturers'); + //$api->get('/capi/vehicles'); // privacy policy $privacy_policy_id = 2; diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 2adf0abb..1d23bc9b 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -603,7 +603,8 @@ class WarrantyController extends Controller } } else - { + { + // what if serial exists but plate number is different? // new warranty $warranty = new Warranty(); From bc74339fbf711a71a601798b16dd4945b7d7e191 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 06:18:37 +0000 Subject: [PATCH 07/23] Add checking if serial exists. #288 --- src/Controller/WarrantyController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 1d23bc9b..4da828c6 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -531,6 +531,7 @@ class WarrantyController extends Controller foreach($warr_results as $warr) { // check if details are complete + //error_log('Updating warranty with serial number ' . $serial . ' and plate number ' . $plate_number); if (empty($warr->getFirstName())) { if (!empty($first_name)) @@ -604,7 +605,16 @@ class WarrantyController extends Controller } else { - // what if serial exists but plate number is different? + // TODO: what if serial exists but plate number is different? + // check if just the serial exists + // if warranty exists, ignore for now + $w_results = $em->getRepository(Warranty::class)->findBy(['serial' => $serial]); + if (!empty($w_results)) + { + continue; + } + + //error_log('Adding warranty with serial number ' . $serial . ' and plate number ' . $plate_number); // new warranty $warranty = new Warranty(); From bd2ea5fba31fd544111ccf6485ba30a0deabf869 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 07:29:25 +0000 Subject: [PATCH 08/23] Add the WarrantyHandler service. Move the computeDateExpire to the service. #286 --- config/services.yaml | 4 +++ .../ComputeWarrantyExpiryDateCommand.php | 14 ++++---- src/Service/WarrantyHandler.php | 35 +++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/Service/WarrantyHandler.php diff --git a/config/services.yaml b/config/services.yaml index 42044b7d..14a5e6c8 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -91,6 +91,10 @@ services: arguments: $geofence_flag: "%env(GEOFENCE_ENABLE)%" + App\Service\WarrantyHandler: + arguments: + $em: "@doctrine.orm.entity_manager" + App\Command\SetCustomerPrivacyPolicyCommand: arguments: $policy_promo: "%env(POLICY_PROMO)%" diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index 7f206cc5..ee49b02d 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -12,6 +12,8 @@ use Doctrine\Common\Persistence\ObjectManager; use App\Entity\Warranty; use App\Entity\Battery; +use App\Service\WarrantyHandler; + use App\Ramcar\WarrantyClass; use DateTime; @@ -20,10 +22,12 @@ use DateInterval; class ComputeWarrantyExpiryDateCommand extends Command { protected $em; + protected $wh; - public function __construct(ObjectManager $em) + public function __construct(ObjectManager $em, WarrantyHandler $wh) { $this->em = $em; + $this->wh = $wh; parent::__construct(); } @@ -51,7 +55,7 @@ class ComputeWarrantyExpiryDateCommand extends Command if ($warr_period != null) { - $expiry_date = $this->computeDateExpire($date_purchase, $warr_period); + $expiry_date = $this->wh->computeDateExpire($date_purchase, $warr_period); } else { @@ -156,10 +160,4 @@ class ComputeWarrantyExpiryDateCommand extends Command return $warranty_period; } - protected function computeDateExpire($date_create, $warranty_period) - { - $expire_date = clone $date_create; - $expire_date->add(new DateInterval('P'.$warranty_period.'M')); - return $expire_date; - } } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php new file mode 100644 index 00000000..3e9018c5 --- /dev/null +++ b/src/Service/WarrantyHandler.php @@ -0,0 +1,35 @@ +em = $em; + } + + public function createWarranty() + { + } + + public function updateWarranty() + { + } + + public function computeDateExpire($date_create, $warranty_period) + { + $expire_date = clone $date_create; + $expire_date->add(new DateInterval('P'.$warranty_period.'M')); + return $expire_date; + } +} From 7da009f6734a78691e6d852e68191eba8f7b9579 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 09:49:48 +0000 Subject: [PATCH 09/23] Move getWarrantyPeriod into the WarrantyHandler. #286 --- .../ComputeWarrantyExpiryDateCommand.php | 91 +-------- src/Service/WarrantyHandler.php | 177 +++++++++++++++++- 2 files changed, 177 insertions(+), 91 deletions(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index ee49b02d..9c271ff6 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -51,7 +51,7 @@ class ComputeWarrantyExpiryDateCommand extends Command error_log('Processing warranty for ' . $warr->getID()); $date_purchase = $warr->getDatePurchase(); - $warr_period = $this->getWarrantyPeriod($warr); + $warr_period = $this->wh->getWarrantyPeriod($warr); if ($warr_period != null) { @@ -71,93 +71,4 @@ class ComputeWarrantyExpiryDateCommand extends Command } } - - protected function getWarrantyPeriod($warr) - { - // find battery via sku/sap battery first - // if sku is null, use battery model and battery size to find battery - // if all three are null, do nothing - - $batteries = null; - - $sap_battery = $warr->getSAPBattery(); - $batt_model = $warr->getBatteryModel(); - $batt_size = $warr->getBatterySize(); - $warranty_class = $warr->getWarrantyClass(); - - if (empty($warranty_class)) - { - error_log('Warranty class is empty for warranty id ' . $warr->getID()); - return null; - } - - if ($sap_battery != null) - { - // get the battery linked to SAP Battery using sap_battery id - $batteries = $this->em->getRepository(Battery::class)->findBy(['sap_code' => $sap_battery->getID()]); - } - else - { - if ($batt_model == null) - { - error_log('Battery model is null for warranty id ' . $warr->getID()); - return null; - } - if ($batt_size == null) - { - error_log('Battery size is null for warranty id ' . $warr->getID()); - return null; - } - - // find battery using battery model and battery size - $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); - } - - if (empty($batteries)) - { - error_log('Battery not found for warranty id ' . $warr->getID()); - return null; - } - - // set to -1 to show that we haven't set a warranty period yet - // cannot set initial value to 0 because warranty tnv can be 0 - $least_warranty = -1; - $warr_period = 0; - foreach ($batteries as $battery) - { - // if multiple batteries, get the smallest warranty period - // check warranty class to get warranty period - if ($warranty_class == WarrantyClass::WTY_PRIVATE) - { - $warr_period = $battery->getWarrantyPrivate(); - error_log('Warranty Period for Private: ' . $warr_period); - } - if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) - { - $warr_period = $battery->getWarrantyCommercial(); - error_log('Warranty Period for Commercial: ' . $warr_period); - } - if ($warranty_class == WarrantyClass::WTY_TNV) - { - $warr_period = $battery->getWarrantyTnv(); - error_log('Warranty Period for TNV: ' . $warr_period); - } - - if ($least_warranty < 0) - { - // set least warranty to the first obtained warranty period - $least_warranty = $warr_period; - } - - if ($least_warranty > $warr_period) - { - $least_warranty = $warr_period; - } - } - - $warranty_period = $least_warranty; - - return $warranty_period; - } - } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 3e9018c5..b8e832ae 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -5,6 +5,9 @@ namespace App\Service; use Doctrine\ORM\EntityManagerInterface; use App\Entity\Warranty; +use App\Entity\Battery; +use App\Entity\BatterySize; +use App\Entity\SAPBattery; use DateTime; use DateInterval; @@ -22,8 +25,91 @@ class WarrantyHandler { } - public function updateWarranty() + public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $battery_id, DateTime $date_purchase) { + // TODO: add serial and plate number to update + // TODO: check if data from existing warranty matches the new data + // check if details are complete + if (empty($warr->getFirstName())) + { + if (!empty($first_name)) + { + $warr->setFirstName($first_name); + } + } + if (empty($warr->getLastName())) + { + if (!empty($last_name)) + { + $warr->setLastName($last_name); + } + } + if (empty($warr->getMobileNumber())) + { + if (!empty($mobile_number)) + { + $warr->setMobileNumber($mobile_number); + } + } + if ((empty($warr->getBatteryModel())) || + (empty($warr->getBatterySize()))) + { + if (!empty($battery_id)) + { + // find battery + $battery = $em->getRepository(Battery::class)->find($battery_id); + if (!empty($battery)) + { + // get the battery model and battery size + $model_id = $battery->getModel()->getID(); + $size_id = $battery->getSize()->getID(); + + $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); + $bty_size = $em->getRepository(BatterySize::class)->find($size_id); + + if ($bty_model != null) + { + $warr->setBatteryModel($bty_model); + } + if ($bty_size != null) + { + $warr->setBatterySize($bty_size); + } + $sap_code = $battery->getSAPCode(); + if (!empty($sap_code)) + { + // find sap battery + $sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code); + if (!empty($sap_batt)) + { + $warr->setSAPBattery($sap_batt); + } + } + } + } + } + + $purchase_date = $warr->getDatePurchase(); + if (empty($purchase_date)) + { + if (!empty($date_purchase)) + { + $warr->setDatePurchase($date_purchase); + } + $purchase_date = $date_purchase; + } + if (empty($warr->getDateExpire())) + { + $period = getWarrantyPeriod($warr); + $expire_date = $this->computeDateExpire($purchase_date, $period); + + $warr->setDateExpire($expire_date); + } + + $em->persist($warr); + $em->flush(); + + } public function computeDateExpire($date_create, $warranty_period) @@ -32,4 +118,93 @@ class WarrantyHandler $expire_date->add(new DateInterval('P'.$warranty_period.'M')); return $expire_date; } + + public function getWarrantyPeriod($warr) + { + // find battery via sku/sap battery first + // if sku is null, use battery model and battery size to find battery + // if all three are null, do nothing + + $batteries = null; + + $sap_battery = $warr->getSAPBattery(); + $batt_model = $warr->getBatteryModel(); + $batt_size = $warr->getBatterySize(); + $warranty_class = $warr->getWarrantyClass(); + + if (empty($warranty_class)) + { + error_log('Warranty class is empty for warranty id ' . $warr->getID()); + return null; + } + + if ($sap_battery != null) + { + // get the battery linked to SAP Battery using sap_battery id + $batteries = $this->em->getRepository(Battery::class)->findBy(['sap_code' => $sap_battery->getID()]); + } + else + { + if ($batt_model == null) + { + error_log('Battery model is null for warranty id ' . $warr->getID()); + return null; + } + if ($batt_size == null) + { + error_log('Battery size is null for warranty id ' . $warr->getID()); + return null; + } + + // find battery using battery model and battery size + $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); + } + + if (empty($batteries)) + { + error_log('Battery not found for warranty id ' . $warr->getID()); + return null; + } + + // set to -1 to show that we haven't set a warranty period yet + // cannot set initial value to 0 because warranty tnv can be 0 + $least_warranty = -1; + $warr_period = 0; + foreach ($batteries as $battery) + { + // if multiple batteries, get the smallest warranty period + // check warranty class to get warranty period + if ($warranty_class == WarrantyClass::WTY_PRIVATE) + { + $warr_period = $battery->getWarrantyPrivate(); + error_log('Warranty Period for Private: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) + { + $warr_period = $battery->getWarrantyCommercial(); + error_log('Warranty Period for Commercial: ' . $warr_period); + } + if ($warranty_class == WarrantyClass::WTY_TNV) + { + $warr_period = $battery->getWarrantyTnv(); + error_log('Warranty Period for TNV: ' . $warr_period); + } + + if ($least_warranty < 0) + { + // set least warranty to the first obtained warranty period + $least_warranty = $warr_period; + } + + if ($least_warranty > $warr_period) + { + $least_warranty = $warr_period; + } + } + + $warranty_period = $least_warranty; + + return $warranty_period; + } + } From a02c364c1f8ecec87bd86d86032ff1650653c9ba Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 09:58:40 +0000 Subject: [PATCH 10/23] Fix testing issues with command. #286 --- src/Command/ComputeWarrantyExpiryDateCommand.php | 8 -------- src/Service/WarrantyHandler.php | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index 9c271ff6..e1bfd78e 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -9,16 +9,8 @@ use Symfony\Component\Console\Output\OutputInterface; use Doctrine\Common\Persistence\ObjectManager; -use App\Entity\Warranty; -use App\Entity\Battery; - use App\Service\WarrantyHandler; -use App\Ramcar\WarrantyClass; - -use DateTime; -use DateInterval; - class ComputeWarrantyExpiryDateCommand extends Command { protected $em; diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index b8e832ae..7cfd8b6a 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -9,6 +9,8 @@ use App\Entity\Battery; use App\Entity\BatterySize; use App\Entity\SAPBattery; +use App\Ramcar\WarrantyClass; + use DateTime; use DateInterval; From 0d3a96e0388358207adb37c6e455e46dfc46a4e4 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 17 Dec 2019 01:05:55 +0000 Subject: [PATCH 11/23] Move updating of warranty to handler. #286 --- src/Controller/WarrantyController.php | 84 ++++----------------------- src/Service/WarrantyHandler.php | 6 +- 2 files changed, 13 insertions(+), 77 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 4da828c6..0c715319 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -11,6 +11,8 @@ use App\Entity\BatterySize; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; +use App\Service\WarrantyHandler; + use Doctrine\ORM\Query; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; @@ -372,13 +374,14 @@ class WarrantyController extends Controller /** * @Menu(selected="warranty_list") */ - public function uploadSubmit(Request $req, EntityManagerInterface $em) + public function uploadSubmit(Request $req, EntityManagerInterface $em, + WarrantyHandler $wh) { // retrieve temporary info for file $file = $req->files->get('csv_file'); // process the csv file - $inv_entries = $this->processWarrantyFile($file, $em); + $inv_entries = $this->processWarrantyFile($file, $em, $wh); $resp = new StreamedResponse(); $resp->setCallback(function() use($inv_entries) { @@ -422,7 +425,8 @@ class WarrantyController extends Controller return $resp; } - protected function processWarrantyFile(UploadedFile $csv_file, EntityManagerInterface $em) + protected function processWarrantyFile(UploadedFile $csv_file, EntityManagerInterface $em, + WarrantyHandler $wh) { // attempt to open file try @@ -530,77 +534,9 @@ class WarrantyController extends Controller { foreach($warr_results as $warr) { - // check if details are complete - //error_log('Updating warranty with serial number ' . $serial . ' and plate number ' . $plate_number); - if (empty($warr->getFirstName())) - { - if (!empty($first_name)) - { - $warr->setFirstName($first_name); - } - } - if (empty($warr->getLastName())) - { - if (!empty($last_name)) - { - $warr->setLastName($last_name); - } - } - if (empty($warr->getMobileNumber())) - { - if (!empty($mobile_number)) - { - $warr->setMobileNumber($mobile_number); - } - } - if ((empty($warr->getBatteryModel())) || - (empty($warr->getBatterySize()))) - { - if (!empty($battery_id)) - { - // find battery - $battery = $em->getRepository(Battery::class)->find($battery_id); - if (!empty($battery)) - { - // get the battery model and battery size - $model_id = $battery->getModel()->getID(); - $size_id = $battery->getSize()->getID(); - - $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); - $bty_size = $em->getRepository(BatterySize::class)->find($size_id); - - if ($bty_model != null) - { - $warr->setBatteryModel($bty_model); - } - if ($bty_size != null) - { - $warr->setBatterySize($bty_size); - } - $sap_code = $battery->getSAPCode(); - if (!empty($sap_code)) - { - // find sap battery - $sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code); - if (!empty($sap_batt)) - { - $warr->setSAPBattery($sap_batt); - } - } - } - } - } - if (empty($warr->getDatePurchase())) - { - if (!empty($date_purchase)) - { - $warr->setDatePurchase($date_purchase); - } - } - - // TODO: compute expiry date - $em->persist($warr); - $em->flush(); + // call service to check if warranty details is incomplete and then update warranty + // using details from csv file + $wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $battery_id, $date_purchase); } } else diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 7cfd8b6a..db90828b 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -179,17 +179,17 @@ class WarrantyHandler if ($warranty_class == WarrantyClass::WTY_PRIVATE) { $warr_period = $battery->getWarrantyPrivate(); - error_log('Warranty Period for Private: ' . $warr_period); + //error_log('Warranty Period for Private: ' . $warr_period); } if ($warranty_class == WarrantyClass::WTY_COMMERCIAL) { $warr_period = $battery->getWarrantyCommercial(); - error_log('Warranty Period for Commercial: ' . $warr_period); + //error_log('Warranty Period for Commercial: ' . $warr_period); } if ($warranty_class == WarrantyClass::WTY_TNV) { $warr_period = $battery->getWarrantyTnv(); - error_log('Warranty Period for TNV: ' . $warr_period); + //error_log('Warranty Period for TNV: ' . $warr_period); } if ($least_warranty < 0) From a10ef2b5d909267fa04b2c0170a196e900ae3324 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 18 Dec 2019 07:57:39 +0000 Subject: [PATCH 12/23] Fix testing issues found for warranty handler. #286 --- .../ComputeWarrantyExpiryDateCommand.php | 35 +-- src/Controller/WarrantyController.php | 88 +++----- src/Service/WarrantyHandler.php | 213 ++++++++++++------ 3 files changed, 205 insertions(+), 131 deletions(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index e1bfd78e..1db6fd42 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -9,6 +9,8 @@ use Symfony\Component\Console\Output\OutputInterface; use Doctrine\Common\Persistence\ObjectManager; +use App\Entity\Battery; + use App\Service\WarrantyHandler; class ComputeWarrantyExpiryDateCommand extends Command @@ -43,24 +45,31 @@ class ComputeWarrantyExpiryDateCommand extends Command error_log('Processing warranty for ' . $warr->getID()); $date_purchase = $warr->getDatePurchase(); - $warr_period = $this->wh->getWarrantyPeriod($warr); - if ($warr_period != null) + $batteries = $this->wh->getBatteriesForWarrantyPeriod($warr); + if (!empty($batteries)) { - $expiry_date = $this->wh->computeDateExpire($date_purchase, $warr_period); - } - else - { - $expiry_date = $date_purchase; + $warranty_class = $warr->getWarrantyClass(); + + $warr_period = $this->wh->getWarrantyPeriod($batteries, $warranty_class); + + if ($warr_period != null) + { + $expiry_date = $this->wh->computeDateExpire($date_purchase, $warr_period); + } + else + { + $expiry_date = $date_purchase; + } + + // save expiry date + $warr->setDateExpire($expiry_date); + + $this->em->persist($warr); + $this->em->flush(); } - // save expiry date - $warr->setDateExpire($expiry_date); - - $this->em->persist($warr); - $this->em->flush(); $this->em->clear(); } - } } diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 0c715319..afdd5158 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -7,6 +7,7 @@ use App\Entity\SAPBattery; use App\Entity\Battery; use App\Entity\BatteryModel; use App\Entity\BatterySize; +use App\Entity\Invoice; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; @@ -477,8 +478,9 @@ class WarrantyController extends Controller $serial = trim($fields[10]); $purchase_date = trim($fields[12]); $battery_id = trim($fields[16]); + $batt_invoice = trim($fields[11]); - $plate_number = $this->cleanPlateNumber($plate); + $plate_number = $wh->cleanPlateNumber($plate); // check if purchase_date or plate_number or serial is empty or if // purchase date is valid @@ -515,7 +517,7 @@ class WarrantyController extends Controller 'vehicle_year' => trim($fields[8]), 'vehicle_plate_number' => $plate_number, 'battery_serial_number' => $serial, - 'battery_sales_invoice' => trim($fields[11]), + 'battery_sales_invoice' => $batt_invoice, 'battery_date_purchase' => $purchase_date, 'distributor_name' => trim($fields[13]), 'distributor_address' => trim($fields[14]), @@ -530,13 +532,42 @@ class WarrantyController extends Controller // additional validation // check if serial number and plate number already exists $warr_results = $em->getRepository(Warranty::class)->findBy(['serial' => $serial, 'plate_number' => $plate_number]); + + // get battery via the invoice because battery_id doesn't match what's in the live data + // get job order via invoice to get the warranty class + $warranty_class = ''; + $batt_list = array(); + + // find invoice + $invoice = $em->getRepository(Invoice::class)->find($batt_invoice); + if (!empty($invoice)) + { + // get job order + $jo = $invoice->getJobOrder(); + + // get warranty class + $warranty_class = $jo->getWarrantyClass(); + + // get battery + $invoice_items = $invoice->getItems(); + foreach ($invoice_items as $item) + { + $battery = $item->getBattery(); + if ($battery != null) + { + $batt_list[] = $item->getBattery(); + } + } + } + if (!empty($warr_results)) { foreach($warr_results as $warr) { // call service to check if warranty details is incomplete and then update warranty // using details from csv file - $wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $battery_id, $date_purchase); + //error_log('Updating warranty for ' . $warr->getID()); + $wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase); } } else @@ -550,57 +581,10 @@ class WarrantyController extends Controller continue; } - //error_log('Adding warranty with serial number ' . $serial . ' and plate number ' . $plate_number); - // new warranty - $warranty = new Warranty(); + //error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number); - // get the battery purchased - // check battery first. If not found, check sap_battery - $battery = $em->getRepository(Battery::class)->find($battery_id); - if ($battery != null) - { - // get the battery model and battery size - $model_id = $battery->getModel()->getID(); - $size_id = $battery->getSize()->getID(); - - $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); - $bty_size = $em->getRepository(BatterySize::class)->find($size_id); - - if ($bty_model != null) - { - $warranty->setBatteryModel($bty_model); - } - - if ($bty_size != null) - { - $warranty->setBatterySize($bty_size); - } - } - else - { - // find battery in sap_battery - $battery = $em->getRepository(SAPBattery::class)->find($battery_id); - if ($battery != null) - { - // battery is SAPBattery - $warranty->setSAPBattery($battery); - } - } - - // TODO: compute expiry date - - // set and save values - $warranty->setSerial($serial) - ->setPlateNumber($plate_number) - ->setFirstName($first_name) - ->setLastName($last_name) - ->setMobileNumber($mobile_number) - ->setDatePurchase($date_purchase); - - $em->persist($warranty); - $em->flush(); + $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); } - } $row_num++; diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index db90828b..4dd4dcae 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -8,6 +8,7 @@ use App\Entity\Warranty; use App\Entity\Battery; use App\Entity\BatterySize; use App\Entity\SAPBattery; +use App\Entity\BatteryModel; use App\Ramcar\WarrantyClass; @@ -23,11 +24,66 @@ class WarrantyHandler $this->em = $em; } - public function createWarranty() + public function createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, + $batt_list, DateTime $date_purchase, $warranty_class) { + // new warranty + $warranty = new Warranty(); + + foreach ($batt_list as $battery) + { + // get the battery model and battery size + $model_id = $battery->getModel()->getID(); + $size_id = $battery->getSize()->getID(); + + $bty_model = $this->em->getRepository(BatteryModel::class)->find($model_id); + $bty_size = $this->em->getRepository(BatterySize::class)->find($size_id); + + if ($bty_model != null) + { + $warranty->setBatteryModel($bty_model); + } + if ($bty_size != null) + { + $warranty->setBatterySize($bty_size); + } + + $sap_code = $battery->getSAPCode(); + if (!empty($sap_code)) + { + // find sap battery + $sap_battery = $this->em->getRepository(SAPBattery::class)->find($sap_code); + if ($sap_battery != null) + { + $warranty->setSAPBattery($sap_battery); + } + } + } + + // compute expiry date + if ((!empty($warranty_class)) && + (count($batt_list) != 0)) + { + $period = $this->getWarrantyPeriod($batt_list, $warranty_class); + $date_expire = $this->computeDateExpire($date_purchase, $period); + + $warranty->setDateExpire($date_expire); + } + + // set and save values + $warranty->setSerial($serial) + ->setPlateNumber($plate_number) + ->setFirstName($first_name) + ->setLastName($last_name) + ->setMobileNumber($mobile_number) + ->setDatePurchase($date_purchase); + + $this->em->persist($warranty); + $this->em->flush(); + $this->em->clear(); } - public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $battery_id, DateTime $date_purchase) + public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase) { // TODO: add serial and plate number to update // TODO: check if data from existing warranty matches the new data @@ -56,35 +112,34 @@ class WarrantyHandler if ((empty($warr->getBatteryModel())) || (empty($warr->getBatterySize()))) { - if (!empty($battery_id)) + if (count($batt_list) != 0) { - // find battery - $battery = $em->getRepository(Battery::class)->find($battery_id); - if (!empty($battery)) + foreach ($batt_list as $battery) { // get the battery model and battery size $model_id = $battery->getModel()->getID(); $size_id = $battery->getSize()->getID(); - $bty_model = $em->getRepository(BatteryModel::class)->find($model_id); - $bty_size = $em->getRepository(BatterySize::class)->find($size_id); + $bty_model = $this->em->getRepository(BatteryModel::class)->find($model_id); + $bty_size = $this->em->getRepository(BatterySize::class)->find($size_id); if ($bty_model != null) { - $warr->setBatteryModel($bty_model); + $warranty->setBatteryModel($bty_model); } if ($bty_size != null) { - $warr->setBatterySize($bty_size); + $warranty->setBatterySize($bty_size); } + $sap_code = $battery->getSAPCode(); if (!empty($sap_code)) { // find sap battery - $sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code); - if (!empty($sap_batt)) + $sap_battery = $this->em->getRepository(SAPBattery::class)->find($sap_code); + if ($sap_battery != null) { - $warr->setSAPBattery($sap_batt); + $warranty->setSAPBattery($sap_battery); } } } @@ -100,18 +155,33 @@ class WarrantyHandler } $purchase_date = $date_purchase; } + if (empty($warr->getDateExpire())) { - $period = getWarrantyPeriod($warr); - $expire_date = $this->computeDateExpire($purchase_date, $period); + $batteries = []; + if (count($batt_list) == 0) + { + $batteries = $this->getBatteriesForWarrantyPeriod($warr); + } + else + { + $batteries = $batt_list; + } - $warr->setDateExpire($expire_date); + if (!empty($batteries)) + { + $period = $this->getWarrantyPeriod($batteries, $warr->getWarrantyClass()); + if (!empty($purchase_date)) + { + $expire_date = $this->computeDateExpire($purchase_date, $period); + $warr->setDateExpire($expire_date); + } + } } - $em->persist($warr); - $em->flush(); - - + $this->em->persist($warr); + $this->em->flush(); + $this->em->clear(); } public function computeDateExpire($date_create, $warranty_period) @@ -121,53 +191,8 @@ class WarrantyHandler return $expire_date; } - public function getWarrantyPeriod($warr) + public function getWarrantyPeriod($batteries, $warranty_class) { - // find battery via sku/sap battery first - // if sku is null, use battery model and battery size to find battery - // if all three are null, do nothing - - $batteries = null; - - $sap_battery = $warr->getSAPBattery(); - $batt_model = $warr->getBatteryModel(); - $batt_size = $warr->getBatterySize(); - $warranty_class = $warr->getWarrantyClass(); - - if (empty($warranty_class)) - { - error_log('Warranty class is empty for warranty id ' . $warr->getID()); - return null; - } - - if ($sap_battery != null) - { - // get the battery linked to SAP Battery using sap_battery id - $batteries = $this->em->getRepository(Battery::class)->findBy(['sap_code' => $sap_battery->getID()]); - } - else - { - if ($batt_model == null) - { - error_log('Battery model is null for warranty id ' . $warr->getID()); - return null; - } - if ($batt_size == null) - { - error_log('Battery size is null for warranty id ' . $warr->getID()); - return null; - } - - // find battery using battery model and battery size - $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); - } - - if (empty($batteries)) - { - error_log('Battery not found for warranty id ' . $warr->getID()); - return null; - } - // set to -1 to show that we haven't set a warranty period yet // cannot set initial value to 0 because warranty tnv can be 0 $least_warranty = -1; @@ -209,4 +234,60 @@ class WarrantyHandler return $warranty_period; } + public function getBatteriesForWarrantyPeriod($warr) + { + // find battery via sku/sap battery first + // if sku is null, use battery model and battery size to find battery + // if all three are null, do nothing + $batteries = null; + + $sap_battery = $warr->getSAPBattery(); + $batt_model = $warr->getBatteryModel(); + $batt_size = $warr->getBatterySize(); + $warranty_class = $warr->getWarrantyClass(); + + if (empty($warranty_class)) + { + error_log('Warranty class is empty for warranty id ' . $warr->getID()); + return null; + } + + if ($sap_battery != null) + { + // get the battery linked to SAP Battery using sap_battery id + $batteries = $this->em->getRepository(Battery::class)->findBy(['sap_code' => $sap_battery->getID()]); + } + else + { + if ($batt_model == null) + { + error_log('Battery model is null for warranty id ' . $warr->getID()); + return null; + } + if ($batt_size == null) + { + error_log('Battery size is null for warranty id ' . $warr->getID()); + return null; + } + + // find battery using battery model and battery size + $batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]); + } + + if (empty($batteries)) + { + error_log('Battery not found for warranty id ' . $warr->getID()); + return null; + } + + return $batteries; + } + + + public function cleanPlateNumber($plate) + { + // remove spaces and make upper case + return strtoupper(str_replace(' ', '', $plate)); + } + } From ff56db09b08d544783bbc631bdda63c3006e1e85 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 20 Dec 2019 07:30:08 +0000 Subject: [PATCH 13/23] Add command to update customer vehicle from warranty data. #290 --- .../UpdateCustomerVehicleWarrantyCommand.php | 85 +++++++++++++++++++ src/Entity/CustomerVehicle.php | 2 +- src/Service/WarrantyHandler.php | 1 + 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/Command/UpdateCustomerVehicleWarrantyCommand.php diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php new file mode 100644 index 00000000..b8a1554d --- /dev/null +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -0,0 +1,85 @@ +em = $em; + $this->wh = $wh; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('customervehicle:updatewarrantyinfo') + ->setDescription('Update customer vehicle warranty.') + ->setHelp('Update customer vehicle warranty.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // get all warranties + // since it's possible that the same plate number will have multiple warranties, order them from earliest to latest + $warr_q = $this->em->createQuery('select w from App\Entity\Warranty w where w.plate_number is not null order by w.date_purchase asc'); + $warranties = $warr_q->iterate(); + + foreach ($warranties as $row) + { + $warr = $row[0]; + + // clean plate number + $plate_number = $this->wh->cleanPlateNumber($warr->getPlateNumber()); + + // get other warranty information + $serial = $warr->getSerial(); + $expiry_date = $warr->getDateExpire(); + + // find battery + $batteries = $this->wh->getBatteriesForWarrantyPeriod($warr); + + // find customer vehicle using plate number + error_log('Finding customer vehicle with plate number ' . $plate_number); + $cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); + + if (!empty($cust_vehicles)) + { + foreach ($cust_vehicles as $cv) + { + if (!empty($batteries)) + { + // set current battery to the last battery in list. + // there are cases where multiple batteries linked to an SAP code. + foreach ($batteries as $batt) + { + $cv->setCurrentBattery($batt); + } + } + $cv->setWarrantyCode($serial) + ->setWarrantyExpiration($expiry_date); + + $this->em->persist($cv); + $this->em->flush(); + } + } + $this->em->clear(); + } + } +} diff --git a/src/Entity/CustomerVehicle.php b/src/Entity/CustomerVehicle.php index 3e4c70a4..98db2ed7 100644 --- a/src/Entity/CustomerVehicle.php +++ b/src/Entity/CustomerVehicle.php @@ -81,7 +81,7 @@ class CustomerVehicle // warranty code // TODO: figure out how to check expiration /** - * @ORM\Column(type="string", length=20, nullable=true) + * @ORM\Column(type="string", length=50, nullable=true) */ protected $warranty_code; diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 4dd4dcae..70a79d94 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -234,6 +234,7 @@ class WarrantyHandler return $warranty_period; } + // TODO: Need to rename this function public function getBatteriesForWarrantyPeriod($warr) { // find battery via sku/sap battery first From 5544d99a98abb8895c9475dd32eeca7ca42c2b7d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 20 Dec 2019 10:17:31 +0000 Subject: [PATCH 14/23] Modify the updating of customer vehicle. #290 --- .../UpdateCustomerVehicleWarrantyCommand.php | 55 ++++++++++++++----- src/Entity/CustomerVehicle.php | 2 +- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php index b8a1554d..82ce0d58 100644 --- a/src/Command/UpdateCustomerVehicleWarrantyCommand.php +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -52,6 +52,14 @@ class UpdateCustomerVehicleWarrantyCommand extends Command $serial = $warr->getSerial(); $expiry_date = $warr->getDateExpire(); + // TODO: check length of serial for now. Should not exceed 20. + // there is a warranty with 2 serial codes in live + // for now, ignore the warranty + if (strlen($serial) > 20) + { + continue; + } + // find battery $batteries = $this->wh->getBatteriesForWarrantyPeriod($warr); @@ -61,23 +69,42 @@ class UpdateCustomerVehicleWarrantyCommand extends Command if (!empty($cust_vehicles)) { - foreach ($cust_vehicles as $cv) - { - if (!empty($batteries)) - { - // set current battery to the last battery in list. + //foreach ($cust_vehicles as $cv) + //{ + // if (!empty($batteries)) + // { + // set current battery to the first battery in list. // there are cases where multiple batteries linked to an SAP code. - foreach ($batteries as $batt) - { - $cv->setCurrentBattery($batt); - } - } - $cv->setWarrantyCode($serial) - ->setWarrantyExpiration($expiry_date); + //foreach ($batteries as $batt) + //{ + // $cv->setCurrentBattery($batt); + //} + // } + //$cv->setWarrantyCode($serial) + // ->setWarrantyExpiration($expiry_date); - $this->em->persist($cv); - $this->em->flush(); + //$this->em->persist($cv); + //$this->em->flush(); + + if (!empty($batteries)) + { + // set current battery to the first battery in list. + // there are cases where multiple batteries linked to an SAP code. + $battery = $batteries[0]; + $battery_id = $battery->getID(); } + $q = $this->em->createQuery('update App\Entity\CustomerVehicle cv + set cv.curr_battery = :batt_id, + cv.warranty_code = :serial, + cv.warranty_expiration = :expiry_date + where cv.plate_number = :plate_number') + ->setParameters([ + 'batt_id' => $battery_id, + 'serial' => $serial, + 'expiry_date' => $expiry_date, + 'plate_number' => $plate_number]); + $q->execute(); + } $this->em->clear(); } diff --git a/src/Entity/CustomerVehicle.php b/src/Entity/CustomerVehicle.php index 98db2ed7..3e4c70a4 100644 --- a/src/Entity/CustomerVehicle.php +++ b/src/Entity/CustomerVehicle.php @@ -81,7 +81,7 @@ class CustomerVehicle // warranty code // TODO: figure out how to check expiration /** - * @ORM\Column(type="string", length=50, nullable=true) + * @ORM\Column(type="string", length=20, nullable=true) */ protected $warranty_code; From 85483ffab808e6781bfc605f24b44c050c119f3b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 20 Dec 2019 13:16:45 +0000 Subject: [PATCH 15/23] Add updating of customer vehicle information when warranty is added. #290 --- src/Controller/WarrantyController.php | 35 +++++++++++++++++++++++++-- src/Service/WarrantyHandler.php | 5 ++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index afdd5158..87cb8db7 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -8,6 +8,7 @@ use App\Entity\Battery; use App\Entity\BatteryModel; use App\Entity\BatterySize; use App\Entity\Invoice; +use App\Entity\CustomerVehicle; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; @@ -583,10 +584,40 @@ class WarrantyController extends Controller //error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number); - $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); + $warranty = $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); + + // update customer vehicle with warranty info + // get expiry date + // TODO: test this + $expiry_date = $warranty->getDateExpire(); + + // find customer vehicle + $cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); + if (!empty($cust_vehicles)) + { + if (!empty($batt_list)) + { + // set current battery to the first battery in list. + // there are cases where multiple batteries linked to an SAP code. + $battery = $batt_list[0]; + $battery_id = $battery->getID(); + } + $q = $em->createQuery('update App\Entity\CustomerVehicle cv + set cv.curr_battery = :batt_id, + cv.warranty_code = :serial, + cv.warranty_expiration = :expiry_date + where cv.plate_number = :plate_number') + ->setParameters([ + 'batt_id' => $battery_id, + 'serial' => $serial, + 'expiry_date' => $expiry_date, + 'plate_number' => $plate_number]); + $q->execute(); + } } } - + + $em->clear(); $row_num++; } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 70a79d94..f56b0f5c 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -81,6 +81,11 @@ class WarrantyHandler $this->em->persist($warranty); $this->em->flush(); $this->em->clear(); + + if ($warranty == null) + error_log('warranty is null'); + + return $warranty; } public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase) From 10d9e6e5aecc4da018fdc31c036e21a9f56bf454 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 23 Dec 2019 02:04:48 +0000 Subject: [PATCH 16/23] Update customer vehicle warranty information when warranty is uploaded. #290 --- .../UpdateCustomerVehicleWarrantyCommand.php | 19 +------- src/Controller/WarrantyController.php | 35 ++------------- src/Service/WarrantyHandler.php | 44 ++++++++++++++++--- 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php index 82ce0d58..4449b54a 100644 --- a/src/Command/UpdateCustomerVehicleWarrantyCommand.php +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -61,7 +61,7 @@ class UpdateCustomerVehicleWarrantyCommand extends Command } // find battery - $batteries = $this->wh->getBatteriesForWarrantyPeriod($warr); + $batteries = $this->wh->getBatteriesForWarranty($warr); // find customer vehicle using plate number error_log('Finding customer vehicle with plate number ' . $plate_number); @@ -69,23 +69,6 @@ class UpdateCustomerVehicleWarrantyCommand extends Command if (!empty($cust_vehicles)) { - //foreach ($cust_vehicles as $cv) - //{ - // if (!empty($batteries)) - // { - // set current battery to the first battery in list. - // there are cases where multiple batteries linked to an SAP code. - //foreach ($batteries as $batt) - //{ - // $cv->setCurrentBattery($batt); - //} - // } - //$cv->setWarrantyCode($serial) - // ->setWarrantyExpiration($expiry_date); - - //$this->em->persist($cv); - //$this->em->flush(); - if (!empty($batteries)) { // set current battery to the first battery in list. diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 87cb8db7..40afec1a 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -567,7 +567,7 @@ class WarrantyController extends Controller { // call service to check if warranty details is incomplete and then update warranty // using details from csv file - //error_log('Updating warranty for ' . $warr->getID()); + error_log('Updating warranty for ' . $warr->getID()); $wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase); } } @@ -582,38 +582,9 @@ class WarrantyController extends Controller continue; } - //error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number); + error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number); - $warranty = $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); - - // update customer vehicle with warranty info - // get expiry date - // TODO: test this - $expiry_date = $warranty->getDateExpire(); - - // find customer vehicle - $cust_vehicles = $em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); - if (!empty($cust_vehicles)) - { - if (!empty($batt_list)) - { - // set current battery to the first battery in list. - // there are cases where multiple batteries linked to an SAP code. - $battery = $batt_list[0]; - $battery_id = $battery->getID(); - } - $q = $em->createQuery('update App\Entity\CustomerVehicle cv - set cv.curr_battery = :batt_id, - cv.warranty_code = :serial, - cv.warranty_expiration = :expiry_date - where cv.plate_number = :plate_number') - ->setParameters([ - 'batt_id' => $battery_id, - 'serial' => $serial, - 'expiry_date' => $expiry_date, - 'plate_number' => $plate_number]); - $q->execute(); - } + $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); } } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index f56b0f5c..4d4b4b62 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -9,6 +9,7 @@ use App\Entity\Battery; use App\Entity\BatterySize; use App\Entity\SAPBattery; use App\Entity\BatteryModel; +use App\Entity\CustomerVehicle; use App\Ramcar\WarrantyClass; @@ -61,6 +62,7 @@ class WarrantyHandler } // compute expiry date + $date_expire = null; if ((!empty($warranty_class)) && (count($batt_list) != 0)) { @@ -80,12 +82,41 @@ class WarrantyHandler $this->em->persist($warranty); $this->em->flush(); + + // update customer vehicle with warranty info + $this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire); + $this->em->clear(); + } - if ($warranty == null) - error_log('warranty is null'); - - return $warranty; + public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire) + { + // find customer vehicle using plate number + // error_log('Finding customer vehicle with plate number ' . $plate_number); + $cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); + $battery_id = null; + if (!empty($cust_vehicles)) + { + if (!empty($batteries)) + { + // set current battery to the first battery in list. + // there are cases where multiple batteries linked to an SAP code. + $battery = $batteries[0]; + $battery_id = $battery->getID(); + } + //error_log('Serial/Warranty Code = ' . $serial); + $q = $this->em->createQuery('update App\Entity\CustomerVehicle cv + set cv.curr_battery = :batt_id, + cv.warranty_code = :serial, + cv.warranty_expiration = :expiry_date + where cv.plate_number = :plate_number') + ->setParameters([ + 'batt_id' => $battery_id, + 'serial' => $serial, + 'expiry_date' => $date_expire, + 'plate_number' => $plate_number]); + $q->execute(); + } } public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase) @@ -166,7 +197,7 @@ class WarrantyHandler $batteries = []; if (count($batt_list) == 0) { - $batteries = $this->getBatteriesForWarrantyPeriod($warr); + $batteries = $this->getBatteriesForWarranty($warr); } else { @@ -239,8 +270,7 @@ class WarrantyHandler return $warranty_period; } - // TODO: Need to rename this function - public function getBatteriesForWarrantyPeriod($warr) + public function getBatteriesForWarranty($warr) { // find battery via sku/sap battery first // if sku is null, use battery model and battery size to find battery From eea64645b54cbf69161cd41a2ccdf9b4d97b31c5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 23 Dec 2019 03:54:01 +0000 Subject: [PATCH 17/23] Move updating of customer vehicle out of the command and into the warranty service. #290 --- src/Command/UpdateCustomerVehicleWarrantyCommand.php | 5 ++++- src/Service/WarrantyHandler.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php index 4449b54a..c771044f 100644 --- a/src/Command/UpdateCustomerVehicleWarrantyCommand.php +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -64,6 +64,7 @@ class UpdateCustomerVehicleWarrantyCommand extends Command $batteries = $this->wh->getBatteriesForWarranty($warr); // find customer vehicle using plate number + /* error_log('Finding customer vehicle with plate number ' . $plate_number); $cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); @@ -88,7 +89,9 @@ class UpdateCustomerVehicleWarrantyCommand extends Command 'plate_number' => $plate_number]); $q->execute(); - } + } */ + $this->wh->updateCustomerVehicle($serial, $batteries, $plate_number, $expiry_date); + $this->em->clear(); } } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 4d4b4b62..c63f0302 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -92,7 +92,7 @@ class WarrantyHandler public function updateCustomerVehicle($serial, $batteries, $plate_number, $date_expire) { // find customer vehicle using plate number - // error_log('Finding customer vehicle with plate number ' . $plate_number); + error_log('Finding customer vehicle with plate number ' . $plate_number); $cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); $battery_id = null; if (!empty($cust_vehicles)) From f5899f618d515a0331b70086cb5886b9be4bd253 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 20 Jan 2020 03:21:51 +0000 Subject: [PATCH 18/23] Fix for command that computes the expiration date of existing warranties. #301 --- src/Command/ComputeWarrantyExpiryDateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/ComputeWarrantyExpiryDateCommand.php b/src/Command/ComputeWarrantyExpiryDateCommand.php index 1db6fd42..383370f7 100644 --- a/src/Command/ComputeWarrantyExpiryDateCommand.php +++ b/src/Command/ComputeWarrantyExpiryDateCommand.php @@ -46,7 +46,7 @@ class ComputeWarrantyExpiryDateCommand extends Command $date_purchase = $warr->getDatePurchase(); - $batteries = $this->wh->getBatteriesForWarrantyPeriod($warr); + $batteries = $this->wh->getBatteriesForWarranty($warr); if (!empty($batteries)) { $warranty_class = $warr->getWarrantyClass(); From c224b1773d2b975d604173e07a9f1725e0d94871 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 20 Jan 2020 06:37:29 +0000 Subject: [PATCH 19/23] Modify query to find customer vehicle using plate number. #302 --- src/Command/UpdateCustomerVehicleWarrantyCommand.php | 2 +- src/Service/WarrantyHandler.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Command/UpdateCustomerVehicleWarrantyCommand.php b/src/Command/UpdateCustomerVehicleWarrantyCommand.php index c771044f..89b6e5e0 100644 --- a/src/Command/UpdateCustomerVehicleWarrantyCommand.php +++ b/src/Command/UpdateCustomerVehicleWarrantyCommand.php @@ -92,7 +92,7 @@ class UpdateCustomerVehicleWarrantyCommand extends Command } */ $this->wh->updateCustomerVehicle($serial, $batteries, $plate_number, $expiry_date); - $this->em->clear(); + $this->em->detach($row[0]); } } } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index c63f0302..bfc30021 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -93,9 +93,12 @@ class WarrantyHandler { // find customer vehicle using plate number error_log('Finding customer vehicle with plate number ' . $plate_number); - $cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]); + $cv_q = $this->em->createQuery('select count(cv) from App\Entity\CustomerVehicle cv where cv.plate_number = :plate_number') + ->setParameter('plate_number', $plate_number); + $cv_result = $cv_q->getSingleScalarResult(); + $battery_id = null; - if (!empty($cust_vehicles)) + if ($cv_result != 0) { if (!empty($batteries)) { @@ -115,8 +118,8 @@ class WarrantyHandler 'serial' => $serial, 'expiry_date' => $date_expire, 'plate_number' => $plate_number]); - $q->execute(); - } + $q->execute(); + } } public function updateWarranty(Warranty $warr, $first_name, $last_name, $mobile_number, $batt_list, DateTime $date_purchase) From d418f0ff5ad1d877db66abbe11545652b2b6659f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 22 Jan 2020 06:42:28 +0000 Subject: [PATCH 20/23] Remove hardcoded prefix from customer. Add country code to .env and services.yaml. #307 --- .env.dist | 3 +++ config/services.yaml | 8 ++++++-- src/Entity/Customer.php | 11 ++++------- .../CustomerHandler/CMBCustomerHandler.php | 19 +++++++++++++------ .../CustomerHandler/ResqCustomerHandler.php | 19 +++++++++++++------ .../JobOrderHandler/CMBJobOrderHandler.php | 15 ++++++++------- .../JobOrderHandler/ResqJobOrderHandler.php | 14 +++++++------- templates/customer/form.html.twig | 8 ++++---- 8 files changed, 58 insertions(+), 39 deletions(-) diff --git a/.env.dist b/.env.dist index f170c3c9..a9fe4b6a 100644 --- a/.env.dist +++ b/.env.dist @@ -50,3 +50,6 @@ GEOFENCE_ENABLE=settotrueorfalse CVU_MFG_ID=insertmfgidforunknownvehicles CVU_BRAND_ID=insertbrandidforunknownvehicles +# country code prefix +COUNTRY_CODE=+insertcountrycodehere + diff --git a/config/services.yaml b/config/services.yaml index d0af7f80..00c5c32f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -164,14 +164,18 @@ services: App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceGenerator\\ResqInvoiceGenerator" # job order generator - App\Service\JobOrderHandler\CMBJobOrderHandler: ~ + App\Service\JobOrderHandler\ResqJobOrderHandler: + arguments: + $country_code: "%env(COUNTRY_CODE)%" #job order generator interface #App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\CMBJobOrderHandler" App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler" # customer generator - App\Service\CustomerHandler\CMBCustomerHandler: ~ + App\Service\CustomerHandler\ResqCustomerHandler: + arguments: + $country_code: "%env(COUNTRY_CODE)%" # customer generator interface #App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\CMBCustomerHandler" diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index abe8286b..b96dfae9 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -14,9 +14,6 @@ use App\Ramcar\CustomerClassification; */ class Customer { - // TODO: make this a setting somewhere - const COUNTRY_CODE_PREFIX = '+60'; - // unique id /** * @ORM\Id @@ -266,16 +263,16 @@ class Customer $phones = []; if (!empty($this->phone_mobile)) - $phones[] = self::COUNTRY_CODE_PREFIX . $this->phone_mobile; + $phones[] = $this->phone_mobile; if (!empty($this->phone_landline)) - $phones[] = self::COUNTRY_CODE_PREFIX . $this->phone_landline; + $phones[] = $this->phone_landline; if (!empty($this->phone_office)) - $phones[] = self::COUNTRY_CODE_PREFIX . $this->phone_office; + $phones[] = $this->phone_office; if (!empty($this->phone_fax)) - $phones[] = self::COUNTRY_CODE_PREFIX . $this->phone_fax; + $phones[] = $this->phone_fax; return $phones; } diff --git a/src/Service/CustomerHandler/CMBCustomerHandler.php b/src/Service/CustomerHandler/CMBCustomerHandler.php index a0f3ca2e..fb6a888e 100644 --- a/src/Service/CustomerHandler/CMBCustomerHandler.php +++ b/src/Service/CustomerHandler/CMBCustomerHandler.php @@ -25,17 +25,17 @@ use DateTime; class CMBCustomerHandler implements CustomerHandlerInterface { - const COUNTRY_CODE_PREFIX = '+60'; - protected $em; protected $validator; - + protected $country_code; protected $template_hash; - public function __construct(EntityManagerInterface $em, ValidatorInterface $validator) + public function __construct(EntityManagerInterface $em, ValidatorInterface $validator, + string $country_code) { $this->em = $em; $this->validator = $validator; + $this->country_code = $country_code; $this->loadTemplates(); } @@ -121,7 +121,14 @@ class CMBCustomerHandler implements CustomerHandlerInterface $row['flag_csat'] = $orow->isCSAT(); // TODO: properly add mobile numbers and plate numbers as searchable/sortable fields, use doctrine events - $row['mobile_numbers'] = implode("
", $orow->getMobileNumberList()); + // prepend the country code before each mobile number + $mobile_number_list = []; + $mobile_numbers = $orow->getMobileNumberList(); + foreach ($mobile_numbers as $mobile_number) + { + $mobile_number_list[] = $this->country_code . $mobile_number; + } + $row['mobile_numbers'] = implode("
", $mobile_number_list); $row['plate_numbers'] = implode("
", $orow->getPlateNumberList()); $rows[] = $row; @@ -467,7 +474,7 @@ class CMBCustomerHandler implements CustomerHandlerInterface $cust = $cv->getCustomer(); $vehicles[] = [ 'id' => $cv->getID(), - 'text' => $cv->getPlateNumber() . ' ' . $cust->getFirstName() . ' ' . $cust->getLastName() . ' ('. self::COUNTRY_CODE_PREFIX . $cust->getPhoneMobile() . ')', + 'text' => $cv->getPlateNumber() . ' ' . $cust->getFirstName() . ' ' . $cust->getLastName() . ' ('. $this->country_code . $cust->getPhoneMobile() . ')', ]; } diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 8ea688cf..5f7e00e2 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -27,17 +27,17 @@ use DateTime; class ResqCustomerHandler implements CustomerHandlerInterface { - const COUNTRY_CODE_PREFIX = '+63'; - protected $em; protected $validator; - + protected $country_code; protected $template_hash; - public function __construct(EntityManagerInterface $em, ValidatorInterface $validator) + public function __construct(EntityManagerInterface $em, ValidatorInterface $validator, + string $country_code) { $this->em = $em; $this->validator = $validator; + $this->country_code = $country_code; $this->loadTemplates(); } @@ -124,7 +124,14 @@ class ResqCustomerHandler implements CustomerHandlerInterface $row['flag_csat'] = $orow->isCSAT(); // TODO: properly add mobile numbers and plate numbers as searchable/sortable fields, use doctrine events - $row['mobile_numbers'] = implode("
", $orow->getMobileNumberList()); + // prepend the country code before each mobile number + $mobile_number_list = []; + $mobile_numbers = $orow->getMobileNumberList(); + foreach ($mobile_numbers as $mobile_number) + { + $mobile_number_list[] = $this->country_code . $mobile_number; + } + $row['mobile_numbers'] = implode("
", $mobile_number_list); $row['plate_numbers'] = implode("
", $orow->getPlateNumberList()); $rows[] = $row; @@ -465,7 +472,7 @@ class ResqCustomerHandler implements CustomerHandlerInterface $cust = $cv->getCustomer(); $vehicles[] = [ 'id' => $cv->getID(), - 'text' => $cv->getPlateNumber() . ' ' . $cust->getFirstName() . ' ' . $cust->getLastName() . ' ('. self::COUNTRY_CODE_PREFIX . $cust->getPhoneMobile() . ')', + 'text' => $cv->getPlateNumber() . ' ' . $cust->getFirstName() . ' ' . $cust->getLastName() . ' ('. $this->country_code . $cust->getPhoneMobile() . ')', ]; } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 1e4d8f9f..89dc9663 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -55,20 +55,20 @@ use FPDF; class CMBJobOrderHandler implements JobOrderHandlerInterface { - const COUNTRY_CODE_PREFIX = '+60'; - protected $em; protected $ic; protected $security; protected $validator; protected $translator; protected $rah; + protected $country_code; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, - TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah) + TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, + string $country_code) { $this->em = $em; $this->ic = $ic; @@ -76,6 +76,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->validator = $validator; $this->translator = $translator; $this->rah = $rah; + $this->country_code = $country_code; $this->loadTemplates(); } @@ -1860,7 +1861,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Mobile Phone:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneMobile() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneMobile() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneMobile() ? $this->country_code . $customer->getPhoneMobile() : '', 0, 'L'); // get Y after right cell $y2 = $pdf->GetY(); @@ -1877,7 +1878,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Landline:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneLandline() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneLandline() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneLandline() ? $this->country_code . $customer->getPhoneLandline() : '', 0, 'L'); // get Y after right cell $y2 = $pdf->GetY(); @@ -1887,11 +1888,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Office Phone:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneOffice() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneOffice() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneOffice() ? $this->country_code . $customer->getPhoneOffice() : '', 0, 'L'); $pdf->SetX($col2_x); $pdf->Cell($label_width, $line_height, 'Fax:'); - $pdf->MultiCell($val_width, $line_height, $customer && $customer->getPhoneFax() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneFax() : '', 0, 'L'); + $pdf->MultiCell($val_width, $line_height, $customer && $customer->getPhoneFax() ? $this->country_code . $customer->getPhoneFax() : '', 0, 'L'); // insert vehicle info $cv = $obj->getCustomerVehicle(); diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index f6f07188..e91e855e 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -53,25 +53,25 @@ use FPDF; class ResqJobOrderHandler implements JobOrderHandlerInterface { - const COUNTRY_CODE_PREFIX = '+60'; - protected $em; protected $ic; protected $security; protected $validator; protected $translator; + protected $country_code; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, - TranslatorInterface $translator) + TranslatorInterface $translator, string $country_code) { $this->em = $em; $this->ic = $ic; $this->security = $security; $this->validator = $validator; $this->translator = $translator; + $this->country_code = $country_code; $this->loadTemplates(); } @@ -1868,7 +1868,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Mobile Phone:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneMobile() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneMobile() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneMobile() ? $this->country_code . $customer->getPhoneMobile() : '', 0, 'L'); // get Y after right cell $y2 = $pdf->GetY(); @@ -1885,7 +1885,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Landline:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneLandline() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneLandline() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneLandline() ? $this->country_code . $customer->getPhoneLandline() : '', 0, 'L'); // get Y after right cell $y2 = $pdf->GetY(); @@ -1895,11 +1895,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $pdf->SetXY($col2_x, $y); $pdf->Cell($label_width, $line_height, 'Office Phone:'); - $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneOffice() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneOffice() : '', 0, 'L'); + $pdf->MultiCell(0, $line_height, $customer && $customer->getPhoneOffice() ? $this->country_code . $customer->getPhoneOffice() : '', 0, 'L'); $pdf->SetX($col2_x); $pdf->Cell($label_width, $line_height, 'Fax:'); - $pdf->MultiCell($val_width, $line_height, $customer && $customer->getPhoneFax() ? self::COUNTRY_CODE_PREFIX . $customer->getPhoneFax() : '', 0, 'L'); + $pdf->MultiCell($val_width, $line_height, $customer && $customer->getPhoneFax() ? $this->country_code . $customer->getPhoneFax() : '', 0, 'L'); // insert vehicle info $cv = $obj->getCustomerVehicle(); diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig index 4f2f5e9f..f502e778 100644 --- a/templates/customer/form.html.twig +++ b/templates/customer/form.html.twig @@ -131,7 +131,7 @@ Mobile Phone
- +63 + {% trans %}country_code_prefix{% endtrans %}
@@ -141,7 +141,7 @@ Landline
- +63 + {% trans %}country_code_prefix{% endtrans %}
@@ -153,7 +153,7 @@ Office Phone
- +63 + {% trans %}country_code_prefix{% endtrans %}
@@ -163,7 +163,7 @@ Fax
- +63 + {% trans %}country_code_prefix{% endtrans %}
From d569c666e36e5ef88a87a8b2f70b3933b8eb5436 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 22 Jan 2020 08:18:30 +0000 Subject: [PATCH 21/23] Add warranty creation when JO is fulfilled to ResqJobOrderHandler. #305 --- .../JobOrderHandler/ResqJobOrderHandler.php | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e91e855e..3f6a336c 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -38,6 +38,7 @@ use App\Ramcar\JORejectionReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; +use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\APNSClient; use App\Service\MapTools; @@ -59,12 +60,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $validator; protected $translator; protected $country_code; + protected $wh; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, - TranslatorInterface $translator, string $country_code) + TranslatorInterface $translator, string $country_code, + WarrantyHandler $wh) { $this->em = $em; $this->ic = $ic; @@ -72,6 +75,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->validator = $validator; $this->translator = $translator; $this->country_code = $country_code; + $this->wh = $wh; $this->loadTemplates(); } @@ -703,6 +707,43 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ]; $mclient->sendEvent($obj, $payload); $mclient->sendRiderEvent($obj, $payload); + + // create the warranty if new battery only + if ($obj->getServiceType () == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $serial = null; + $warranty_class = $obj->getWarrantyClass(); + $first_name = $obj->getCustomer()->getFirstName(); + $last_name = $obj->getCustomer()->getLastName(); + $mobile_number = $obj->getCustomer()->getPhoneMobile(); + + // check if date fulfilled is null + if ($obj->getDateFulfill() == null) + $date_purchase = $obj->getDateCreate(); + else + $date_purchase = $obj->getDateFulfill(); + + $plate_number = $this->wh->cleanPlateNumber($obj->getCustomerVehicle()->getPlateNumber()); + + $batt_list = array(); + $invoice = $obj->getInvoice(); + if (!empty($invoice)) + { + // get battery + $invoice_items = $invoice->getItems(); + foreach ($invoice_items as $item) + { + $battery = $item->getBattery(); + if ($battery != null) + { + $batt_list[] = $item->getBattery(); + } + } + } + + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); + } + } } From 2f9f787e1d78ea0f84c05e59d12d61377fe45c14 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jan 2020 03:49:44 +0000 Subject: [PATCH 22/23] Added CMB CustomerHandler in services.yaml. #305 --- config/services.yaml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 00c5c32f..ef6e13e4 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -164,22 +164,30 @@ services: App\Service\InvoiceGeneratorInterface: "@App\\Service\\InvoiceGenerator\\ResqInvoiceGenerator" # job order generator - App\Service\JobOrderHandler\ResqJobOrderHandler: + #App\Service\JobOrderHandler\ResqJobOrderHandler: + # arguments: + # $country_code: "%env(COUNTRY_CODE)%" + + App\Service\JobOrderHandler\CMBJobOrderHandler: arguments: - $country_code: "%env(COUNTRY_CODE)%" + $country_code: "%env(COUNTRY_CODE)%" #job order generator interface - #App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\CMBJobOrderHandler" - App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler" + App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\CMBJobOrderHandler" + #App\Service\JobOrderHandlerInterface: "@App\\Service\\JobOrderHandler\\ResqJobOrderHandler" # customer generator - App\Service\CustomerHandler\ResqCustomerHandler: + App\Service\CustomerHandler\CMBCustomerHandler: arguments: - $country_code: "%env(COUNTRY_CODE)%" + $country_code: "%env(COUNTRY_CODE)%" + + #App\Service\CustomerHandler\ResqCustomerHandler: + # arguments: + # $country_code: "%env(COUNTRY_CODE)%" # customer generator interface - #App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\CMBCustomerHandler" - App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\ResqCustomerHandler" + App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\CMBCustomerHandler" + #App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\ResqCustomerHandler" # rider assignment App\Service\RiderAssignmentHandler\CMBRiderAssignmentHandler: ~ From 2c9f5180e3dcb8d0743adc8a172d1ce07029d6ed Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jan 2020 07:47:32 +0000 Subject: [PATCH 23/23] Move warranty creation when JO is fulfilled to the warranty handler for CMB. #308 --- .../JobOrderHandler/CMBJobOrderHandler.php | 110 ++++++------------ 1 file changed, 35 insertions(+), 75 deletions(-) diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 89dc9663..4803e1ec 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -40,6 +40,7 @@ use App\Ramcar\JORejectionReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; use App\Service\RiderAssignmentHandlerInterface; +use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\APNSClient; use App\Service\MapTools; @@ -62,13 +63,14 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface protected $translator; protected $rah; protected $country_code; + protected $wh; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah, - string $country_code) + string $country_code, WarrantyHandler $wh) { $this->em = $em; $this->ic = $ic; @@ -77,6 +79,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface $this->translator = $translator; $this->rah = $rah; $this->country_code = $country_code; + $this->wh = $wh; $this->loadTemplates(); } @@ -842,7 +845,37 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // create the warranty if new battery only if ($obj->getServiceType () == CMBServiceType::BATTERY_REPLACEMENT_NEW) { - $this->createWarranty($obj); + $serial = null; + $warranty_class = $obj->getWarrantyClass(); + $first_name = $obj->getCustomer()->getFirstName(); + $last_name = $obj->getCustomer()->getLastName(); + $mobile_number = $obj->getCustomer()->getPhoneMobile(); + + // check if date fulfilled is null + if ($obj->getDateFulfill() == null) + $date_purchase = $obj->getDateCreate(); + else + $date_purchase = $obj->getDateFulfill(); + + $plate_number = $this->wh->cleanPlateNumber($obj->getCustomerVehicle()->getPlateNumber()); + + $batt_list = array(); + $invoice = $obj->getInvoice(); + if (!empty($invoice)) + { + // get battery + $invoice_items = $invoice->getItems(); + foreach ($invoice_items as $item) + { + $battery = $item->getBattery(); + if ($battery != null) + { + $batt_list[] = $item->getBattery(); + } + } + } + + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); } } } @@ -2395,79 +2428,6 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface ->setWarrantyExpiration($warr_date); } - protected function createWarranty($jo) - { - $warranty = new Warranty(); - - $warranty_class = $jo->getWarrantyClass(); - $first_name = $jo->getCustomer()->getFirstName(); - $last_name = $jo->getCustomer()->getLastName(); - $mobile_number = $jo->getCustomer()->getPhoneMobile(); - - // check if date fulfilled is null - if ($jo->getDateFulfill() == null) - $date_create = $jo->getDateCreate(); - else - $date_create = $jo->getDateFulfill(); - - // normalize the plate number - $plate_number = $this->normalizePlateNumber($jo->getCustomerVehicle()->getPlateNumber()); - - // get battery and its warranty periods - $warranty_period = 0; - $invoice_items = $jo->getInvoice()->getItems(); - foreach ($invoice_items as $item) - { - if ($item->getBattery() != null) - { - $battery = $item->getBattery(); - $warranty->setBatteryModel($battery->getModel()); - $warranty->setBatterySize($battery->getSize()); - - // use getWarrantyPrivate for passenger warranty - if ($warranty_class == CMBWarrantyClass::WTY_PASSENGER) - $warranty_period = $battery->getWarrantyPrivate(); - else if ($warranty_class == CMBWarrantyClass::WTY_COMMERCIAL) - $warranty_period = $battery->getWarrantyCommercial(); - } - } - - // compute expiry date - $expiry_date = $this->computeDateExpire($date_create, $warranty_period); - - $warranty->setWarrantyClass($warranty_class) - ->setFirstName($first_name) - ->setLastName($last_name) - ->setMobileNumber($mobile_number) - ->setDatePurchase($date_create) - ->setDateExpire($expiry_date) - ->setPlateNumber($plate_number); - - $this->em->persist($warranty); - $this->em->flush(); - - } - - protected function normalizePlateNumber($plate_number) - { - // make it upper case - $plate_number = trim(strtoupper($plate_number)); - - // remove special characters and spaces - $plate_number = preg_replace('/[^A-Za-z0-9]/', '', $plate_number); - - //error_log('plate number ' . $plate_number); - - return $plate_number; - } - - protected function computeDateExpire($date_create, $warranty_period) - { - $expire_date = clone $date_create; - $expire_date->add(new DateInterval('P'.$warranty_period.'M')); - return $expire_date; - } - // TODO: re-enable search, figure out how to group the orWhere filters into one, so can execute that plus the pending filter // check if datatable filter is present and append to query protected function setQueryFilters($datatable, &$query, $qb, $hubs, $tier, $status)