Fix issues found during testing. #274
This commit is contained in:
parent
6bde277fef
commit
a8f069781d
1 changed files with 26 additions and 12 deletions
|
|
@ -40,25 +40,28 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
{
|
{
|
||||||
// load all customers
|
// load all customers
|
||||||
$this->loadCustomers();
|
$this->loadCustomers();
|
||||||
|
|
||||||
// get all warranties
|
// get all warranties
|
||||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||||
|
|
||||||
foreach($warranties as $warr)
|
foreach($warranties as $warr)
|
||||||
{
|
{
|
||||||
|
$cust_found = false;
|
||||||
// check if warranty mobile already exists in customer
|
// check if warranty mobile already exists in customer
|
||||||
$w_mobile = $warr->getMobileNumber();
|
$w_mobile = $warr->getMobileNumber();
|
||||||
if (empty($w_mobile))
|
if (empty($w_mobile))
|
||||||
{
|
{
|
||||||
// TODO: for now, if warranty mobile number is empty, do nothing
|
// TODO: for now, if warranty mobile number is empty, do nothing
|
||||||
|
$output->writeln('Move to next warranty since mobile number is empty');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse warranty mobile in case of multiple numbers
|
// parse warranty mobile in case of multiple numbers
|
||||||
// check for spaces, slash, and forward slash
|
// check for spaces, slash, and forward slash
|
||||||
$w_mobile_array = [];
|
$w_mobile_array = [];
|
||||||
if (preg_match('/[\/\\]/', $w_mobile))
|
if (preg_match('/[\\\s\/]/', $w_mobile))
|
||||||
{
|
{
|
||||||
$w_mobile_array = preg_split('/[\/\\]/', $w_mobile);
|
$w_mobile_array = preg_split('/[\\\s\/]/', $w_mobile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -66,11 +69,9 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
$w_mobile_array[] = $w_mobile;
|
$w_mobile_array[] = $w_mobile;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cust_found = false;
|
|
||||||
|
|
||||||
// set values for new customer vehicle
|
// set values for new customer vehicle
|
||||||
$w_plate_number = $warr->getPlateNumber();
|
$w_plate_number = $warr->getPlateNumber();
|
||||||
$default_vehicle = $this->em->getRepository(Vehicle::class)->findBy(['name' =>'Unknown']);
|
$default_vehicle = $this->em->getRepository(Vehicle::class)->findOneBy(['make' =>'Unknown']);
|
||||||
if (empty($default_vehicle))
|
if (empty($default_vehicle))
|
||||||
{
|
{
|
||||||
$output->writeln("Need to add vehicle with manufacturer name Unknown and make name Unknown");
|
$output->writeln("Need to add vehicle with manufacturer name Unknown and make name Unknown");
|
||||||
|
|
@ -84,11 +85,11 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
$c_mobile = $customer->getPhoneMobile();
|
$c_mobile = $customer->getPhoneMobile();
|
||||||
if (!(empty($c_mobile)))
|
if (!(empty($c_mobile)))
|
||||||
{
|
{
|
||||||
if (strpos($c_mobile, $w_mobile_num))
|
$pos = strpos($c_mobile, $w_mobile_num);
|
||||||
|
if ($pos !== false)
|
||||||
{
|
{
|
||||||
// mobile number belongs to existing customer
|
// mobile number belongs to existing customer
|
||||||
// get customer vehicles
|
// get customer vehicles
|
||||||
$c_vehicles = $customer->getVehicles();
|
|
||||||
if (!(empty($c_vehicles)))
|
if (!(empty($c_vehicles)))
|
||||||
{
|
{
|
||||||
// check if plate number of customer vehicle matches warranty plate number
|
// check if plate number of customer vehicle matches warranty plate number
|
||||||
|
|
@ -99,32 +100,42 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
{
|
{
|
||||||
// move to the next warranty since current warranty belongs to an
|
// move to the next warranty since current warranty belongs to an
|
||||||
// existing customer and customer vehicle
|
// existing customer and customer vehicle
|
||||||
|
$cust_found = true;
|
||||||
break 3;
|
break 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add customer vehicle to existing customer with unknown manufacturer and make
|
// add customer vehicle to existing customer with unknown manufacturer and make
|
||||||
|
$cust_found = true;
|
||||||
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
||||||
}
|
}
|
||||||
$cust_found = true;
|
|
||||||
}
|
}
|
||||||
// no customer mobile number, ignore for now
|
// no customer mobile number, ignore for now
|
||||||
}
|
}
|
||||||
// if customer not found, add customer and customer vehicle
|
// if customer not found, add customer and customer vehicle
|
||||||
if ($cust_found != true)
|
if (!($cust_found))
|
||||||
{
|
{
|
||||||
// get warranty first name, last name
|
// get warranty first name, last name
|
||||||
$w_first_name = $warr->getFirstName();
|
$w_first_name = $warr->getFirstName();
|
||||||
$w_last_name = $warr->getLastName();
|
$w_last_name = $warr->getLastName();
|
||||||
|
|
||||||
|
$output->writeln($w_first_name);
|
||||||
|
$output->writeln($w_last_name);
|
||||||
|
$output->writeln($w_plate_number);
|
||||||
|
|
||||||
$new_cust = new Customer();
|
$new_cust = new Customer();
|
||||||
$new_cust->setFirstName($w_first_name)
|
$new_cust->setFirstName($w_first_name)
|
||||||
->setLastName($w_last_name);
|
->setLastName($w_last_name)
|
||||||
|
->setPhoneMobile($w_mobile_num);
|
||||||
|
|
||||||
$this->em->persist($cust);
|
$this->em->persist($new_cust);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
$this->createCustomerVehicle($cust, $default_vehicle, $w_plate_number);
|
$this->createCustomerVehicle($new_cust, $default_vehicle, $w_plate_number);
|
||||||
|
|
||||||
|
// add latest customer to hash
|
||||||
|
$cust_id = $new_cust->getID();
|
||||||
|
$this->cust_index[$cust_id] = $new_cust;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +161,10 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
$new_cv->setCustomer($cust)
|
$new_cv->setCustomer($cust)
|
||||||
->setPlateNumber($plate_number)
|
->setPlateNumber($plate_number)
|
||||||
->setStatusCondition(VehicleStatusCondition::BRAND_NEW)
|
->setStatusCondition(VehicleStatusCondition::BRAND_NEW)
|
||||||
|
->setModelYear('')
|
||||||
|
->setColor('')
|
||||||
->setFuelType(FuelType::GAS)
|
->setFuelType(FuelType::GAS)
|
||||||
|
->setHasMotoliteBattery(true)
|
||||||
->setVehicle($vehicle);
|
->setVehicle($vehicle);
|
||||||
|
|
||||||
$this->em->persist($new_cv);
|
$this->em->persist($new_cv);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue