From bd2ea5fba31fd544111ccf6485ba30a0deabf869 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Dec 2019 07:29:25 +0000 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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 08/10] 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 09/10] 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 10/10] 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))