54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\JobOrder;
|
|
|
|
use App\Ramcar\ServiceType;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
class JobOrderManager
|
|
{
|
|
protected $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
}
|
|
|
|
public function fulfillJobOrder($jo_id)
|
|
{
|
|
$results = $this->em->getRepository(JobOrder::class)->findby(array('id' => $jo_id, 'service_type' => ServiceType::BATTERY_REPLACEMENT_NEW));
|
|
if (isset($results[0]))
|
|
{
|
|
$jo = $results[0];
|
|
$jo->fulfill();
|
|
|
|
$cust_vehicle = $jo->getCustomerVehicle();
|
|
$invoice = $jo->getInvoice();
|
|
$this->updateCustomerVehicleBattery($cust_vehicle, $invoice);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected function updateCustomerVehicleBattery($cust_vehicle, $invoice)
|
|
{
|
|
if (($cust_vehicle != null) && ($invoice != null))
|
|
{
|
|
$items = $invoice->getItems();
|
|
foreach ($items as $item)
|
|
{
|
|
$new_battery = $item->getBattery();
|
|
$cust_vehicle->setCurrentBattery($new_battery);
|
|
$cust_vehicle->setHasMotoliteBattery(true);
|
|
}
|
|
|
|
$this->em->flush();
|
|
}
|
|
}
|
|
}
|