<?php
namespace App\Entity\Gos;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperclass()
*/
class BaseCoupon
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var bool
*
* @ORM\Column(name="isActive", type="boolean")
*/
protected $isActive = true;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isGross;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isUserAssigned;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\User", inversedBy="assignedCoupons")
*/
protected $user;
/**
* @ORM\Column(type="float", precision=10, scale=2, nullable=true)
*/
protected $discount;
/**
* @ORM\Column(type="integer")
*/
protected $maximumQuantityUse;
/**
* @ORM\Column(type="integer")
*/
protected $usedCodes = 0;
/**
* @ORM\Column(type="datetime")
*/
protected $dateFrom;
/**
* @ORM\Column(type="datetime")
*/
protected $dateTo;
/**
* @ORM\Column(type="string", length=8, nullable=true)
*/
protected $actionNumber;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $fromSource;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $campaign;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $campaignChannel;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $comment;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2, nullable=true)
*/
protected $gratisPriceNet;
/**
* @var float
*
* @ORM\Column(type="float", precision=18, scale=2, nullable=true)
*/
protected $gratisPriceGross;
/**
* @ORM\OneToMany(targetEntity="ProductAssociation", mappedBy="couponDefault")
*/
protected $productAssociation;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Cart", mappedBy="coupon")
*/
protected $cart;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\Cart", mappedBy="coupons")
*/
protected $carts;
/**
* @ORM\OneToMany(targetEntity="ProductCart", mappedBy="coupon")
*/
protected $productCart;
/**
* @ORM\ManyToMany(targetEntity="ProductCart", inversedBy="coupons")
*/
protected $productCarts;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\CouponPending", mappedBy="coupon")
*/
protected $couponPending;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\CouponType", inversedBy="coupon")
*/
protected $couponType;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\CouponPackProduct", mappedBy="coupon", orphanRemoval=true, cascade={"persist"})
*/
protected $couponPackProducts;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
protected $isBundle = false;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
protected $isWholeBundleRequired = false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Alert", mappedBy="coupon")
*/
protected $alerts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ClientType", inversedBy="coupons")
*/
protected $clientType;
/**
* @ORM\OneToOne(targetEntity="Gift", mappedBy="giftDiscountCode")
*/
protected $gift;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $generatedWithCoupon;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $nameGeneratedCoupon;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":0})
*/
protected $isCascade;
/**
* @ORM\OneToOne(targetEntity="CouponCascadeSettings", mappedBy="coupon", cascade={"persist"})
*/
protected $cascadeSettings;
/**
* @ORM\Column(type="datetime")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default":0})
*/
protected $freeShippingCost = 0;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
protected $isAutoGenerated = false;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
private $isApplicationCode;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\ApplicationCoupon", inversedBy="coupon", cascade={"persist"})
* @ORM\JoinColumn()
*/
private $applicationCoupon;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $forTele;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $createdBy;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
protected $isPostageCostOnePLN = false;
/**
* @var string
*
* @ORM\Column(type="text", nullable=true)
*/
protected $customPromo1;
/**
* @var string
*
* @ORM\Column(type="text", nullable=true)
*/
protected $customPromo2;
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return (string)$this->code;
}
public function getObjectVars()
{
return get_object_vars($this);
}
public function isInProductVariantList(Array $productVariantList)
{
foreach($this->getProductVariant() as $productVariant)
{
if ( \in_array($productVariant->getProductVariantNoComplete(), $productVariantList))
{
return true;
}
}
return false;
}
public function isValid(): bool
{
$dateNow = (new \DateTime())->format('Y-m-d H:i:s');
if ($this->getDateFrom()->format('Y-m-d H:i:s') <= $dateNow
&& $this->getDateTo()->format('Y-m-d H:i:s') >= $dateNow
&& $this->isActive)
{
return true;
}
return false;
}
/**
* Constructor
*/
public function __construct()
{
$this->cart = new ArrayCollection();
$this->couponPending = new ArrayCollection();
$this->couponPackProducts = new ArrayCollection();
$this->alerts = new ArrayCollection();
$this->productAssociation = new ArrayCollection();
$this->productCart = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->productCarts = new ArrayCollection();
$this->dateFrom = new \DateTime();
$this->dateTo = new \DateTime("+ 1 month");
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set isActive
*
* @param boolean $isActive
*
* @return Coupon
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set code
*
* @param string $code
*
* @return Coupon
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* Set discount
*
* @param float $discount
*
* @return Coupon
*/
public function setDiscount($discount)
{
$this->discount = $discount;
return $this;
}
/**
* Get discount
*
* @return float
*/
public function getDiscount()
{
return $this->discount;
}
/**
* Set maximumQuantityUse
*
* @param integer $maximumQuantityUse
*
* @return Coupon
*/
public function setMaximumQuantityUse($maximumQuantityUse)
{
$this->maximumQuantityUse = $maximumQuantityUse;
return $this;
}
/**
* Get maximumQuantityUse
*
* @return integer
*/
public function getMaximumQuantityUse()
{
return $this->maximumQuantityUse;
}
/**
* Set usedCodes
*
* @param integer $usedCodes
*
* @return Coupon
*/
public function setUsedCodes($usedCodes)
{
$this->usedCodes = $usedCodes;
return $this;
}
/**
* Get usedCodes
*
* @return integer
*/
public function getUsedCodes()
{
return $this->usedCodes;
}
/**
* Set dateFrom
*
* @param \DateTime $dateFrom
*
* @return Coupon
*/
public function setDateFrom($dateFrom)
{
$this->dateFrom = $dateFrom;
return $this;
}
/**
* Get dateFrom
*
* @return \DateTime
*/
public function getDateFrom()
{
return $this->dateFrom;
}
/**
* Set dateTo
*
* @param \DateTime $dateTo
*
* @return Coupon
*/
public function setDateTo($dateTo)
{
$this->dateTo = $dateTo;
return $this;
}
/**
* Get dateTo
*
* @return \DateTime
*/
public function getDateTo()
{
return $this->dateTo;
}
/**
* Set description
*
* @param string $description
*
* @return Coupon
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return Coupon
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return Coupon
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Add cart
*
* @param \App\Entity\Gos\Cart $cart
*
* @return Coupon
*/
public function addCart(\App\Entity\Gos\Cart $cart)
{
$this->cart[] = $cart;
$this->addCarts($cart);
return $this;
}
/**
* Add carts
*
* @param \App\Entity\Gos\Cart $cart
*
* @return self
*/
public function addCarts(\App\Entity\Gos\Cart $cart)
{
if (!$this->carts->contains($cart))
{
$this->carts->add($cart);
}
return $this;
}
/**
* Remove cart
*
* @param \App\Entity\Gos\Cart $cart
*/
public function removeCart(\App\Entity\Gos\Cart $cart)
{
$this->cart->removeElement($cart);
$this->carts->removeElement($cart);
}
/**
* Remove carts
*
* @param \App\Entity\Gos\Cart $cart
*
* @return self
*/
public function removeCarts(\App\Entity\Gos\Cart $cart)
{
$this->carts->removeElement($cart);
$this->cart->removeElement($cart);
return $this;
}
/**
* Get cart
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCart()
{
return $this->cart;
}
/**
* Get carts
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCarts()
{
return $this->carts;
}
/**
* Add couponPending
*
* @param \App\Entity\Gos\CouponPending $couponPending
*
* @return Coupon
*/
public function addCouponPending(\App\Entity\Gos\CouponPending $couponPending)
{
$this->couponPending[] = $couponPending;
return $this;
}
/**
* Remove couponPending
*
* @param \App\Entity\Gos\CouponPending $couponPending
*/
public function removeCouponPending(\App\Entity\Gos\CouponPending $couponPending)
{
$this->couponPending->removeElement($couponPending);
}
/**
* Get couponPending
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCouponPending()
{
return $this->couponPending;
}
/**
* Set couponType
*
* @param \App\Entity\Gos\CouponType $couponType
*
* @return Coupon
*/
public function setCouponType(\App\Entity\Gos\CouponType $couponType = null)
{
$this->couponType = $couponType;
return $this;
}
/**
* Get couponType
*
* @return \App\Entity\Gos\CouponType
*/
public function getCouponType()
{
return $this->couponType;
}
/**
* Set actionNumber
*
* @param string $actionNumber
*
* @return Coupon
*/
public function setActionNumber($actionNumber)
{
$this->actionNumber = $actionNumber;
return $this;
}
/**
* Get actionNumber
*
* @return string
*/
public function getActionNumber()
{
return $this->actionNumber;
}
/**
* Set fromSource
*
* @param string $fromSource
*
* @return Coupon
*/
public function setFromSource($fromSource)
{
$this->fromSource = $fromSource;
return $this;
}
/**
* Get fromSource
*
* @return string
*/
public function getFromSource()
{
return $this->fromSource;
}
/**
* Set campaign
*
* @param string $campaign
*
* @return Coupon
*/
public function setCampaign($campaign)
{
$this->campaign = $campaign;
return $this;
}
/**
* Get campaign
*
* @return string
*/
public function getCampaign()
{
return $this->campaign;
}
/**
* Set campaignChannel
*
* @param string $campaignChannel
*
* @return Coupon
*/
public function setCampaignChannel($campaignChannel)
{
$this->campaignChannel = $campaignChannel;
return $this;
}
/**
* Get campaignChannel
*
* @return string
*/
public function getCampaignChannel()
{
return $this->campaignChannel;
}
/**
* Set isGross
*
* @param boolean $isGross
*
* @return Coupon
*/
public function setIsGross($isGross)
{
$this->isGross = $isGross;
return $this;
}
/**
* Get isGross
*
* @return boolean
*/
public function getIsGross()
{
return $this->isGross;
}
/**
* Set isUserAssigned
*
* @param boolean $isUsedAssigned
*
* @return Coupon
*/
public function setIsUserAssigned($isUsedAssigned)
{
$this->isUserAssigned = $isUsedAssigned;
return $this;
}
/**
* Get isUserAssigned
*
* @return boolean
*/
public function getIsUserAssigned()
{
return $this->isUserAssigned;
}
/**
* Set isBundle
*
* @param boolean $isBundle
* @return Coupon
*/
public function setIsBundle($isBundle)
{
$this->isBundle = $isBundle;
return $this;
}
/**
* Get isBundle
*
* @return boolean
*/
public function getIsBundle()
{
return $this->isBundle;
}
/**
* Set isWholeBundleRequired
*
* @param boolean $isWholeBundleRequired
* @return Coupon
*/
public function setIsWholeBundleRequired($isWholeBundleRequired)
{
$this->isWholeBundleRequired = $isWholeBundleRequired;
return $this;
}
/**
* Get isWholeBundleRequired
*
* @return boolean
*/
public function getIsWholeBundleRequired()
{
return $this->isWholeBundleRequired;
}
/**
* Set couponPackProducts
*
* @param \Doctrine\Common\Collections\Collection $couponPackProducts
* @return Coupon
*/
public function setCouponPackProducts($couponPackProducts)
{
$this->couponPackProducts = $couponPackProducts;
return $this;
}
/**
* Add couponPackProduct
*
* @param CouponPackProduct $couponPackProduct
* @return Coupon
*/
public function addCouponPackProduct(\App\Entity\Gos\CouponPackProduct $couponPackProduct)
{
$couponPackProduct->setCoupon($this);
$this->couponPackProducts[] = $couponPackProduct;
return $this;
}
/**
* Remove couponPackProduct
*
* @param CouponPackProduct $couponPackProduct
* @return Coupon
*/
public function removeCouponPackProduct(\App\Entity\Gos\CouponPackProduct $couponPackProduct)
{
$this->couponPackProducts->removeElement($couponPackProduct);
return $this;
}
/**
* Get couponPackProducts
*
* @return ArrayCollection
*/
public function getCouponPackProducts()
{
return $this->couponPackProducts;
}
/**
* Set gratisPriceNet
*
* @param float $gratisPriceNet
*
* @return Coupon
*/
public function setGratisPriceNet($gratisPriceNet)
{
$this->gratisPriceNet = $gratisPriceNet;
return $this;
}
/**
* Get gratisPriceNet
*
* @return float
*/
public function getGratisPriceNet()
{
return $this->gratisPriceNet;
}
/**
* Set gratisPriceGross
*
* @param float $gratisPriceGross
*
* @return Coupon
*/
public function setGratisPriceGross($gratisPriceGross)
{
$this->gratisPriceGross = $gratisPriceGross;
return $this;
}
/**
* Get gratisPriceGross
*
* @return float
*/
public function getGratisPriceGross()
{
return $this->gratisPriceGross;
}
/**
* Set isAutoGenerated
*
* @param boolean $isAutoGenerated
*
* @return Coupon
*/
public function setIsAutoGenerated($isAutoGenerated)
{
$this->isAutoGenerated = $isAutoGenerated;
return $this;
}
/**
* Get isAutoGenerated
*
* @return boolean
*/
public function getIsAutoGenerated()
{
return $this->isAutoGenerated;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Alert[]
*/
public function getAlerts(): Collection
{
return $this->alerts;
}
public function addAlert(Alert $alert): self
{
if (!$this->alerts->contains($alert)) {
$this->alerts[] = $alert;
$alert->setCoupon($this);
}
return $this;
}
public function removeAlert(Alert $alert): self
{
if ($this->alerts->contains($alert)) {
$this->alerts->removeElement($alert);
// set the owning side to null (unless already changed)
if ($alert->getCoupon() === $this) {
$alert->setCoupon(null);
}
}
return $this;
}
public function getUsesLeft(): int
{
if ($this->maximumQuantityUse == 0)
{
return 999;
}
return $this->maximumQuantityUse - abs($this->usedCodes);
}
public function getStatus(): int
{
if ($this->dateTo < new \DateTime())
return 2;
elseif ($this->dateFrom > new \DateTime())
return 3;
else
return 1;
}
/**
* @return Collection|ProductAssociation[]
*/
public function getProductAssociation(): Collection
{
return $this->productAssociation;
}
public function addProductAssociation(ProductAssociation $productAssociation): self
{
if (!$this->productAssociation->contains($productAssociation)) {
$this->productAssociation[] = $productAssociation;
$productAssociation->setCouponDefault($this);
}
return $this;
}
public function removeProductAssociation(ProductAssociation $productAssociation): self
{
if ($this->productAssociation->contains($productAssociation)) {
$this->productAssociation->removeElement($productAssociation);
// set the owning side to null (unless already changed)
if ($productAssociation->getCouponDefault() === $this) {
$productAssociation->setCouponDefault(null);
}
}
return $this;
}
public function getClientType(): ?ClientType
{
return $this->clientType;
}
public function setClientType(?ClientType $clientType): self
{
$this->clientType = $clientType;
return $this;
}
public function getGift(): ?Gift
{
return $this->gift;
}
public function setGift(?Gift $gift): self
{
$this->gift = $gift;
// set (or unset) the owning side of the relation if necessary
$newGiftDiscountCode = $gift === null ? null : $this;
if ($newGiftDiscountCode !== $gift->getGiftDiscountCode()) {
$gift->setGiftDiscountCode($newGiftDiscountCode);
}
return $this;
}
/**
* Set generatedWithCoupon
*
* @param boolean $generatedWithCoupon
*
* @return Coupon
*/
public function setGeneratedWithCoupon($generatedWithCoupon)
{
$this->generatedWithCoupon = $generatedWithCoupon;
return $this;
}
/**
* Get generatedWithCoupon
*
* @return boolean
*/
public function getGeneratedWithCoupon()
{
return $this->generatedWithCoupon;
}
/**
* Set nameGeneratedCoupon
*
* @param string nameGeneratedCoupon
*
* @return Coupon
*/
public function setNameGeneratedCoupon($nameGeneratedCoupon)
{
$this->nameGeneratedCoupon = $nameGeneratedCoupon;
return $this;
}
/**
* Get nameGeneratedCoupon
*
* @return string
*/
public function getNameGeneratedCoupon()
{
return $this->nameGeneratedCoupon;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
/**
* @return Collection|ProductCart[]
*/
public function getProductCart(): Collection
{
return $this->productCart;
}
/**
* @return Collection|ProductCart[]
*/
public function getProductCarts(): Collection
{
return $this->productCarts;
}
public function addProductCart(ProductCart $productCart): self
{
if (!$this->productCart->contains($productCart)) {
$this->productCarts[] = $productCart;
}
if (!$this->productCarts->contains($productCart)) {
$this->productCarts->add($productCart);
}
return $this;
}
public function addProductCarts(ProductCart $productCart): self
{
if (!$this->productCarts->contains($productCart)) {
$this->productCarts->add($productCart);
}
return $this;
}
public function removeProductCart(ProductCart $productCart): self
{
if ($this->productCart->contains($productCart)) {
$this->productCart->removeElement($productCart);
}
if ($this->productCarts->contains($productCart)) {
$this->productCarts->removeElement($productCart);
}
return $this;
}
public function removeProductCarts(ProductCart $productCart): self
{
if ($this->productCarts->contains($productCart)) {
$this->productCarts->removeElement($productCart);
}
return $this;
}
public function getIsCascade(): ?bool
{
return $this->isCascade;
}
public function setIsCascade(?bool $isCascade): self
{
$this->isCascade = $isCascade;
return $this;
}
public function getCascadeSettings(): ?CouponCascadeSettings
{
return $this->cascadeSettings;
}
public function setCascadeSettings(?CouponCascadeSettings $cascadeSettings): self
{
$this->cascadeSettings = $cascadeSettings;
// set (or unset) the owning side of the relation if necessary
$newCoupon = $cascadeSettings === null ? null : $this;
if ($newCoupon !== $cascadeSettings->getCoupon()) {
$cascadeSettings->setCoupon($newCoupon);
}
return $this;
}
public function getFreeShippingCost() :bool
{
if ($this->freeShippingCost == null)
{
$this->freeShippingCost = 0;
}
return $this->freeShippingCost;
}
public function setFreeShippingCost(?bool $freeShippingCost) :self
{
$this->freeShippingCost = $freeShippingCost;
return $this;
}
public function getisApplicationCode(): ?bool
{
return $this->isApplicationCode;
}
public function setIsApplicationCode(bool $isApplicationCode): self
{
$this->isApplicationCode = $isApplicationCode;
return $this;
}
public function getApplicationCoupon(): ?ApplicationCoupon
{
return $this->applicationCoupon;
}
public function setApplicationCoupon(?ApplicationCoupon $applicationCoupon): self
{
$this->applicationCoupon = $applicationCoupon;
return $this;
}
public function getForTele(): ?bool
{
return $this->forTele;
}
public function setForTele(?bool $forTele): self
{
$this->forTele = $forTele;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getIsPostageCostOnePLN(): ?bool
{
return $this->isPostageCostOnePLN;
}
public function setIsPostageCostOnePLN(bool $isPostageCostOnePLN): self
{
$this->isPostageCostOnePLN = $isPostageCostOnePLN;
return $this;
}
public function getCustomPromo1(): ?string
{
return $this->customPromo1;
}
public function setCustomPromo1(?string $customPromo1): self
{
$this->customPromo1 = $customPromo1;
return $this;
}
public function getCustomPromo2(): ?string
{
return $this->customPromo2;
}
public function setCustomPromo2(?string $customPromo2): self
{
$this->customPromo2 = $customPromo2;
return $this;
}
}