Move warranty creation from JO to event listener. #331

This commit is contained in:
Korina Cordero 2020-02-20 07:01:41 +00:00
parent ffae746a02
commit c6217e2f76
2 changed files with 62 additions and 39 deletions

View file

@ -5,26 +5,50 @@ namespace App\EventListener;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use App\Entity\JobOrder; use App\Entity\JobOrder;
use App\Entity\Warranty;
use App\Service\WarrantyHandler; use App\Service\WarrantyHandler;
use App\Service\JobOrderHandlerInterface;
use App\Ramcar\JOStatus;
class JobOrderStatusListener class JobOrderStatusListener
{ {
public function __construct(WarrantyHandler $wh) protected $wh;
protected $jo_handler;
public function __construct(WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler)
{ {
$this->wh = $wh; $this->wh = $wh;
$this->jo_handler = $jo_handler;
} }
// when a JO is updated
public function postUpdate(JobOrder $jo, LifecycleEventArgs $args) public function postUpdate(JobOrder $jo, LifecycleEventArgs $args)
{ {
$status = $jo->getStatus(); $status = $jo->getStatus();
if ($status == JOStatus::FULFILLED) if ($status == JOStatus::FULFILLED)
{ {
error_log('hello!'); $this->createWarrantyFromJO($jo);
}
}
// when a new job order comes in and status is already fulfilled
public function postPersist(JobOrder $jo, LifecycleEventArgs $args)
{
$status = $jo->getStatus();
if ($status == JOStatus::FULFILLED)
{
$this->createWarrantyFromJO($jo);
}
}
protected function createWarrantyFromJO(JobOrder $jo)
{
// create warranty // create warranty
/* if ($this->jo_handler->checkIfNewBattery($jo))
if ($this->checkIfNewBattery($jo))
{ {
$serial = null; $serial = null;
$warranty_class = $jo->getWarrantyClass(); $warranty_class = $jo->getWarrantyClass();
@ -61,9 +85,7 @@ class JobOrderStatusListener
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
} }
} */
} }
} }
} }

View file

@ -937,6 +937,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
// call rider assignment handler's fulfillJobOrder // call rider assignment handler's fulfillJobOrder
$this->rah->fulfillJobOrder($obj, $image_url, $rider); $this->rah->fulfillJobOrder($obj, $image_url, $rider);
/*
// create the warranty if new battery only // create the warranty if new battery only
if ($this->checkIfNewBattery($obj)) if ($this->checkIfNewBattery($obj))
{ {
@ -979,7 +980,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
} }
} } */
// validated! save the entity // validated! save the entity
$em->flush(); $em->flush();
@ -2605,7 +2606,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$cust_vehicle->setWarrantyCode($req->request->get('warranty_code')); $cust_vehicle->setWarrantyCode($req->request->get('warranty_code'));
$em->persist($cust_vehicle); $em->persist($cust_vehicle);
/*
// create the warranty if new battery only // create the warranty if new battery only
if ($this->checkIfNewBattery($jo)) if ($this->checkIfNewBattery($jo))
{ {
@ -2648,7 +2649,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
} }
} } */
$em->flush(); $em->flush();
} }