Add report of added customers and customer vehicles as output. #274

This commit is contained in:
Korina Cordero 2019-11-21 02:39:31 +00:00
parent 2b21db6c01
commit f914fce20f

View file

@ -24,6 +24,10 @@ use DateTime;
class CreateCustomerFromWarrantyCommand extends Command
{
const CV_FOUND = 'Vehicle found';
const CV_NEW = 'New vehicle';
const CUST_NEW = 'New customer and vehicle.';
protected $em;
protected $cust_index;
@ -88,8 +92,9 @@ class CreateCustomerFromWarrantyCommand extends Command
// $warranties = $warr_q->getResult();
// $warranties = $this->em->getRepository(Warranty::class)->findAll();
$invalid_warranties = [];
//$invalid_warranties = [];
// $warr_count = count($warranties);
$created_objs = [];
$output->writeln("Processing warranties... ");
foreach($warranties as $row)
{
@ -101,7 +106,7 @@ class CreateCustomerFromWarrantyCommand extends Command
if (empty($w_mobile))
{
// TODO: for now, if warranty mobile number is empty, add to list of invalid entries
$invalid_warranties[] = $this->processInvalidEntries($warr);
//$invalid_warranties[] = $this->processInvalidEntries($warr);
continue;
}
@ -188,6 +193,7 @@ class CreateCustomerFromWarrantyCommand extends Command
{
// vehicle found, do nothing.
error_log('vehicle found - ' . $w_plate_number);
$created_objs[] = $this->createReportData($warr, self::CV_FOUND);
}
else
{
@ -195,6 +201,7 @@ class CreateCustomerFromWarrantyCommand extends Command
// add customer vehicle to existing customer with unknown manufacturer and make
error_log('new vehicle - ' . $w_plate_number);
$this->createCustomerVehicle($customer, $this->getDefaultVehicle(), $w_plate_number);
$created_objs[] = $this->createReportData($warr, self::CV_NEW);
$total_cv_added++;
}
}
@ -221,8 +228,10 @@ class CreateCustomerFromWarrantyCommand extends Command
$this->createCustomerVehicle($new_cust, $this->getDefaultVehicle(), $w_plate_number);
$created_objs[] = $this->createReportData($warr, self::CUST_NEW);
// add latest customer to hash
$this->cust_index[$w_mobile_num][] = $new_cust;
//$this->cust_index[$w_mobile_num][] = $new_cust;
$total_cust_added++;
$total_cv_added++;
@ -264,11 +273,27 @@ class CreateCustomerFromWarrantyCommand extends Command
}
*/
// process the report data
if (count($created_objs) > 0)
{
fputcsv($fh, [
'ID',
'Mobile Number',
'Plate Number',
'Action Done',
]);
foreach($created_objs as $row)
{
fputcsv($fh, $row);
}
}
fclose($fh);
$output->writeln('');
$output->writeln('Total warranties: ' . $total_warr);
$output->writeln('Total warranties with no mobile number: ' . $total_inv_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);
}
@ -349,6 +374,19 @@ class CreateCustomerFromWarrantyCommand extends Command
$this->em->persist($new_cv);
}
protected function createReportData($warr, $action)
{
$obj = [
'id' => $warr->getID(),
'mobile_number' => $warr->getMobileNumber(),
'plate_number' => $warr->getPlateNumber(),
'action_done' => $action,
];
return $obj;
}
protected function processInvalidEntries($warr)
{
$batt_model = '';