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;