Add insurance information to customer vehicle endpoint #761
This commit is contained in:
parent
a002da6aad
commit
38023bdb00
5 changed files with 35 additions and 20 deletions
|
|
@ -176,6 +176,22 @@ class VehicleController extends ApiController
|
||||||
if ($cv->getName() != null)
|
if ($cv->getName() != null)
|
||||||
$cv_name = $cv->getName();
|
$cv_name = $cv->getName();
|
||||||
|
|
||||||
|
// get latest insurance row
|
||||||
|
$insurance = null;
|
||||||
|
$iobj = $cv->getLatestInsuranceApplication();
|
||||||
|
if (!empty($iobj)) {
|
||||||
|
$gt = $iobj->getGatewayTransaction();
|
||||||
|
|
||||||
|
$insurance = [
|
||||||
|
'id' => $iobj->getID(),
|
||||||
|
'status' => $iobj->getStatus(),
|
||||||
|
'coc_url' => $iobj->getCOC(),
|
||||||
|
'checkout_url' => $gt->getMetadata()['checkout_url'],
|
||||||
|
'transaction_status' => $gt->getStatus(),
|
||||||
|
'premium_amount' => (string)bcdiv($gt->getAmount(), 100), // NOTE: hard expressing as string so it's consistent
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$cv_list[] = [
|
$cv_list[] = [
|
||||||
'cv_id' => $cv->getID(),
|
'cv_id' => $cv->getID(),
|
||||||
'mfg_id' => $cv->getVehicle()->getManufacturer()->getID(),
|
'mfg_id' => $cv->getVehicle()->getManufacturer()->getID(),
|
||||||
|
|
@ -192,6 +208,7 @@ class VehicleController extends ApiController
|
||||||
'is_motolite' => $cv->hasMotoliteBattery() ? 1 : 0,
|
'is_motolite' => $cv->hasMotoliteBattery() ? 1 : 0,
|
||||||
'is_active' => $cv->isActive() ? 1 : 0,
|
'is_active' => $cv->isActive() ? 1 : 0,
|
||||||
'warranty' => $warranty,
|
'warranty' => $warranty,
|
||||||
|
'latest_insurance' => $insurance,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Ramcar\InsuranceApplicationStatus;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use Doctrine\Common\Collections\Criteria;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
|
|
@ -116,15 +118,13 @@ class CustomerVehicle
|
||||||
|
|
||||||
// link to insurance
|
// link to insurance
|
||||||
/**
|
/**
|
||||||
* @ORM\OneToOne(targetEntity="InsuranceApplication", inversedBy="customer_vehicle")
|
* @ORM\OneToMany(targetEntity="InsuranceApplication", mappedBy="customer_vehicle")
|
||||||
* @ORM\JoinColumn(name="insurance_application_id", referencedColumnName="id", nullable=true)
|
|
||||||
*/
|
*/
|
||||||
protected $insurance_application;
|
protected $insurance_applications;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->flag_active = true;
|
$this->flag_active = true;
|
||||||
|
|
||||||
$this->job_orders = new ArrayCollection();
|
$this->job_orders = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,14 +290,18 @@ class CustomerVehicle
|
||||||
return $this->flag_active;
|
return $this->flag_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setInsuranceApplication(InsuranceApplication $application)
|
public function getInsuranceApplications()
|
||||||
{
|
{
|
||||||
$this->insurance_application = $application;
|
return $this->insurance_applications;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInsuranceApplication()
|
public function getLatestInsuranceApplication()
|
||||||
{
|
{
|
||||||
return $this->insurance_application;
|
$criteria = Criteria::create()
|
||||||
|
->where(Criteria::expr()->notIn('status', [InsuranceApplicationStatus::EXPIRED, InsuranceApplicationStatus::CANCELLED]))
|
||||||
|
->orderBy(['date_submit' => Criteria::DESC])
|
||||||
|
->setMaxResults(1);
|
||||||
|
|
||||||
|
return $this->insurance_applications->matching($criteria)[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,17 +180,6 @@ class GatewayTransaction
|
||||||
return $this->ext_transaction_id;
|
return $this->ext_transaction_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCallbackClass($callback_class)
|
|
||||||
{
|
|
||||||
$this->callback_class = $callback_class;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCallbackClass()
|
|
||||||
{
|
|
||||||
return $this->callback_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMetadata($metadata)
|
public function setMetadata($metadata)
|
||||||
{
|
{
|
||||||
$this->metadata = $metadata;
|
$this->metadata = $metadata;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class InsuranceApplication
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="CustomerVehicle", inversedBy="insurance")
|
* @ORM\ManyToOne(targetEntity="CustomerVehicle", inversedBy="insurance")
|
||||||
* @ORM\JoinColumn(name="customer_vehicle_id", referencedColumnName="id")
|
* @ORM\JoinColumn(name="customer_vehicle_id", referencedColumnName="id")
|
||||||
|
* @Assert\NotBlank()
|
||||||
*/
|
*/
|
||||||
protected $customer_vehicle;
|
protected $customer_vehicle;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,14 @@ class InsuranceApplicationStatus extends NameValue
|
||||||
const CREATED = 'created';
|
const CREATED = 'created';
|
||||||
const PAID = 'paid';
|
const PAID = 'paid';
|
||||||
const COMPLETED = 'completed';
|
const COMPLETED = 'completed';
|
||||||
|
const CANCELLED = 'cancelled';
|
||||||
|
const EXPIRED = 'expired';
|
||||||
|
|
||||||
const COLLECTION = [
|
const COLLECTION = [
|
||||||
'created' => 'Created',
|
'created' => 'Created',
|
||||||
'paid' => 'Paid',
|
'paid' => 'Paid',
|
||||||
'completed' => 'Completed',
|
'completed' => 'Completed',
|
||||||
|
'cancelled' => 'Cancelled',
|
||||||
|
'expired' => 'Expired',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue