diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index af75e3b2..9c74dee8 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -9,6 +9,7 @@ use App\Entity\BatteryModel; use App\Entity\BatterySize; use App\Entity\Invoice; use App\Entity\CustomerVehicle; +use App\Entity\Customer; use App\Ramcar\WarrantyClass; use App\Ramcar\WarrantyStatus; @@ -647,6 +648,43 @@ class WarrantyController extends Controller } } + // find customer vehicle using plate number + $vehicle = null; + //$customer_vehicle = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $plate_number]); + $cv_query = $em->createQuery('SELECT cv FROM App\Entity\CustomerVehicle cv WHERE cv.plate_number = :plate_number'); + $customer_vehicle = $cv_query->setParameters([ + 'plate_number' => $plate_number, + ]) + ->setMaxResults(1) + ->getOneOrNullResult(); + + if ($customer_vehicle != null) + $vehicle = $customer_vehicle->getVehicle(); + + // find customer using mobile number + $customer = null; + //$customer_results = $em->getRepository(Customer::class)->findBy(['phone_mobile' => $mobile_number]); + $cust_query = $em->createQuery('SELECT c FROM App\Entity\Customer c where c.phone_mobile = :mobile_number'); + $customer_results = $cust_query->setParameters([ + 'mobile_number' => $mobile_number + ]) + ->getResult(); + + foreach ($customer_results as $cust) + { + if ($customer_vehicle != null) + { + if ($cust->getID() == $customer_vehicle->getCustomer()->getID()) + break; + } + } + + if ($customer_vehicle != null) + { + // set customer to associated customer of customer vehicle + $customer = $customer_vehicle->getCustomer(); + } + if (!empty($warr_results)) { foreach($warr_results as $warr) @@ -674,7 +712,7 @@ class WarrantyController extends Controller $source = WarrantySource::BULK_UPLOAD; $wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, - $user_id, $source); + $user_id, $source, $customer, $vehicle); } } diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 06c18590..4782a0c4 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -538,7 +538,7 @@ class Warranty return $this->file_warr_card; } - public function setVehicle(Vehicle $v) + public function setVehicle(Vehicle $v = null) { $this->vehicle = $v; return $this; @@ -637,7 +637,7 @@ class Warranty return $this->flag_validated; } - public function setCustomer(Customer $customer) + public function setCustomer(Customer $customer = null) { $this->customer = $customer; return $this;