diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index fb5b225b..b36419eb 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -54,6 +54,12 @@ class CreateCustomerFromWarrantyCommand extends Command throw new Exception('The file "' . $csv_file . '" could be opened.'); } + // counters for warranties, customers, customer vehicles + $total_warr = 0; + $total_inv_warr = 0; + $total_cust_added = 0; + $total_cv_added = 0; + // load all customers $this->loadCustomers(); @@ -88,7 +94,12 @@ class CreateCustomerFromWarrantyCommand extends Command } // set values for new customer vehicle - $w_plate_number = $warr->getPlateNumber(); + $clean_plate = $this->cleanPlateNumber($warr->getPlateNumber()); + if (!($clean_plate)) + { + continue; + } + $w_plate_number = $clean_plate; $default_vehicle = $this->em->getRepository(Vehicle::class)->findOneBy(['make' =>'Unknown']); if (empty($default_vehicle)) { @@ -113,12 +124,21 @@ class CreateCustomerFromWarrantyCommand extends Command // check if plate number of customer vehicle matches warranty plate number foreach ($c_vehicles as $c_vehicle) { - $cv_plate_number = $c_vehicle->getPlateNumber(); - if ($cv_plate_number == $w_plate_number) + $clean_cv_plate = $this->cleanPlateNumber($c_vehicle->getPlateNumber()); + if (!($clean_cv_plate)) { - // customer and customer vehicle already exists + // add the vehicle from warranty $cust_found = true; - break; + $this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number); + } + else + { + if ($clean_cv_plate == $w_plate_number) + { + // customer and customer vehicle already exists + $cust_found = true; + break; + } } } if (!$cust_found) @@ -320,4 +340,17 @@ class CreateCustomerFromWarrantyCommand extends Command return $invalid_warranty; } + + protected function cleanPlateNumber($plate) + { + // trim and make upper case + $clean_plate = strtoupper(trim($plate)); + + // check if alphanumeric, max length is 11, no spaces + $res = preg_match("/^[A-Z0-9]{1,11}+$/", $clean_plate); + if ($res) + return $clean_plate; + + return false; + } }