Merge branch '400-resq-check-jos-with-no-warranty-entries' into 'master'
Resolve "Resq - check JOs with no warranty entries" Closes #400 See merge request jankstudio/resq!450
This commit is contained in:
commit
2f80a510b0
2 changed files with 74 additions and 34 deletions
|
|
@ -19,6 +19,8 @@ use App\Entity\SAPBattery;
|
|||
use App\Ramcar\ServiceType;
|
||||
use App\Ramcar\WarrantyStatus;
|
||||
|
||||
use DoctrineExtensions\Query\Mysql\DateFormat;
|
||||
|
||||
class GenerateWarrantyFromJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
|
@ -30,7 +32,6 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$this->em = $em;
|
||||
|
||||
$this->loadSAPBatteries();
|
||||
$this->loadWarranties();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
@ -39,7 +40,10 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
{
|
||||
$this->setName('warranty:generate')
|
||||
->setDescription('Generates warranty from job order and inserts into database')
|
||||
->setHelp('Generate warranty from job order');
|
||||
->setHelp('Generate warranty from job order')
|
||||
->addArgument('start_date', InputArgument::REQUIRED, 'Start Date')
|
||||
->addArgument('end_date', InputArgument::REQUIRED, 'End Date')
|
||||
->addArgument('output_filename', InputArgument::REQUIRED, 'Output Filename');
|
||||
}
|
||||
|
||||
protected function computeDateExpire($date_create, $warranty_period)
|
||||
|
|
@ -62,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]))
|
||||
|
|
@ -96,8 +78,9 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
protected function findWarranty($plate_number, $expiry_date)
|
||||
{
|
||||
$date_expire = $expiry_date->format('Y-m-d');
|
||||
if (!isset($this->warranties_hash[$plate_number][$date_expire]))
|
||||
// find warranty given plate number and expiration date
|
||||
$results = $this->em->getRepository(Warranty::class)->findBy(['plate_number' => $plate_number, 'date_expire' => $expiry_date]);
|
||||
if (empty($results))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -109,9 +92,20 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
{
|
||||
$em = $this->em;
|
||||
|
||||
$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);
|
||||
$end_date->setTime(23, 59);
|
||||
|
||||
// to save on joins, go with invoice item first
|
||||
$query = $em->createQuery('select ii,i,jo,cv from App\Entity\InvoiceItem ii inner join ii.invoice i inner join i.job_order jo inner join jo.cus_vehicle cv join jo.customer c where ii.battery is not null and jo.service_type = :service_type');
|
||||
$query->setParameter('service_type', ServiceType::BATTERY_REPLACEMENT_NEW);
|
||||
$query = $em->createQuery('select ii,i,jo,cv from App\Entity\InvoiceItem ii inner join ii.invoice i inner join i.job_order jo inner join jo.cus_vehicle cv join jo.customer c where ii.battery is not null and jo.service_type = :service_type and jo.date_schedule > :date_start and jo.date_schedule < :date_end');
|
||||
$query->setParameter('service_type', ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
->setParameter('date_start', $start_date)
|
||||
->setParameter('date_end', $end_date);
|
||||
|
||||
/*
|
||||
$query = $em->createQuery('SELECT jo FROM App\Entity\JobOrder jo
|
||||
WHERE jo.service_type = :service_type');
|
||||
|
|
@ -120,6 +114,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
$result = $query->iterate();
|
||||
|
||||
$dupe_warranties = [];
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$invoice_item = $row[0];
|
||||
|
|
@ -169,15 +164,28 @@ 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;
|
||||
}
|
||||
|
||||
// check if warranty already exists
|
||||
$cleaned_plate_number = Warranty::cleanPlateNumber($cv->getPlateNumber());
|
||||
|
||||
$expiry_date = $this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
|
||||
$found_warranty = $this->findWarranty($cleaned_plate_number, $expiry_date);
|
||||
if (!$found_warranty)
|
||||
//$expiry_date = $this->computeDateExpire($jo->getInvoice()->getDateCreate(), $warranty_period);
|
||||
// use date_schedule as the starting point of expiry date computation
|
||||
$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 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))
|
||||
{
|
||||
$bty_model_id = $invoice_item->getBattery()->getModel()->getID();
|
||||
$bty_size_id = $invoice_item->getBattery()->getSize()->getID();
|
||||
|
|
@ -188,7 +196,7 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
|
||||
$date_create = date('Y-m-d H:i:s');
|
||||
|
||||
$date_expire = $expiry_date->format('Y-m-d');
|
||||
$date_expire = $expiry_date_date_schedule->format('Y-m-d');
|
||||
|
||||
$first_name = addslashes(trim($customer->getFirstName()));
|
||||
$last_name = addslashes(trim($customer->getLastName()));
|
||||
|
|
@ -197,13 +205,26 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
|||
$values = '(' . $bty_model_id . ',' . $bty_size_id . ',NULL,\'' . $warranty_class . '\',\''
|
||||
. $cleaned_plate_number . '\',\'' . WarrantyStatus::ACTIVE . '\',\'' . $date_create . '\',\'' . $date_purchase
|
||||
. '\',\'' . $date_expire . '\',NULL,'
|
||||
. $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\');';
|
||||
. $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\',' . 0 . ',NULL' . ');';
|
||||
|
||||
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number) VALUES ' . $values . "\n";
|
||||
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n";
|
||||
|
||||
echo $sql_statement;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -862,6 +862,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
|
||||
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
||||
}
|
||||
else
|
||||
error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue