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)