<?php
namespace App\Entity\System;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Class CodeDiscount
*
* @ORM\Table(name="code_discount")
*
* @ORM\Entity(repositoryClass="App\Repository\System\CodeDiscountRepository")
*/
class CodeDiscount
{
public const FREE_SUBSCRIPTION_CODE_PREFIX = 'FREE_SUBSCRIPTION';
public const FREE_CONNECTOR_CODE_PREFIX = 'FREE_CONNECTOR';
public const FREE_MIGRATION_CODE = 'MIGRATION';
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column (type="string", length=30, unique=true)
*/
private ?string $code = null;
/**
* @ORM\Column (type="boolean")
*/
private bool $active = false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\System\Customer")
*
* @ORM\JoinColumn(name="customer", referencedColumnName="id_customer")
*/
private ?Customer $customer = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\System\Employee")
*
* @ORM\JoinColumn(name="employee", referencedColumnName="id_employee", nullable=false)
*/
private Employee $employee;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $redeemLimit = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $redeemLimitByCustomer = null;
/**
* @var float
*
* @ORM\Column(type="float", options={"default" : 0.000000})
*/
private $discount;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $dateExpiration;
/**
* @var \DateTime|null
*
* @ORM\Column(type="datetime")
*/
private $dateStarting;
/**
* @var Order[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\System\Order", mappedBy="idVoucher")
*/
private $orders;
/**
* @var ArrayCollection<int, CodeDiscountRule>|CodeDiscountRule[]
*
* @ORM\ManyToMany(targetEntity="CodeDiscountRule", inversedBy="codeDiscounts")
*/
private $codeDiscountRules;
/**
* @ORM\Column (type="string", nullable=true)
*/
private ?string $comments;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
*/
private $dateAdd;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime")
*/
private $dateUpd;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->codeDiscountRules = new ArrayCollection();
$this->dateAdd = new \DateTime();
$this->dateUpd = new \DateTime();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getCode(): string
{
return $this->code;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
/**
* @return Customer|null
*/
public function getCustomer(): ?Customer
{
return $this->customer;
}
/**
* @return float
*/
public function getDiscount(): float
{
return $this->discount;
}
/**
* @return \DateTime|null
*/
public function getDateExpiration(): ?\DateTime
{
return $this->dateExpiration;
}
/**
* @return \DateTime
*/
public function getDateStarting(): \DateTime
{
return $this->dateStarting;
}
/**
* @return Order[]|ArrayCollection
*/
public function getOrders()
{
return $this->orders;
}
/**
* @param Order[]|ArrayCollection $orders
*/
public function setOrders($orders): self
{
$this->orders = $orders;
return $this;
}
public function setCode(string $code): CodeDiscount
{
$this->code = $code;
return $this;
}
public function setActive(bool $active): CodeDiscount
{
$this->active = $active;
return $this;
}
public function setCustomer(?Customer $customer): CodeDiscount
{
$this->customer = $customer;
return $this;
}
public function setDiscount(float $discount): CodeDiscount
{
$this->discount = $discount;
return $this;
}
public function setDateExpiration(?\DateTime $dateExpiration): CodeDiscount
{
$this->dateExpiration = $dateExpiration;
return $this;
}
public function setDateStarting(?\DateTime $dateStarting): CodeDiscount
{
$this->dateStarting = $dateStarting;
return $this;
}
/**
* @return CodeDiscountRule[]|ArrayCollection<int, CodeDiscountRule>
*/
public function getCodeDiscountRules()
{
return $this->codeDiscountRules;
}
public function hasCodeDiscountRule(int $codeDiscountRuleId): bool
{
foreach ($this->codeDiscountRules as $codeDiscountRule) {
if ($codeDiscountRule->getId() === $codeDiscountRuleId) {
return true;
}
}
return false;
}
public function addCodeDiscountRule(CodeDiscountRule $codeDiscountRule): CodeDiscount
{
if (!$this->codeDiscountRules->contains($codeDiscountRule)) {
$this->codeDiscountRules[] = $codeDiscountRule;
}
return $this;
}
/**
* @param CodeDiscountRule[]|ArrayCollection<int, CodeDiscountRule> $codeDiscountRules
*/
public function setCodeDiscountRules($codeDiscountRules): CodeDiscount
{
$this->codeDiscountRules = $codeDiscountRules;
return $this;
}
public function getRedeemLimit(): ?int
{
return $this->redeemLimit;
}
public function setRedeemLimit(?int $redeemLimit): CodeDiscount
{
$this->redeemLimit = $redeemLimit;
return $this;
}
public function getRedeemLimitByCustomer(): ?int
{
return $this->redeemLimitByCustomer;
}
public function setRedeemLimitByCustomer(?int $redeemLimitByCustomer): CodeDiscount
{
$this->redeemLimitByCustomer = $redeemLimitByCustomer;
return $this;
}
public function getEmployee(): Employee
{
return $this->employee;
}
public function setEmployee(Employee $employee): CodeDiscount
{
$this->employee = $employee;
return $this;
}
public function getComments(): ?string
{
return $this->comments;
}
public function setComments(?string $comments): CodeDiscount
{
$this->comments = $comments;
return $this;
}
public function getDateAdd(): \DateTime
{
return $this->dateAdd;
}
public function setDateAdd(\DateTime $dateAdd): CodeDiscount
{
$this->dateAdd = $dateAdd;
return $this;
}
public function getDateUpd(): \DateTime
{
return $this->dateUpd;
}
public function setDateUpd(\DateTime $dateUpd): CodeDiscount
{
$this->dateUpd = $dateUpd;
return $this;
}
}