From f914fce20fb819df914fdc0a37bc16c06302bd15 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 21 Nov 2019 02:39:31 +0000 Subject: [PATCH] Add report of added customers and customer vehicles as output. #274 --- .../CreateCustomerFromWarrantyCommand.php | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index bfac02d8..9d24fc03 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -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 = '';