Add subscription entity #799
This commit is contained in:
parent
62f11c9ef5
commit
aa85198b7a
3 changed files with 240 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
194
src/Entity/Subscription.php
Normal file
194
src/Entity/Subscription.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="subscription")
|
||||
*/
|
||||
class Subscription
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// link to customer
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Customer")
|
||||
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="CustomerVehicle", inversedBy="subscriptions")
|
||||
* @ORM\JoinColumn(name="customer_vehicle_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $customer_vehicle;
|
||||
|
||||
// date subscription was created
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
// date subscription starts
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $date_start;
|
||||
|
||||
// date subscription ends
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $date_end;
|
||||
|
||||
// date subscription was cancelled
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
protected $date_cancel;
|
||||
|
||||
// external api id (paymongo)
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
*/
|
||||
protected $ext_api_id;
|
||||
|
||||
// status of the subscription
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
// other data related to the transaction
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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
|
||||
}
|
||||
}
|
||||
20
src/Ramcar/SubscriptionStatus.php
Normal file
20
src/Ramcar/SubscriptionStatus.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
class SubscriptionStatus extends NameValue
|
||||
{
|
||||
const PENDING = 'pending';
|
||||
const ACTIVE = 'active';
|
||||
const ENDED = 'ended';
|
||||
const CANCELLED = 'cancelled';
|
||||
const REPOSSESSED = 'reposessed';
|
||||
|
||||
const COLLECTION = [
|
||||
'pending' => 'Pending',
|
||||
'active' => 'Active',
|
||||
'ended' => 'Ended',
|
||||
'cancelled' => 'Cancelled',
|
||||
'repossessed' => 'Reposessed',
|
||||
];
|
||||
}
|
||||
Loading…
Reference in a new issue