Modify the customer hash. #274
This commit is contained in:
parent
9b0bd63723
commit
041d5b408b
1 changed files with 73 additions and 40 deletions
|
|
@ -94,20 +94,21 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
{
|
{
|
||||||
$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");
|
||||||
}
|
}
|
||||||
// search cust_index for numbers in mobile_array
|
|
||||||
foreach ($w_mobile_array as $w_mobile_num)
|
foreach ($w_mobile_array as $w_mobile_num)
|
||||||
{
|
{
|
||||||
foreach ($this->cust_index as $key => $customer)
|
if (!empty($w_mobile_num))
|
||||||
{
|
{
|
||||||
$c_mobile = $customer->getPhoneMobile();
|
if (isset($this->cust_index[$w_mobile_num]))
|
||||||
if (!(empty($c_mobile)))
|
|
||||||
{
|
{
|
||||||
$pos = strpos($c_mobile, $w_mobile_num);
|
$customers = $this->cust_index[$w_mobile_num];
|
||||||
if ($pos !== false)
|
|
||||||
|
foreach ($customers as $customer)
|
||||||
{
|
{
|
||||||
// mobile number belongs to existing customer
|
// get customer vehicles for customer
|
||||||
// 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
|
||||||
foreach ($c_vehicles as $c_vehicle)
|
foreach ($c_vehicles as $c_vehicle)
|
||||||
|
|
@ -115,44 +116,52 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
$cv_plate_number = $c_vehicle->getPlateNumber();
|
$cv_plate_number = $c_vehicle->getPlateNumber();
|
||||||
if ($cv_plate_number == $w_plate_number)
|
if ($cv_plate_number == $w_plate_number)
|
||||||
{
|
{
|
||||||
// move to the next warranty since current warranty belongs to an
|
// customer and customer vehicle already exists
|
||||||
// existing customer and customer vehicle
|
|
||||||
$cust_found = true;
|
$cust_found = true;
|
||||||
break 3;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$cust_found)
|
||||||
|
{
|
||||||
|
// customer exists but not customer vehicle
|
||||||
|
// add customer vehicle to existing customer with unknown manufacturer and make
|
||||||
|
$cust_found = true;
|
||||||
|
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// customer exists but not customer vehicle
|
||||||
|
// add customer vehicle to existing customer with unknown manufacturer and make
|
||||||
|
$cust_found = true;
|
||||||
|
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
||||||
}
|
}
|
||||||
// add customer vehicle to existing customer with unknown manufacturer and make
|
|
||||||
$cust_found = true;
|
|
||||||
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no customer mobile number, ignore for now
|
else
|
||||||
}
|
{
|
||||||
// if customer not found, add customer and customer vehicle
|
// customer not found, add customer and customer vehicle
|
||||||
if (!($cust_found))
|
// get warranty first name, last name
|
||||||
{
|
$w_first_name = $warr->getFirstName();
|
||||||
// get warranty first name, last name
|
$w_last_name = $warr->getLastName();
|
||||||
$w_first_name = $warr->getFirstName();
|
|
||||||
$w_last_name = $warr->getLastName();
|
|
||||||
|
|
||||||
$output->writeln($w_first_name);
|
//$output->writeln($w_first_name);
|
||||||
$output->writeln($w_last_name);
|
//$output->writeln($w_last_name);
|
||||||
$output->writeln($w_plate_number);
|
//$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);
|
->setPhoneMobile($w_mobile_num);
|
||||||
|
|
||||||
$this->em->persist($new_cust);
|
$this->em->persist($new_cust);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
$this->createCustomerVehicle($new_cust, $default_vehicle, $w_plate_number);
|
$this->createCustomerVehicle($new_cust, $default_vehicle, $w_plate_number);
|
||||||
|
|
||||||
// add latest customer to hash
|
// add latest customer to hash
|
||||||
$cust_id = $new_cust->getID();
|
$this->cust_index[$w_mobile_num][] = $new_cust;
|
||||||
$this->cust_index[$cust_id] = $new_cust;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,8 +195,8 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadCustomers()
|
protected function loadCustomers()
|
||||||
{
|
{
|
||||||
|
|
@ -197,8 +206,32 @@ class CreateCustomerFromWarrantyCommand extends Command
|
||||||
$this->cust_index = [];
|
$this->cust_index = [];
|
||||||
foreach ($customers as $customer)
|
foreach ($customers as $customer)
|
||||||
{
|
{
|
||||||
$cust_id = $customer->getID();
|
$mobile = trim($customer->getPhoneMobile());
|
||||||
$this->cust_index[$cust_id] = $customer;
|
if (!empty($mobile))
|
||||||
|
{
|
||||||
|
$mobile_array = [];
|
||||||
|
// need to check if multiple numbers in mobile
|
||||||
|
if (preg_match('/[\\\s\/]/', $mobile))
|
||||||
|
{
|
||||||
|
$mobile_array = preg_split('/[\\\s\/]/', $mobile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// only one mobile number
|
||||||
|
$mobile_array[] = $mobile;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($mobile_array as $number)
|
||||||
|
{
|
||||||
|
if (!(empty($number)))
|
||||||
|
{
|
||||||
|
if (!isset($this->cust_index[$number]))
|
||||||
|
{
|
||||||
|
$this->cust_index[$number][] = $customer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue