src/Entity/IncomingOrder.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\IncomingOrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ORM\Entity(repositoryClass=IncomingOrderRepository::class)
  11.  */
  12. class IncomingOrder
  13. {
  14.     use TimestampableEntity;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      * @Groups({"list_incoming_order"})
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="incomingOrders")
  24.      * @Groups({"list_incoming_order"})
  25.      */
  26.     private ?User $user;
  27.     /**
  28.      * @ORM\Column(type="date")
  29.      * @Groups({"list_incoming_order"})
  30.      */
  31.     private ?\DateTimeInterface $orderDate;
  32.     /**
  33.      * @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="incomingOrders")
  34.      * @Groups({"list_incoming_order"})
  35.      */
  36.     private $supplier;
  37.     /**
  38.      * @ORM\Column(type="text", nullable=true)
  39.      * @Groups({"list_incoming_order"})
  40.      */
  41.     private ?string $notes;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity=ProductIn::class, mappedBy="incomingOrder", cascade={"persist"})
  44.      */
  45.     private $productIns;
  46.     /**
  47.      * @ORM\Column(type="string", length=255)
  48.      */
  49.     private ?string $status;
  50.     const STATUS_PENDING    "pending";
  51.     const STATUS_SENT "sent";
  52.     const STATUS_COMPLETED "completed";
  53.     /** @var array user friendly named type */
  54.     protected static array $statusName = [
  55.         self::STATUS_PENDING    => 'Pending',
  56.         self::STATUS_SENT => 'Sent',
  57.         self::STATUS_COMPLETED => 'Completed'
  58.     ];
  59.     public function __construct()
  60.     {
  61.         $this->productIns = new ArrayCollection();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getUser(): ?User
  68.     {
  69.         return $this->user;
  70.     }
  71.     public function setUser(?User $user): self
  72.     {
  73.         $this->user $user;
  74.         return $this;
  75.     }
  76.     public function getOrderDate(): ?\DateTimeInterface
  77.     {
  78.         return $this->orderDate;
  79.     }
  80.     public function setOrderDate(\DateTimeInterface $orderDate): self
  81.     {
  82.         $this->orderDate $orderDate;
  83.         return $this;
  84.     }
  85.     public function getSupplier(): ?Supplier
  86.     {
  87.         return $this->supplier;
  88.     }
  89.     public function setSupplier(?Supplier $supplier): self
  90.     {
  91.         $this->supplier $supplier;
  92.         return $this;
  93.     }
  94.     public function getNotes(): ?string
  95.     {
  96.         return $this->notes;
  97.     }
  98.     public function setNotes(?string $notes): self
  99.     {
  100.         $this->notes $notes;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection<int, ProductIn>
  105.      */
  106.     public function getProductIns(): Collection
  107.     {
  108.         return $this->productIns;
  109.     }
  110.     public function addProductIn(ProductIn $productIn): self
  111.     {
  112.         if (!$this->productIns->contains($productIn)) {
  113.             $this->productIns[] = $productIn;
  114.             $productIn->setIncomingOrder($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeProductIn(ProductIn $productIn): self
  119.     {
  120.         if ($this->productIns->removeElement($productIn)) {
  121.             // set the owning side to null (unless already changed)
  122.             if ($productIn->getIncomingOrder() === $this) {
  123.                 $productIn->setIncomingOrder(null);
  124.             }
  125.         }
  126.         return $this;
  127.     }
  128.     public function getTotalProductInsQty()
  129.     {
  130.         $productIns $this->getProductIns();
  131.         $total 0;
  132.         foreach ($productIns as $productIn){
  133.             $total $total $productIn->getQty();
  134.         }
  135.         return $total;
  136.     }
  137.     public function getStatus(): ?string
  138.     {
  139.         return $this->status;
  140.     }
  141.     public static function getStatusName($statusShortName): ?string
  142.     {
  143.         if (!isset(static::$statusName[$statusShortName])) {
  144.             return "Unknown status ($statusShortName)";
  145.         }
  146.         return static::$statusName[$statusShortName];
  147.         //return $this->status;
  148.     }
  149.     public function setStatus(string $status): self
  150.     {
  151.         if (!in_array($statusIncomingOrder::getAvailableStatuses())) {
  152.             throw new \InvalidArgumentException("Invalid type");
  153.         }
  154.         $this->status $status;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return array<string>
  159.      */
  160.     public static function getAvailableStatuses(): array
  161.     {
  162.         return [
  163.             self::STATUS_PENDING,
  164.             self::STATUS_SENT,
  165.             self::STATUS_COMPLETED
  166.         ];
  167.     }
  168. }