Add command to update customer vehicle from warranty data. #290
This commit is contained in:
parent
a10ef2b5d9
commit
ff56db09b0
3 changed files with 87 additions and 1 deletions
85
src/Command/UpdateCustomerVehicleWarrantyCommand.php
Normal file
85
src/Command/UpdateCustomerVehicleWarrantyCommand.php
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
<?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\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\CustomerVehicle;
|
||||||
|
|
||||||
|
use App\Service\WarrantyHandler;
|
||||||
|
|
||||||
|
class UpdateCustomerVehicleWarrantyCommand extends Command
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
protected $wh;
|
||||||
|
|
||||||
|
public function __construct(ObjectManager $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();
|
||||||
|
|
||||||
|
// find battery
|
||||||
|
$batteries = $this->wh->getBatteriesForWarrantyPeriod($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))
|
||||||
|
{
|
||||||
|
foreach ($cust_vehicles as $cv)
|
||||||
|
{
|
||||||
|
if (!empty($batteries))
|
||||||
|
{
|
||||||
|
// set current battery to the last battery in list.
|
||||||
|
// there are cases where multiple batteries linked to an SAP code.
|
||||||
|
foreach ($batteries as $batt)
|
||||||
|
{
|
||||||
|
$cv->setCurrentBattery($batt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$cv->setWarrantyCode($serial)
|
||||||
|
->setWarrantyExpiration($expiry_date);
|
||||||
|
|
||||||
|
$this->em->persist($cv);
|
||||||
|
$this->em->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->em->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ class CustomerVehicle
|
||||||
// warranty code
|
// warranty code
|
||||||
// TODO: figure out how to check expiration
|
// TODO: figure out how to check expiration
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=20, nullable=true)
|
* @ORM\Column(type="string", length=50, nullable=true)
|
||||||
*/
|
*/
|
||||||
protected $warranty_code;
|
protected $warranty_code;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@ class WarrantyHandler
|
||||||
return $warranty_period;
|
return $warranty_period;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Need to rename this function
|
||||||
public function getBatteriesForWarrantyPeriod($warr)
|
public function getBatteriesForWarrantyPeriod($warr)
|
||||||
{
|
{
|
||||||
// find battery via sku/sap battery first
|
// find battery via sku/sap battery first
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue