Add output files for missing warranties, invalid plate numbers, and commercial private warranties. #407

This commit is contained in:
Korina Cordero 2020-05-18 07:17:58 +00:00
parent 4b11b7e200
commit ed2e54f428

View file

@ -17,6 +17,8 @@ use App\Ramcar\ServiceType;
use App\Service\WarrantyHandler;
use DateTime;
class GetFlawedWarrantiesCommand extends Command
{
protected $em;
@ -66,7 +68,7 @@ class GetFlawedWarrantiesCommand extends Command
$comm_private_warranties = $first_results_set['commercial_private'];
// our warranty error categories: missing, commercial_private, invalid plate number, duplicate, start date of expiry computation wrong
$this->outputResults($missing_warranties, $invalid_plate_numbers, $comm_prvate_warranties);
$this->outputResults($s_date, $e_date, $missing_warranties, $invalid_plate_numbers, $comm_private_warranties);
return 0;
}
@ -130,7 +132,6 @@ class GetFlawedWarrantiesCommand extends Command
// check if plate number is "clean". If not, do not insert into warranty
if (!(Warranty::cleanPlateNumber($cv->getPlateNumber())))
{
// log with the dupes
$invalids[] = [
'jo_id' => $jo->getID(),
'plate_number' => $cv->getPlateNumber(),
@ -144,7 +145,7 @@ class GetFlawedWarrantiesCommand extends Command
$cleaned_plate_number = Warranty::cleanPlateNumber($cv->getPlateNumber());
// use date_create of invoice as start date, as decided in group chat
$expiry_date_date_create = $this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
$expiry_date_date_create = $this->wh->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
$results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cleaned_plate_number,
'date_expire' => $expiry_date_date_create]);;
@ -215,9 +216,86 @@ class GetFlawedWarrantiesCommand extends Command
{
}
protected function outputResults($missing, $invalid, $commercial_private)
protected function outputResults($start_date, $end_date, $missing, $invalid, $commercial_private)
{
$date_range = $start_date . '-' . $end_date;
// output one file per array in csv format
// missing warranties
// we output the JOs with no warranties
$missing_csv_filename = $date_range . '-' . 'missing_warranties.csv';
try
{
$missing_fh = fopen($missing_csv_filename, 'a');
}
catch (Exception $e)
{
throw new Exception('The file "' . $missing_csv_filename . '" could not be opened.');
}
if ((count($missing)) > 0)
{
fputcsv($missing_fh, [
'JO ID',
'Plate Number',
'Expiry Date',
]);
foreach($missing as $missing_row)
{
fputcsv($missing_fh, $missing_row);
}
}
// invalid plate numbers
$invalid_plates_csv_filename = $date_range . '-' . 'invalid_plate_jos.csv';
try
{
$invalid_plates_fh = fopen($invalid_plates_csv_filename, 'a');
}
catch (Exception $e)
{
throw new Exception('The file "' . $invalid_plates_csv_filename . '" could not be opened.');
}
if ((count($invalid)) > 0)
{
fputcsv($invalid_plates_fh, [
'JO ID',
'Plate Number',
'Expiry Date',
]);
foreach($invalid as $invalid_row)
{
fputcsv($invalid_plates_fh, $invalid_row);
}
}
// warranties whose expiration dates were set to the commercial period
// but warranty class is private
$comm_private_csv_filename = $date_range . '-' . 'comm_private_warranties.csv';
try
{
$comm_private_fh = fopen($comm_private_csv_filename, 'a');
}
catch (Exception $e)
{
throw new Exception('The file "' . $comm_private_csv_filename . '" could not be opened.');
}
if ((count($commercial_private)) > 0)
{
fputcsv($comm_private_fh, [
'Warranty ID',
'Plate Number',
'Expiry Date',
]);
foreach($commercial_private as $comm_private_row)
{
fputcsv($comm_private_fh, $comm_private_row);
}
}
}
protected function loadSAPBatteries()