<?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
{
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column (type="string", length=30, unique=true)
*/
private $code;
/**
* @var bool
*
* @ORM\Column (type="boolean")
*/
private $active;
/**
* @var Customer|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\System\Customer", inversedBy="customerApi")
*
* @ORM\JoinColumn(name="customer", referencedColumnName="id_customer")
*/
private $customer;
/**
* @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="decimal", precision=20, scale=6, 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;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->codeDiscountRules = new ArrayCollection();
}
/**
* @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;
}
}