src/Evo/Infrastructure/MappingORM/Order.php line 24

Open in your IDE?
  1. <?php
  2. namespace Evo\Infrastructure\MappingORM;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use App\Enum\VATRateEnum;
  7. use App\Utils\OrderUtils;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ApiResource(attributes={
  14.  *     "normalization_context"={"groups"={"read_order"}},
  15.  *     "denormalization_context"={"groups"={"write_order"}}
  16.  * }, itemOperations={"get", "put"})
  17.  * @ORM\Entity(repositoryClass="App\Repository\OrderRepository")
  18.  * @ORM\Table(name="orders")
  19.  * @ApiFilter(SearchFilter::class, properties={"organization": "exact", "category": "exact"})
  20.  */
  21. class Order
  22. {
  23.     /**
  24.      * @Groups({"read_order", "read_organization", "write_organization"})
  25.      * @ORM\Id()
  26.      * @ORM\GeneratedValue()
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private ?int $id null;
  30.     /**
  31.      * @Groups({"read_order", "write_order", "read_organization", "write_organization", "read_item", "write_item"})
  32.      * @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Item", mappedBy="itemOrder", cascade={"persist"})
  33.      */
  34.     private ?Collection $items;
  35.     /**
  36.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private ?string $status null;
  40.     /**
  41.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  42.      * @ORM\Column(type="datetime", nullable=true)
  43.      */
  44.     private $createdAt;
  45.     /**
  46.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  47.      * @ORM\Column(type="float", nullable=true)
  48.      */
  49.     private $totalPriceWithoutTax 0;
  50.     /**
  51.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  52.      * @ORM\Column(type="string", length=255)
  53.      */
  54.     private ?string $VATRate VATRateEnum::VAT_20;
  55.     /**
  56.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  57.      * @ORM\Column(type="float", nullable=true)
  58.      */
  59.     private $totalPrice 0;
  60.     /**
  61.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  62.      * @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\Invoice", cascade={"persist"})
  63.      */
  64.     private ?Invoice $invoice null;
  65.     /**
  66.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  67.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="orders")
  68.      * @ORM\JoinColumn(nullable=false)
  69.      */
  70.     private ?Organization $organization null;
  71.     /**
  72.      * @Groups({"read_order", "write_order", "read_organization", "write_organization"})
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     private $category;
  76.     public function __construct()
  77.     {
  78.         $this->items = new ArrayCollection();
  79.         $this->createdAt = new \DateTime();
  80.     }
  81.     /**
  82.      * @return Collection|Item[]
  83.      */
  84.     public function getItems(): Collection
  85.     {
  86.         return $this->items;
  87.     }
  88.     public function addItem(Item $item): self
  89.     {
  90.         if (!$this->items->contains($item)) {
  91.             $this->items[] = $item;
  92.             $item->setItemOrder($this);
  93.         }
  94.         return $this;
  95.     }
  96.     public function removeItem(Item $item): self
  97.     {
  98.         if ($this->items->contains($item)) {
  99.             $this->items->removeElement($item);
  100.             // set the owning side to null (unless already changed)
  101.             if ($item->getItemOrder() === $this) {
  102.                 $item->setItemOrder(null);
  103.             }
  104.         }
  105.         return $this;
  106.     }
  107.     public function getPack()
  108.     {
  109.         $subscriptionProducts = [];
  110.         foreach ($this->getItems() as $item) {
  111.             if ($item->getProduct()->getUniqueKey()) {
  112.                 $subscriptionProducts[] = $item->getProduct()->getUniqueKey();
  113.             }
  114.         }
  115.         return OrderUtils::getPackByProducts($subscriptionProducts);
  116.     }
  117.     public function getStatus(): ?string
  118.     {
  119.         return $this->status;
  120.     }
  121.     public function setStatus(string $status): self
  122.     {
  123.         $this->status $status;
  124.         return $this;
  125.     }
  126.     public function getCreatedAt(): ?\DateTimeInterface
  127.     {
  128.         return $this->createdAt;
  129.     }
  130.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  131.     {
  132.         $this->createdAt $createdAt;
  133.         return $this;
  134.     }
  135.     public function getTotalPriceWithoutTax(): ?float
  136.     {
  137.         return $this->totalPriceWithoutTax;
  138.     }
  139.     public function setTotalPriceWithoutTax(float $totalPriceWithoutTax): self
  140.     {
  141.         $this->totalPriceWithoutTax $totalPriceWithoutTax;
  142.         return $this;
  143.     }
  144.     public function getVATRate(): ?string
  145.     {
  146.         return $this->VATRate;
  147.     }
  148.     public function setVATRate(string $VATRate): self
  149.     {
  150.         $this->VATRate $VATRate;
  151.         return $this;
  152.     }
  153.     public function getTotalPrice(): ?float
  154.     {
  155.         return $this->totalPrice;
  156.     }
  157.     public function setTotalPrice(float $totalPrice): self
  158.     {
  159.         $this->totalPrice $totalPrice;
  160.         return $this;
  161.     }
  162.     public function getInvoice(): ?Invoice
  163.     {
  164.         return $this->invoice;
  165.     }
  166.     public function setInvoice(?Invoice $invoice): self
  167.     {
  168.         $this->invoice $invoice;
  169.         return $this;
  170.     }
  171.     public function getOrganization(): ?Organization
  172.     {
  173.         return $this->organization;
  174.     }
  175.     public function setOrganization(?Organization $organization): self
  176.     {
  177.         $this->organization $organization;
  178.         return $this;
  179.     }
  180.     public function __toString()
  181.     {
  182.         return '#'.$this->getId();
  183.     }
  184.     public function getId(): ?int
  185.     {
  186.         return $this->id;
  187.     }
  188.     /**
  189.      * @return mixed
  190.      */
  191.     public function getCategory()
  192.     {
  193.         return $this->category;
  194.     }
  195.     /**
  196.      * @param mixed $category
  197.      */
  198.     public function setCategory($category): self
  199.     {
  200.         $this->category $category;
  201.         return $this;
  202.     }
  203. }