Move warranty creation from JO to event listener. #331
This commit is contained in:
parent
ffae746a02
commit
c6217e2f76
2 changed files with 62 additions and 39 deletions
|
|
@ -5,26 +5,50 @@ namespace App\EventListener;
|
|||
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\Warranty;
|
||||
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
|
||||
use App\Ramcar\JOStatus;
|
||||
|
||||
class JobOrderStatusListener
|
||||
{
|
||||
public function __construct(WarrantyHandler $wh)
|
||||
protected $wh;
|
||||
protected $jo_handler;
|
||||
|
||||
public function __construct(WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler)
|
||||
{
|
||||
$this->wh = $wh;
|
||||
$this->jo_handler = $jo_handler;
|
||||
}
|
||||
|
||||
// when a JO is updated
|
||||
public function postUpdate(JobOrder $jo, LifecycleEventArgs $args)
|
||||
{
|
||||
$status = $jo->getStatus();
|
||||
|
||||
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
|
||||
/*
|
||||
if ($this->checkIfNewBattery($jo))
|
||||
if ($this->jo_handler->checkIfNewBattery($jo))
|
||||
{
|
||||
$serial = null;
|
||||
$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);
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -937,6 +937,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
// call rider assignment handler's fulfillJobOrder
|
||||
$this->rah->fulfillJobOrder($obj, $image_url, $rider);
|
||||
|
||||
/*
|
||||
// create the warranty if new battery only
|
||||
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);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
|
@ -2605,7 +2606,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
$cust_vehicle->setWarrantyCode($req->request->get('warranty_code'));
|
||||
|
||||
$em->persist($cust_vehicle);
|
||||
|
||||
/*
|
||||
// create the warranty if new battery only
|
||||
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);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue