src/Flexy/ShopBundle/Entity/Promotion/Coupon.php line 21

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Promotion;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Customer\Customer;
  5. use App\Flexy\ShopBundle\Entity\Order\Order;
  6. use App\Flexy\ShopBundle\Repository\Promotion\CouponRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use ApiPlatform\Core\Annotation\ApiFilter;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. #[ApiResource]
  15. #[ApiFilter(SearchFilter::class, properties: ['exact''code'])]
  16. #[UniqueEntity('code')]
  17. #[ORM\Entity(repositoryClassCouponRepository::class)]
  18. class Coupon
  19. {
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type'integer')]
  23.     private $id;
  24.     #[ORM\Column(type'string'length255)]
  25.     private ?string $name null;
  26.     #[ORM\Column(type'string'length255)]
  27.     private ?string $code null;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private ?string $type null;
  30.     #[ORM\Column(type'integer'nullabletrue)]
  31.     private ?int $usageLimit null;
  32.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  33.     private ?\DateTimeImmutable $endAt null;
  34.     #[ORM\ManyToOne(targetEntityPromotion::class, inversedBy'coupons')]
  35.     private ?\App\Flexy\ShopBundle\Entity\Promotion\Promotion $promotion null;
  36.     #[ORM\Column(type'string'length255nullabletrue)]
  37.     private $typeReduction;
  38.     #[ORM\Column(type'float'nullabletrue)]
  39.     private ?float $valueReduction null;
  40.     #[ORM\OneToMany(targetEntityOrder::class, mappedBy'coupon')]
  41.     private \Doctrine\Common\Collections\Collection|array $orders;
  42.         #[ORM\Column(type'integer'nullabletrue)]
  43.     private ?int $minProductsByOrder null;
  44.     #[ORM\Column(type'text'nullabletrue)]
  45.     private ?string $description null;
  46.     #[ORM\ManyToMany(targetEntityCustomer::class, inversedBy'affectedCoupons')]
  47.     private \Doctrine\Common\Collections\Collection|array $allowedCustomers;
  48.     #[ORM\ManyToOne(targetEntityCustomer::class, inversedBy'affectedCouponsOnlyForMe')]
  49.     private ?\App\Flexy\ShopBundle\Entity\Customer\Customer $onlyThisCustomer null;
  50.     
  51.     
  52.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  53.     private ?\DateTimeImmutable $purchase_at null;
  54.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  55.     private ?\DateTimeImmutable $purchase_end null;
  56.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  57.     private ?\DateTimeImmutable $consumPeriod_at null;
  58.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  59.     private ?\DateTimeImmutable $consumPeriod_end null;
  60.     
  61.     public function __construct()
  62.     {
  63.         $this->orders = new ArrayCollection();
  64.         $this->allowedCustomers = new ArrayCollection();
  65.     }
  66.     public function __toString()
  67.     {
  68.         return (string)$this->code;
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getName(): ?string
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function setName(string $name): self
  79.     {
  80.         $this->name $name;
  81.         return $this;
  82.     }
  83.     public function getCode(): ?string
  84.     {
  85.         return $this->code;
  86.     }
  87.     public function setCode(string $code): self
  88.     {
  89.         $this->code $code;
  90.         return $this;
  91.     }
  92.     public function getType(): ?string
  93.     {
  94.         return $this->type;
  95.     }
  96.     public function setType(?string $type): self
  97.     {
  98.         $this->type $type;
  99.         return $this;
  100.     }
  101.     public function getUsageLimit(): ?int
  102.     {
  103.         return $this->usageLimit;
  104.     }
  105.     public function setUsageLimit(?int $usageLimit): self
  106.     {
  107.         $this->usageLimit $usageLimit;
  108.         return $this;
  109.     }
  110.     public function getEndAt(): ?\DateTimeImmutable
  111.     {
  112.         return $this->endAt;
  113.     }
  114.     public function setEndAt(?\DateTimeImmutable $endAt): self
  115.     {
  116.         $this->endAt $endAt;
  117.         return $this;
  118.     }
  119.     public function getPromotion(): ?Promotion
  120.     {
  121.         return $this->promotion;
  122.     }
  123.     public function setPromotion(?Promotion $promotion): self
  124.     {
  125.         $this->promotion $promotion;
  126.         return $this;
  127.     }
  128.     public function getTypeReduction()
  129.     {
  130.         return $this->typeReduction;
  131.     }
  132.     public function setTypeReduction$typeReduction)
  133.     {
  134.         $this->typeReduction $typeReduction;
  135.         return $this;
  136.     }
  137.     public function getValueReduction(): ?float
  138.     {
  139.         return $this->valueReduction;
  140.     }
  141.     public function setValueReduction(?float $valueReduction): self
  142.     {
  143.         $this->valueReduction $valueReduction;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, Order>
  148.      */
  149.     public function getOrders(): Collection
  150.     {
  151.         return $this->orders;
  152.     }
  153.     public function addOrder(Order $order): self
  154.     {
  155.         if (!$this->orders->contains($order)) {
  156.             $this->orders[] = $order;
  157.             $order->setCoupon($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeOrder(Order $order): self
  162.     {
  163.         if ($this->orders->removeElement($order)) {
  164.             // set the owning side to null (unless already changed)
  165.             if ($order->getCoupon() === $this) {
  166.                 $order->setCoupon(null);
  167.             }
  168.         }
  169.         return $this;
  170.     }
  171.     public function getMinProductsByOrder(): ?int
  172.     {
  173.         return $this->minProductsByOrder;
  174.     }
  175.     public function setMinProductsByOrder(?int $minProductsByOrder): self
  176.     {
  177.         $this->minProductsByOrder $minProductsByOrder;
  178.         return $this;
  179.     }
  180.     public function getDescription(): ?string
  181.     {
  182.         return $this->description;
  183.     }
  184.     public function setDescription(?string $description): self
  185.     {
  186.         $this->description $description;
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return Collection<int, Customer>
  191.      */
  192.     public function getAllowedCustomers(): Collection
  193.     {
  194.         return $this->allowedCustomers;
  195.     }
  196.     public function addAllowedCustomer(Customer $allowedCustomer): self
  197.     {
  198.         if (!$this->allowedCustomers->contains($allowedCustomer)) {
  199.             $this->allowedCustomers[] = $allowedCustomer;
  200.         }
  201.         return $this;
  202.     }
  203.     public function removeAllowedCustomer(Customer $allowedCustomer): self
  204.     {
  205.         $this->allowedCustomers->removeElement($allowedCustomer);
  206.         return $this;
  207.     }
  208.     public function getOnlyThisCustomer(): ?Customer
  209.     {
  210.         return $this->onlyThisCustomer;
  211.     }
  212.     public function setOnlyThisCustomer(?Customer $onlyThisCustomer): self
  213.     {
  214.         $this->onlyThisCustomer $onlyThisCustomer;
  215.         return $this;
  216.     }
  217.     
  218.      public function getPurchaseAt(): ?\DateTimeImmutable
  219.     {
  220.         return $this->purchase_at;
  221.     }
  222.     public function setPurchaseAt(?\DateTimeImmutable $purchase_at): static
  223.     {
  224.         $this->purchase_at $purchase_at;
  225.         return $this;
  226.     }
  227.     public function getPurchaseEnd(): ?\DateTimeImmutable
  228.     {
  229.         return $this->purchase_end;
  230.     }
  231.     public function setPurchaseEnd(?\DateTimeImmutable $purchase_end): static
  232.     {
  233.         $this->purchase_end $purchase_end;
  234.         return $this;
  235.     }
  236.     public function getConsumPeriodAt(): ?\DateTimeImmutable
  237.     {
  238.         return $this->consumPeriod_at;
  239.     }
  240.     public function setConsumPeriodAt(?\DateTimeImmutable $consumPeriod_at): static
  241.     {
  242.         $this->consumPeriod_at $consumPeriod_at;
  243.         return $this;
  244.     }
  245.     public function getConsumPeriodEnd(): ?\DateTimeImmutable
  246.     {
  247.         return $this->consumPeriod_end;
  248.     }
  249.     public function setConsumPeriodEnd(?\DateTimeImmutable $consumPeriod_end): static
  250.     {
  251.         $this->consumPeriod_end $consumPeriod_end;
  252.         return $this;
  253.     }
  254. }