Add output file for existing warranties and invalid plate numbers. #400
This commit is contained in:
parent
24d297b48f
commit
78136cc281
1 changed files with 41 additions and 28 deletions
|
|
@ -32,7 +32,6 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$this->em = $em;
|
||||
|
||||
$this->loadSAPBatteries();
|
||||
$this->loadWarranties();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
@ -43,7 +42,8 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
->setDescription('Generates warranty from job order and inserts into database')
|
||||
->setHelp('Generate warranty from job order')
|
||||
->addArgument('start_date', InputArgument::REQUIRED, 'Start Date')
|
||||
->addArgument('end_date', InputArgument::REQUIRED, 'End Date');
|
||||
->addArgument('end_date', InputArgument::REQUIRED, 'End Date')
|
||||
->addArgument('output_filename', InputArgument::REQUIRED, 'Output Filename');
|
||||
}
|
||||
|
||||
protected function computeDateExpire($date_create, $warranty_period)
|
||||
|
|
@ -66,28 +66,6 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
}
|
||||
}
|
||||
|
||||
protected function loadWarranties()
|
||||
{
|
||||
$this->warranties_hash = [];
|
||||
|
||||
/*
|
||||
$warranties = $this->em->getRepository(Warranty::class)->findAll();
|
||||
foreach($warranties as $warranty)
|
||||
{
|
||||
$plate_number = $warranty->getPlateNumber();
|
||||
$date_expire = $warranty->getDateExpire();
|
||||
|
||||
// skip null date expire
|
||||
if ($date_expire == null)
|
||||
continue;
|
||||
|
||||
$expiry_date = $date_expire->format('Y-m-d');
|
||||
|
||||
$this->warranties_hash[$plate_number][$expiry_date] = $warranty->getID();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
protected function findSAPBattery($batt_id)
|
||||
{
|
||||
if (!isset($this->sapbatt_hash[$batt_id]))
|
||||
|
|
@ -116,6 +94,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
$s_date = $input->getArgument('start_date');
|
||||
$e_date = $input->getArgument('end_date');
|
||||
$output_filename = $input->getArgument('output_filename');
|
||||
|
||||
$start_date = DateTime::createFromFormat('Ymd', $s_date);
|
||||
$end_date = DateTime::createFromFormat('Ymd', $e_date);
|
||||
|
|
@ -135,6 +114,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
$result = $query->iterate();
|
||||
|
||||
$dupe_warranties = [];
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$invoice_item = $row[0];
|
||||
|
|
@ -184,6 +164,11 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
// check if plate number is "clean". If not, do not insert into warranty
|
||||
if (!(Warranty::cleanPlateNumber($cv->getPlateNumber())))
|
||||
{
|
||||
// log with the dupes
|
||||
$dupe_warranties[] = [
|
||||
'plate_number' => $cv->getPlateNumber(),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -195,8 +180,9 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$expiry_date_date_schedule = $this->computeDateExpire($jo->getDateSchedule(), $warranty_period);
|
||||
$found_warranty_date_schedule = $this->findWarranty($cleaned_plate_number, $expiry_date_date_schedule);
|
||||
|
||||
// need to check for warranty if date schedule != date_create because first version of this command used date_create for expiry date computation
|
||||
$expiry_date_date_create = $this->computeDateExpire($jo->getDateCreate(), $warranty_period);
|
||||
// need to check for warranty using invoice date_create because
|
||||
// first version of this command used invoice's date_create for expiry date computation
|
||||
$expiry_date_date_create = $this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
|
||||
$found_warranty_date_create = $this->findWarranty($cleaned_plate_number, $expiry_date_date_create);
|
||||
|
||||
if ((!$found_warranty_date_schedule) && (!$found_warranty_date_create))
|
||||
|
|
@ -227,8 +213,18 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
}
|
||||
else
|
||||
error_log('Warranty already exists for ' . $cleaned_plate_number . ' with expiration date ' .
|
||||
$expiry_date_date_schedule->format('Y-m-d') . ' or ' . $expiry_date_date_create->format('Y-m-d'));
|
||||
{
|
||||
$expiry_date = '';
|
||||
if ($expiry_date_date_create != $expiry_date_date_schedule)
|
||||
$expiry_date = $expiry_date_date_create->format('Y-m-d');
|
||||
else
|
||||
$expiry_date = $expiry_date_date_schedule->format('Y-m-d');
|
||||
|
||||
$dupe_warranties[] = [
|
||||
'plate_number' => $cleaned_plate_number,
|
||||
'expiry_date' => $expiry_date,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -237,6 +233,23 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$em->clear();
|
||||
}
|
||||
|
||||
// check if dupes were found
|
||||
if (count($dupe_warranties) > 0)
|
||||
{
|
||||
// output file
|
||||
$dupe_outfile = fopen($output_filename, 'a');
|
||||
|
||||
foreach ($dupe_warranties as $dupe)
|
||||
{
|
||||
if (empty($dupe['expiry_date']))
|
||||
fwrite($dupe_outfile, 'Invalid plate number ' . $dupe['plate_number'] . "\n");
|
||||
else
|
||||
fwrite($dupe_outfile, 'Warranty already exists for ' . $dupe['plate_number'] . ' with expiration date ' . $dupe['expiry_date'] . "\n");
|
||||
}
|
||||
|
||||
fclose($dupe_outfile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue