100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use App\Entity\Warranty;
|
|
use App\Entity\CustomerVehicle;
|
|
|
|
use App\Service\WarrantyHandler;
|
|
|
|
class UpdateCustomerVehicleWarrantyCommand extends Command
|
|
{
|
|
protected $em;
|
|
protected $wh;
|
|
|
|
public function __construct(EntityManagerInterface $em, WarrantyHandler $wh)
|
|
{
|
|
$this->em = $em;
|
|
$this->wh = $wh;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('customervehicle:updatewarrantyinfo')
|
|
->setDescription('Update customer vehicle warranty.')
|
|
->setHelp('Update customer vehicle warranty.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
// get all warranties
|
|
// since it's possible that the same plate number will have multiple warranties, order them from earliest to latest
|
|
$warr_q = $this->em->createQuery('select w from App\Entity\Warranty w where w.plate_number is not null order by w.date_purchase asc');
|
|
$warranties = $warr_q->iterate();
|
|
|
|
foreach ($warranties as $row)
|
|
{
|
|
$warr = $row[0];
|
|
|
|
// clean plate number
|
|
$plate_number = $this->wh->cleanPlateNumber($warr->getPlateNumber());
|
|
|
|
// get other warranty information
|
|
$serial = $warr->getSerial();
|
|
$expiry_date = $warr->getDateExpire();
|
|
|
|
// TODO: check length of serial for now. Should not exceed 20.
|
|
// there is a warranty with 2 serial codes in live
|
|
// for now, ignore the warranty
|
|
if (strlen($serial) > 20)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// find battery
|
|
$batteries = $this->wh->getBatteriesForWarranty($warr);
|
|
|
|
// find customer vehicle using plate number
|
|
/*
|
|
error_log('Finding customer vehicle with plate number ' . $plate_number);
|
|
$cust_vehicles = $this->em->getRepository(CustomerVehicle::class)->findBy(['plate_number' => $plate_number]);
|
|
|
|
if (!empty($cust_vehicles))
|
|
{
|
|
if (!empty($batteries))
|
|
{
|
|
// set current battery to the first battery in list.
|
|
// there are cases where multiple batteries linked to an SAP code.
|
|
$battery = $batteries[0];
|
|
$battery_id = $battery->getID();
|
|
}
|
|
$q = $this->em->createQuery('update App\Entity\CustomerVehicle cv
|
|
set cv.curr_battery = :batt_id,
|
|
cv.warranty_code = :serial,
|
|
cv.warranty_expiration = :expiry_date
|
|
where cv.plate_number = :plate_number')
|
|
->setParameters([
|
|
'batt_id' => $battery_id,
|
|
'serial' => $serial,
|
|
'expiry_date' => $expiry_date,
|
|
'plate_number' => $plate_number]);
|
|
$q->execute();
|
|
|
|
} */
|
|
$this->wh->updateCustomerVehicle($serial, $batteries, $plate_number, $expiry_date);
|
|
|
|
$this->em->detach($row[0]);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|