<?php
namespace App\Entity\Management\Subscription;
use App\Model\TimestampableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Management\Subscription\Offer;
/**
* Discount
*
* @ORM\Table(name="Discount")
* @ORM\Entity(repositoryClass="App\Repository\Management\DiscountRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Discount
{
use TimestampableTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255,unique=true)
*
*/
private $title;
/**
* @var string
*
* @ORM\Column(type="string", length=255,unique=true)
*
*/
private $codePromo;
/**
* @var integer
*
* @ORM\Column(name="percent", type="decimal", scale=2 ,nullable=true)
*/
private $percent;
/**
* @var string
* @ORM\Column(name="duration",type="string",nullable=true)
*/
private $duration;
/**
* @ORM\Column(name="description",type="text",nullable=true)
*/
private $description;
/**
* @ORM\Column(name="amount",type="integer",nullable=true)
*/
private $amount;
/**
* @ORM\Column(name="stripe_id",type="string",length=255,nullable=true)
*
*/
private $stripeId;
/**
* @var string
* @ORM\Column(name="duration_in_months",type="integer",nullable=true)
*/
private $durationInMonths;
/**
* @var \DateTime
* @ORM\Column(name="start_valid",type="datetime", nullable=true)
*/
private $startValid;
/**
* @var \DateTime
* @ORM\Column(name="end_valid",type="datetime", nullable=true)
*/
private $endValid;
/**
* @ORM\Column(name="online",type="boolean",nullable=true)
*/
private $online;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $isDelete;
/**
* @ORM\ManyToMany(targetEntity=Offer::class)
*/
private $allowOffer;
/**
* @ORM\ManyToOne(targetEntity=Discount::class)
*/
private $moreChildReduce;
/***************** fin **********************/
public function __construct()
{
$this->allowOffer = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Discount
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set percent
*
* @param integer $percent
* @return Discount
*/
public function setPercent($percent)
{
$this->percent = $percent;
return $this;
}
/**
* Get percent
*
* @return integer
*/
public function getPercent()
{
return $this->percent;
}
/**
* @return string
*/
public function getDuration()
{
return $this->duration;
}
/**
* @param string $duration
*/
public function setDuration($duration)
{
$this->duration = $duration;
}
/**
* @return mixed
*/
public function getOffers()
{
return $this->offers;
}
/**
* @param mixed $offers
*/
public function addOffers($offers)
{
$this->offers[] = $offers;
}
/**
* @param mixed $offers
*/
public function setOffers($offers)
{
$this->offers = $offers;
}
public function __toString()
{
return $this->title;
}
/**
* @return string
*/
public function getDurationInMonths()
{
return $this->durationInMonths;
}
/**
* @param string $durationInMonths
*/
public function setDurationInMonths($durationInMonths)
{
$this->durationInMonths = $durationInMonths;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param mixed $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}
/**
* @return mixed
*/
public function getStripeId()
{
return $this->stripeId;
}
/**
* @param mixed $stripeId
*/
public function setStripeId($stripeId)
{
$this->stripeId = $stripeId;
}
/**
* @return date
*/
public function getStartValid()
{
return $this->startValid;
}
/**
* @param date $startValid
*/
public function setStartValid($startValid)
{
$this->startValid = $startValid;
}
/**
* @return date
*/
public function getEndValid()
{
return $this->endValid;
}
/**
* @param date $endValid
*/
public function setEndValid($endValid)
{
$this->endValid = $endValid;
}
/**
* @return mixed
*/
public function getDiscountHistory()
{
return $this->discountHistory;
}
/**
* @param mixed $discountHistory
*/
public function setDiscountHistory($discountHistory)
{
$this->discountHistory = $discountHistory;
}
/**
* @return array
*/
public function getChoiceOffer()
{
return $this->choiceOffer;
}
/**
* @param array $choiceOffer
*/
public function setChoiceOffer( $choiceOffer)
{
$this->choiceOffer = $choiceOffer;
}
/**
* @return string
*/
public function getCodePromo(): ?string
{
return $this->codePromo;
}
/**
* @param string $codePromo
*/
public function setCodePromo(string $codePromo): void
{
$this->codePromo = $codePromo;
}
/**
* @return mixed
*/
public function getOnline()
{
return $this->online;
}
/**
* @param mixed $online
*/
public function setOnline($online): void
{
$this->online = $online;
}
/**
* @return mixed
*/
public function getIsDelete()
{
return $this->isDelete;
}
/**
* @param mixed $isDelete
*/
public function setIsDelete($isDelete): void
{
$this->isDelete = $isDelete;
}
public function actif(){
if($this->online){
if(!is_null($this->startValid)){
$now = new \DateTime();
return $this->startValid<=$now && $now<=$this->endValid;
}
return true;
}
return false;
}
public function setAllowOffer(ArrayCollection $packs): void
{
$this->allowOffer = $packs;
}
public function addAllowOffer(Offer $offer): void
{
if(!$this->allowOffer->contains($offer))
$this->allowOffer[] = $offer;
}
public function getAllowOffer(){
return $this->allowOffer;
}
/**
* @return mixed
*/
public function getMoreChildReduce()
{
return $this->moreChildReduce;
}
/**
* @param mixed $moreChildReduce
*/
public function setMoreChildReduce($moreChildReduce): void
{
$this->moreChildReduce = $moreChildReduce;
}
}