Add csv file for warranties that have no phone number. #274
This commit is contained in:
parent
a8f069781d
commit
9b0bd63723
1 changed files with 121 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Command;
|
|||
use Symfony\Component\Console\Command\Command;
|
||||
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 Doctrine\Common\Persistence\ObjectManager;
|
||||
|
|
@ -18,6 +19,8 @@ use App\Entity\Vehicle;
|
|||
use App\Ramcar\FuelType;
|
||||
use App\Ramcar\VehicleStatusCondition;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class CreateCustomerFromWarrantyCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
|
@ -34,16 +37,30 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
{
|
||||
$this->setName('customer:createfromwarranty')
|
||||
->setDescription('Create customers from existing warranties.')
|
||||
->setHelp('Creates customers from existing warranties.');
|
||||
->setHelp('Creates customers from existing warranties.')
|
||||
->addArgument('file', InputArgument::REQUIRED, 'Path to the output CSV file with the warranties.');
|
||||
}
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$csv_file = $input->getArgument('file');
|
||||
|
||||
// attempt to open file
|
||||
try
|
||||
{
|
||||
$fh = fopen($csv_file, "w");
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new Exception('The file "' . $csv_file . '" could be opened.');
|
||||
}
|
||||
|
||||
// load all customers
|
||||
$this->loadCustomers();
|
||||
|
||||
// get all warranties
|
||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||
|
||||
$invalid_warranties = [];
|
||||
foreach($warranties as $warr)
|
||||
{
|
||||
$cust_found = false;
|
||||
|
|
@ -51,8 +68,9 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
$w_mobile = $warr->getMobileNumber();
|
||||
if (empty($w_mobile))
|
||||
{
|
||||
// TODO: for now, if warranty mobile number is empty, do nothing
|
||||
$output->writeln('Move to next warranty since mobile number is empty');
|
||||
// TODO: for now, if warranty mobile number is empty, add to list of invalid entries
|
||||
$invalid_warranties[] = $this->processInvalidEntries($warr);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +97,6 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
// search cust_index for numbers in mobile_array
|
||||
foreach ($w_mobile_array as $w_mobile_num)
|
||||
{
|
||||
// if present, check if customer vehicle plate number matches warranty plate number?
|
||||
foreach ($this->cust_index as $key => $customer)
|
||||
{
|
||||
$c_mobile = $customer->getPhoneMobile();
|
||||
|
|
@ -139,6 +156,37 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fputcsv($fh, $row);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
protected function loadCustomers()
|
||||
|
|
@ -170,4 +218,73 @@ class CreateCustomerFromWarrantyCommand extends Command
|
|||
$this->em->persist($new_cv);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
protected function processInvalidEntries($warr)
|
||||
{
|
||||
$batt_model = '';
|
||||
$batt_size = '';
|
||||
$sap_batt = '';
|
||||
$policy = '';
|
||||
$date_purchased = '';
|
||||
$date_expire = '';
|
||||
$date_claim = '';
|
||||
|
||||
$create_date = $warr->getDateCreate();
|
||||
$date_create = $create_date->format('d/M/y');
|
||||
|
||||
if ($warr->getDatePurchase() != null)
|
||||
{
|
||||
$p_date = $warr->getDatePurchase();
|
||||
$date_purchased = $p_date->format('d/M/y');
|
||||
}
|
||||
if ($warr->getDateClaim() != null)
|
||||
{
|
||||
$c_date = $warr->getDateClaim();
|
||||
$date_claim = $c_date->format('d/M/y');
|
||||
}
|
||||
if ($warr->getDateExpire() != null)
|
||||
{
|
||||
$e_date = $warr->getDateExpire();
|
||||
$date_expire = $e_date->format('d/M/y');
|
||||
}
|
||||
|
||||
if ($warr->getBatteryModel() != null)
|
||||
{
|
||||
$batt_model = $warr->getBatteryModel()-getName();
|
||||
}
|
||||
if ($warr->getBatterySize() != null)
|
||||
{
|
||||
$batt_size = $warr->getBatterySize()->getName();
|
||||
}
|
||||
if ($warr->getSAPBattery() != null)
|
||||
{
|
||||
$sap_batt = $warr->getSAPBattery()->getBrand()->getName();
|
||||
}
|
||||
if ($warr->getPrivacyPolicy() != null)
|
||||
{
|
||||
$policy = $warr->getPrivacyPolicy()->getName();
|
||||
}
|
||||
|
||||
$invalid_warranty = [
|
||||
'id' => $warr->getID(),
|
||||
'serial' => $warr->getSerial(),
|
||||
'warranty_class' => $warr->getWarrantyClass(),
|
||||
'last_name' => $warr->getLastName(),
|
||||
'first_name' => $warr->getFirstName(),
|
||||
'mobile_number' => $warr->getMobileNumber(),
|
||||
'plate_number' => $warr->getPlateNumber(),
|
||||
'battery_model' => $batt_model,
|
||||
'battery_size' => $batt_size,
|
||||
'sap_battery' => $sap_batt,
|
||||
'status' => $warr->getStatus(),
|
||||
'date_create' => $date_create,
|
||||
'date_purchase' => $date_purchased,
|
||||
'date_expire' => $date_expire,
|
||||
'date_claim' => $date_claim,
|
||||
'claimed_from' => $warr->getClaimedFrom(),
|
||||
'privacy_policy' => $policy,
|
||||
];
|
||||
|
||||
return $invalid_warranty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue