73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\JobOrder;
|
|
|
|
use App\Ramcar\ServiceType;
|
|
use App\Ramcar\JOStatus;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use PDO;
|
|
|
|
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;
|
|
}
|
|
|
|
public function getCustomerJobOrderCount($customer_id)
|
|
{
|
|
$db = $this->em->getConnection();
|
|
|
|
$query_sql = 'SELECT COUNT(*) AS jo_count FROM job_order WHERE customer_id = :cust_id AND status != :status_cancelled';
|
|
|
|
$query_stmt = $db->prepare($query_sql);
|
|
$query_stmt->bindValue('cust_id', $customer_id);
|
|
$query_stmt->bindValue('status_cancelled', JOStatus::CANCELLED);
|
|
|
|
$jo_results = $query_stmt->executeQuery();
|
|
$results = $jo_results->fetchAssociative();
|
|
|
|
return $results['jo_count'];
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|