Modify the updating of customer vehicle. #290

This commit is contained in:
Korina Cordero 2019-12-20 10:17:31 +00:00
parent ff56db09b0
commit 5544d99a98
2 changed files with 42 additions and 15 deletions

View file

@ -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();
}

View file

@ -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;