diff --git a/src/Entity/CustomerVehicle.php b/src/Entity/CustomerVehicle.php index f36c1de5..c39e46c0 100644 --- a/src/Entity/CustomerVehicle.php +++ b/src/Entity/CustomerVehicle.php @@ -3,6 +3,7 @@ namespace App\Entity; use App\Ramcar\InsuranceApplicationStatus; +use App\Ramcar\SubscriptionStatus; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; @@ -122,6 +123,12 @@ class CustomerVehicle */ protected $insurance_applications; + // link to subscription + /** + * @ORM\OneToMany(targetEntity="Subscription", mappedBy="customer_vehicle") + */ + protected $subscriptions; + public function __construct() { $this->flag_active = true; @@ -307,9 +314,25 @@ class CustomerVehicle return !empty($result) ? $result[0] : null; } - public function getLatestActiveSubscription() + public function getSubscriptions() { - // TODO: get latest active sub using relationship to be built - return null; + 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; } } diff --git a/src/Entity/Subscription.php b/src/Entity/Subscription.php new file mode 100644 index 00000000..1db78332 --- /dev/null +++ b/src/Entity/Subscription.php @@ -0,0 +1,194 @@ +date_create = new DateTime(); + $this->date_start = null; + $this->date_end = null; + $this->date_cancel = null; + $this->metadata = []; + } + + public function getID() + { + return $this->id; + } + + public function setCustomer(Customer $cust = null) + { + $this->customer = $cust; + return $this; + } + + public function getCustomer() + { + return $this->customer; + } + + public function setCustomerVehicle(CustomerVehicle $customer_vehicle) + { + $this->customer_vehicle = $customer_vehicle; + return $this; + } + + public function getCustomerVehicle() + { + return $this->customer_vehicle; + } + + public function setDateCreate(DateTime $date) + { + $this->date_create = $date; + return $this; + } + + public function getDateCreate() + { + return $this->date_create; + } + + public function setDateStart(DateTime $date) + { + $this->date_start = $date; + return $this; + } + + public function getDateStart() + { + return $this->date_start; + } + + public function setDateEnd(DateTime $date) + { + $this->date_end = $date; + return $this; + } + + public function getDateEnd() + { + return $this->date_end; + } + + public function setDateCancel(DateTime $date) + { + $this->date_cancel = $date; + return $this; + } + + public function getDateCancel() + { + return $this->date_cancel; + } + + public function setStatus($status) + { + return $this->status = $status; + } + + public function getStatus() + { + return $this->status; + } + + public function setExtApiId($ext_api_id) + { + return $this->ext_api_id = $ext_api_id; + } + + public function getExtApiId() + { + return $this->ext_api_id; + } + + public function setMetadata($metadata) + { + return $this->metadata = $metadata; + } + + public function getMetadata() + { + return $this->metadata; + } + + public function getGatewayTransactions() + { + // TODO: get gateway transactions here via type and metadata + } +} diff --git a/src/Ramcar/SubscriptionStatus.php b/src/Ramcar/SubscriptionStatus.php new file mode 100644 index 00000000..9c957497 --- /dev/null +++ b/src/Ramcar/SubscriptionStatus.php @@ -0,0 +1,20 @@ + 'Pending', + 'active' => 'Active', + 'ended' => 'Ended', + 'cancelled' => 'Cancelled', + 'repossessed' => 'Reposessed', + ]; +}