resq/src/Entity/CustomerVehicle.php
2024-08-24 07:50:50 +08:00

338 lines
7.6 KiB
PHP

<?php
namespace App\Entity;
use App\Ramcar\InsuranceApplicationStatus;
use App\Ramcar\SubscriptionStatus;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use DateTime;
use Doctrine\Common\Collections\Criteria;
/**
* @ORM\Entity
* @ORM\Table(name="customer_vehicle", indexes={@ORM\Index(columns={"plate_number"}, flags={"fulltext"}),
@ORM\Index(name="plate_number_idx", columns={"plate_number"})})
*/
class CustomerVehicle
{
// unique id
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
// user-defined name for vehicle
/**
* @ORM\Column(type="string", length=80, nullable=true)
*/
protected $name;
// link to customer
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="vehicles")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $customer;
// vehicle
/**
* @ORM\ManyToOne(targetEntity="Vehicle", inversedBy="cust_vehicles")
* @ORM\JoinColumn(name="vehicle_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
protected $vehicle;
// plate number
/**
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank()
*/
protected $plate_number;
// model year
/**
* @ORM\Column(type="smallint")
*/
protected $model_year;
// color of customer's vehicle
/**
* @ORM\Column(type="string", length=80)
*/
protected $color;
// vehicle status (new / second-hand)
/**
* @ORM\Column(type="string", length=15)
*/
protected $status_condition;
// fuel type - diesel, gas
/**
* @ORM\Column(type="string", length=15)
*/
protected $fuel_type;
// warranty code
// TODO: figure out how to check expiration
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
protected $warranty_code;
// date that battery warranty expires
/**
* @ORM\Column(type="date", nullable=true)
*/
protected $warranty_expiration;
// link to current battery
/**
* @ORM\ManyToOne(targetEntity="Battery", inversedBy="cust_vehicles")
* @ORM\JoinColumn(name="battery_id", referencedColumnName="id", nullable=true)
*/
protected $curr_battery;
// job orders that involve customer vehicle
/**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="cus_vehicle")
*/
protected $job_orders;
// vehicle using motolite battery?
/**
* @ORM\Column(type="boolean")
*/
protected $flag_motolite_battery;
// is vehicle still active?
/**
* @ORM\Column(type="boolean")
*/
protected $flag_active;
// link to insurance
/**
* @ORM\OneToMany(targetEntity="InsuranceApplication", mappedBy="customer_vehicle")
*/
protected $insurance_applications;
// link to subscription
/**
* @ORM\OneToMany(targetEntity="Subscription", mappedBy="customer_vehicle")
*/
protected $subscriptions;
public function __construct()
{
$this->flag_active = true;
$this->job_orders = new ArrayCollection();
}
public function getID()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setVehicle(Vehicle $vehicle)
{
$this->vehicle = $vehicle;
return $this;
}
public function getVehicle()
{
return $this->vehicle;
}
public function setPlateNumber($plate_number)
{
// make it upper case
$plate_number = trim(strtoupper($plate_number));
// remove spaces
$plate_number = str_replace(' ', '', $plate_number);
// upper case
$plate_number = strtoupper($plate_number);
$this->plate_number = $plate_number;
return $this;
}
public function getPlateNumber()
{
return strtoupper($this->plate_number);
}
public function setModelYear($model_year)
{
$this->model_year = $model_year;
return $this;
}
public function getModelYear()
{
return $this->model_year;
}
public function setColor($color)
{
$this->color = $color;
return $this;
}
public function getColor()
{
return $this->color;
}
public function setStatusCondition($status_condition)
{
$this->status_condition = $status_condition;
return $this;
}
public function getStatusCondition()
{
return $this->status_condition;
}
public function setFuelType($fuel_type)
{
$this->fuel_type = $fuel_type;
return $this;
}
public function getFuelType()
{
return $this->fuel_type;
}
public function setWarrantyCode($warranty_code)
{
$this->warranty_code = $warranty_code;
return $this;
}
public function getWarrantyCode()
{
return $this->warranty_code;
}
public function setWarrantyExpiration(DateTime $warranty_expiration = null)
{
$this->warranty_expiration = $warranty_expiration;
return $this;
}
public function getWarrantyExpiration()
{
return $this->warranty_expiration;
}
public function setCurrentBattery(Battery $curr_battery)
{
$this->curr_battery = $curr_battery;
return $this;
}
public function getCurrentBattery()
{
return $this->curr_battery;
}
public function getJobOrders()
{
return $this->job_orders;
}
public function setHasMotoliteBattery($flag_motolite_battery = true)
{
$this->flag_motolite_battery = $flag_motolite_battery;
return $this;
}
public function hasMotoliteBattery()
{
return $this->flag_motolite_battery;
}
public function setActive($flag_active = true)
{
$this->flag_active = $flag_active;
return $this;
}
public function isActive()
{
return $this->flag_active;
}
public function getInsuranceApplications()
{
return $this->insurance_applications;
}
public function getLatestInsuranceApplication()
{
$criteria = Criteria::create()
->where(Criteria::expr()->notIn('status', [InsuranceApplicationStatus::CANCELLED]))
->orderBy(['date_submit' => Criteria::DESC])
->setMaxResults(1);
$result = $this->insurance_applications->matching($criteria);
return !empty($result) ? $result[0] : null;
}
public function getSubscriptions()
{
return $this->subscriptions;
}
public function getLatestSubscription()
{
// we get the latest subscription that actually started
$criteria = Criteria::create()
->where(Criteria::expr()->notIn('status', [
SubscriptionStatus::CANCELLED,
SubscriptionStatus::PENDING,
]))
->where(Criteria::expr()->neq('date_start', null))
->orderBy(['date_create' => Criteria::DESC])
->setMaxResults(1);
$result = $this->subscriptions->matching($criteria);
return !empty($result) ? $result[0] : null;
}
}