Add ids to env.dist. #274
This commit is contained in:
parent
98c5bdc670
commit
737dd4e22a
2 changed files with 153 additions and 122 deletions
|
|
@ -45,3 +45,8 @@ OTP_MODE=settotestorrandom
|
|||
|
||||
# geofence
|
||||
GEOFENCE_ENABLE=settotrueorfalse
|
||||
|
||||
# unknown manufacturer and vehicle ids
|
||||
CVU_MFG_ID=insertmfgidforunknownvehicles
|
||||
CVU_BRAND_ID=insertbrandidforunknownvehicles
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
|
|
@ -42,6 +43,13 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
}
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// get the default ids from .env
|
||||
$dotenv = new Dotenv();
|
||||
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||
|
||||
$cvu_mfg_id = $_ENV['CVU_MFG_ID'];
|
||||
$cvu_brand_id = $_ENV['CVU_BRAND_ID'];
|
||||
|
||||
$csv_file = $input->getArgument('file');
|
||||
|
||||
// attempt to open file
|
||||
|
|
@ -60,162 +68,180 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
$total_cust_added = 0;
|
||||
$total_cv_added = 0;
|
||||
|
||||
// load all customers
|
||||
$this->loadCustomers();
|
||||
|
||||
// get all warranties
|
||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||
|
||||
$invalid_warranties = [];
|
||||
foreach($warranties as $warr)
|
||||
$default_vehicle = $this->em->getRepository(Vehicle::class)->find($cvu_brand_id);
|
||||
if (empty($default_vehicle))
|
||||
{
|
||||
$cust_found = false;
|
||||
// check if warranty mobile already exists in customer
|
||||
$w_mobile = $warr->getMobileNumber();
|
||||
if (empty($w_mobile))
|
||||
{
|
||||
// TODO: for now, if warranty mobile number is empty, add to list of invalid entries
|
||||
$invalid_warranties[] = $this->processInvalidEntries($warr);
|
||||
$output->writeln("Need to add vehicle with default values.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// load all customers
|
||||
$output->writeln('Loading customer data...');
|
||||
$this->loadCustomers($output);
|
||||
|
||||
continue;
|
||||
}
|
||||
// get all warranties
|
||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||
|
||||
// parse warranty mobile in case of multiple numbers
|
||||
// check for spaces, slash, and forward slash
|
||||
$w_mobile_array = [];
|
||||
if (preg_match('/[\\\s\/]/', $w_mobile))
|
||||
{
|
||||
$w_mobile_array = preg_split('/[\\\s\/]/', $w_mobile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// only one mobile number
|
||||
$w_mobile_array[] = $w_mobile;
|
||||
}
|
||||
|
||||
// set values for new customer vehicle
|
||||
$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))
|
||||
{
|
||||
$output->writeln("Need to add vehicle with manufacturer name Unknown and make name Unknown");
|
||||
}
|
||||
|
||||
foreach ($w_mobile_array as $w_mobile_num)
|
||||
{
|
||||
if (!empty($w_mobile_num))
|
||||
$invalid_warranties = [];
|
||||
$output->writeln('Processing warranties... ');
|
||||
foreach($warranties as $warr)
|
||||
{
|
||||
$total_warr++;
|
||||
$cust_found = false;
|
||||
// check if warranty mobile already exists in customer
|
||||
$w_mobile = $warr->getMobileNumber();
|
||||
if (empty($w_mobile))
|
||||
{
|
||||
if (isset($this->cust_index[$w_mobile_num]))
|
||||
// TODO: for now, if warranty mobile number is empty, add to list of invalid entries
|
||||
$invalid_warranties[] = $this->processInvalidEntries($warr);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// parse warranty mobile in case of multiple numbers
|
||||
// check for spaces, slash, and forward slash
|
||||
$w_mobile_array = [];
|
||||
if (preg_match('/[\\\s\/]/', $w_mobile))
|
||||
{
|
||||
$w_mobile_array = preg_split('/[\\\s\/]/', $w_mobile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// only one mobile number
|
||||
$w_mobile_array[] = $w_mobile;
|
||||
}
|
||||
|
||||
// set values for new customer vehicle
|
||||
$clean_plate = $this->cleanPlateNumber($warr->getPlateNumber());
|
||||
if (!($clean_plate))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$w_plate_number = $clean_plate;
|
||||
|
||||
foreach ($w_mobile_array as $w_mobile_num)
|
||||
{
|
||||
if (!empty($w_mobile_num))
|
||||
{
|
||||
$customers = $this->cust_index[$w_mobile_num];
|
||||
|
||||
foreach ($customers as $customer)
|
||||
if (isset($this->cust_index[$w_mobile_num]))
|
||||
{
|
||||
// get customer vehicles for customer
|
||||
$c_vehicles = $customer->getVehicles();
|
||||
$customers = $this->cust_index[$w_mobile_num];
|
||||
|
||||
if (!empty($c_vehicles))
|
||||
foreach ($customers as $customer)
|
||||
{
|
||||
// check if plate number of customer vehicle matches warranty plate number
|
||||
foreach ($c_vehicles as $c_vehicle)
|
||||
// get customer vehicles for customer
|
||||
$c_vehicles = $customer->getVehicles();
|
||||
|
||||
if (!empty($c_vehicles))
|
||||
{
|
||||
$clean_cv_plate = $this->cleanPlateNumber($c_vehicle->getPlateNumber());
|
||||
if (!($clean_cv_plate))
|
||||
// check if plate number of customer vehicle matches warranty plate number
|
||||
foreach ($c_vehicles as $c_vehicle)
|
||||
{
|
||||
// add the vehicle from warranty
|
||||
$cust_found = true;
|
||||
$this->createCustomerVehicle($customer, $default_vehicle, $w_plate_number);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($clean_cv_plate == $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);
|
||||
$total_cv_added++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($clean_cv_plate == $w_plate_number)
|
||||
{
|
||||
// customer and customer vehicle already exists
|
||||
$cust_found = true;
|
||||
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);
|
||||
$total_cv_added++;
|
||||
}
|
||||
}
|
||||
if (!$cust_found)
|
||||
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);
|
||||
$total_cv_added++;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// customer not found, add customer and customer vehicle
|
||||
// get warranty first name, last name
|
||||
$w_first_name = $warr->getFirstName();
|
||||
$w_last_name = $warr->getLastName();
|
||||
else
|
||||
{
|
||||
// customer not found, add customer and customer vehicle
|
||||
// get warranty first name, last name
|
||||
$w_first_name = $warr->getFirstName();
|
||||
$w_last_name = $warr->getLastName();
|
||||
|
||||
//$output->writeln($w_first_name);
|
||||
//$output->writeln($w_last_name);
|
||||
//$output->writeln($w_plate_number);
|
||||
//$output->writeln($w_first_name);
|
||||
//$output->writeln($w_last_name);
|
||||
//$output->writeln($w_plate_number);
|
||||
|
||||
$new_cust = new Customer();
|
||||
$new_cust->setFirstName($w_first_name)
|
||||
->setLastName($w_last_name)
|
||||
->setPhoneMobile($w_mobile_num);
|
||||
$new_cust = new Customer();
|
||||
$new_cust->setFirstName($w_first_name)
|
||||
->setLastName($w_last_name)
|
||||
->setPhoneMobile($w_mobile_num);
|
||||
|
||||
$this->em->persist($new_cust);
|
||||
$this->em->flush();
|
||||
$this->em->persist($new_cust);
|
||||
$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
|
||||
$this->cust_index[$w_mobile_num][] = $new_cust;
|
||||
// add latest customer to hash
|
||||
$this->cust_index[$w_mobile_num][] = $new_cust;
|
||||
|
||||
$total_cust_added++;
|
||||
$total_cv_added++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process invalid warranties, if any
|
||||
if (count($invalid_warranties) > 0)
|
||||
{
|
||||
fputcsv($fh, [
|
||||
'ID',
|
||||
'Serial',
|
||||
'Warranty Class',
|
||||
'Last Name',
|
||||
'First Name',
|
||||
'Mobile Number',
|
||||
'Plate Number',
|
||||
'Battery Model',
|
||||
'Battery Size',
|
||||
'SAP Battery',
|
||||
'Status',
|
||||
'Date Created',
|
||||
'Date Purchased',
|
||||
'Expiry Date',
|
||||
'Date Claimed',
|
||||
'Claimed From',
|
||||
'Privacy Policy',
|
||||
]);
|
||||
|
||||
foreach($invalid_warranties as $row)
|
||||
// process invalid warranties, if any
|
||||
if (count($invalid_warranties) > 0)
|
||||
{
|
||||
fputcsv($fh, $row);
|
||||
}
|
||||
}
|
||||
fputcsv($fh, [
|
||||
'ID',
|
||||
'Serial',
|
||||
'Warranty Class',
|
||||
'Last Name',
|
||||
'First Name',
|
||||
'Mobile Number',
|
||||
'Plate Number',
|
||||
'Battery Model',
|
||||
'Battery Size',
|
||||
'SAP Battery',
|
||||
'Status',
|
||||
'Date Created',
|
||||
'Date Purchased',
|
||||
'Expiry Date',
|
||||
'Date Claimed',
|
||||
'Claimed From',
|
||||
'Privacy Policy',
|
||||
]);
|
||||
|
||||
fclose($fh);
|
||||
foreach($invalid_warranties as $row)
|
||||
{
|
||||
$total_inv_warr++;
|
||||
fputcsv($fh, $row);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
|
||||
$output->writeln('Total warranties: ' . $total_warr);
|
||||
$output->writeln('Total warranties with no mobile number: ' . $total_inv_warr);
|
||||
$output->writeln('Total customers added: ' . $total_cust_added);
|
||||
$output->writeln('Total customer vehicles added: ' . $total_cv_added);
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadCustomers()
|
||||
|
|
|
|||
Loading…
Reference in a new issue