Add clean plate number function. #274
This commit is contained in:
parent
041d5b408b
commit
98c5bdc670
1 changed files with 38 additions and 5 deletions
|
|
@ -54,6 +54,12 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
throw new Exception('The file "' . $csv_file . '" could be opened.');
|
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
|
// load all customers
|
||||||
$this->loadCustomers();
|
$this->loadCustomers();
|
||||||
|
|
||||||
|
|
@ -88,7 +94,12 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// set values for new customer vehicle
|
// 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']);
|
$default_vehicle = $this->em->getRepository(Vehicle::class)->findOneBy(['make' =>'Unknown']);
|
||||||
if (empty($default_vehicle))
|
if (empty($default_vehicle))
|
||||||
{
|
{
|
||||||
|
|
@ -113,12 +124,21 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
// check if plate number of customer vehicle matches warranty plate number
|
// check if plate number of customer vehicle matches warranty plate number
|
||||||
foreach ($c_vehicles as $c_vehicle)
|
foreach ($c_vehicles as $c_vehicle)
|
||||||
{
|
{
|
||||||
$cv_plate_number = $c_vehicle->getPlateNumber();
|
$clean_cv_plate = $this->cleanPlateNumber($c_vehicle->getPlateNumber());
|
||||||
if ($cv_plate_number == $w_plate_number)
|
if (!($clean_cv_plate))
|
||||||
{
|
{
|
||||||
// customer and customer vehicle already exists
|
// add the vehicle from warranty
|
||||||
$cust_found = true;
|
$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)
|
if (!$cust_found)
|
||||||
|
|
@ -320,4 +340,17 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
|
|
||||||
return $invalid_warranty;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue