src/Entity/InventoryProduct.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\InventoryProductRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\Common\Collections\Criteria;
  8. use Doctrine\Common\Collections\Expr\Comparison;
  9. /**
  10.  * @ORM\Entity(repositoryClass=InventoryProductRepository::class)
  11.  * @ORM\HasLifecycleCallbacks
  12.  */
  13. class InventoryProduct
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private $sku;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $manufacturer;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $quantity_type;
  37.     /**
  38.      * @ORM\Column(type="datetime_immutable")
  39.      */
  40.     private $created_at;
  41.     /**
  42.      * @ORM\Column(type="datetime_immutable", nullable=true)
  43.      */
  44.     private $updated_at;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity=InventoryItems::class, cascade={"persist"}, mappedBy="product")
  47.      */
  48.     private $inventoryItems;
  49.     /**
  50.      * @ORM\Column(type="float", nullable=true)
  51.      */
  52.     private $purchase_price;
  53.     /**
  54.      * @ORM\Column(type="float", nullable=true)
  55.      */
  56.     private $sale_price;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $supplier;
  61.     /**
  62.      * @ORM\Column(type="text", nullable=true)
  63.      */
  64.     private $note;
  65.     public function __construct()
  66.     {
  67.         $this->inventoryItems = new ArrayCollection();
  68.     }
  69.     /**
  70.      * @ORM\PrePersist
  71.      */
  72.     public function setCreatedAtValue(): void
  73.     {
  74.         $this->created_at = new \DateTimeImmutable();
  75.         $this->setUpdatedAtValue();
  76.     }
  77.     /**
  78.      * @ORM\PreUpdate
  79.      */
  80.     public function setUpdatedAtValue(): void
  81.     {
  82.         $this->updated_at = new \DateTimeImmutable();
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getName(): ?string
  89.     {
  90.         return $this->name;
  91.     }
  92.     public function setName(string $name): self
  93.     {
  94.         $this->name = $name;
  95.         return $this;
  96.     }
  97.     public function getSku(): ?string
  98.     {
  99.         return $this->sku;
  100.     }
  101.     public function setSku(?string $sku): self
  102.     {
  103.         $this->sku = $sku;
  104.         return $this;
  105.     }
  106.     public function getManufacturer(): ?string
  107.     {
  108.         return $this->manufacturer;
  109.     }
  110.     public function setManufacturer(?string $manufacturer): self
  111.     {
  112.         $this->manufacturer = $manufacturer;
  113.         return $this;
  114.     }
  115.     public function getQuantityType(): ?string
  116.     {
  117.         return $this->quantity_type;
  118.     }
  119.     public function setQuantityType(string $quantity_type): self
  120.     {
  121.         $this->quantity_type = $quantity_type;
  122.         return $this;
  123.     }
  124.     public function getCreatedAt(): ?\DateTimeImmutable
  125.     {
  126.         return $this->created_at;
  127.     }
  128.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  129.     {
  130.         $this->created_at = $created_at;
  131.         return $this;
  132.     }
  133.     public function getUpdatedAt(): ?\DateTimeImmutable
  134.     {
  135.         return $this->updated_at;
  136.     }
  137.     public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
  138.     {
  139.         $this->updated_at = $updated_at;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection<int, InventoryItems>
  144.      */
  145.     public function getInventoryItems(): Collection
  146.     {
  147.         $criteria = new Criteria();
  148.         //$criteria->orderBy(['id' => Order::Descending]);
  149.         $comparison = new Comparison('type', Comparison::EQ, 1);
  150.         $criteria->where($comparison);
  151.         return $this->inventoryItems->matching($criteria);
  152.         return $this->inventoryItems;
  153.     }
  154.     public function addInventoryItem(InventoryItems $inventoryItem): self
  155.     {
  156.         if (!$this->inventoryItems->contains($inventoryItem)) {
  157.             $this->inventoryItems[] = $inventoryItem;
  158.             $inventoryItem->setProduct($this);
  159.             //$inventoryItem->setPurchasePrice($this->getPurchasePrice());
  160.             //$inventoryItem->setSalePrice($this->getSalePrice());
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeInventoryItem(InventoryItems $inventoryItem): self
  165.     {
  166.         if ($this->inventoryItems->removeElement($inventoryItem)) {
  167.             // set the owning side to null (unless already changed)
  168.             if ($inventoryItem->getProduct() === $this) {
  169.                 $inventoryItem->setProduct(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174.     public function getPurchasePrice(): ?float
  175.     {
  176.         return $this->purchase_price;
  177.     }
  178.     public function setPurchasePrice(?float $purchase_price): self
  179.     {
  180.         $this->purchase_price = $purchase_price;
  181.         return $this;
  182.     }
  183.     public function getSalePrice(): ?float
  184.     {
  185.         return $this->sale_price;
  186.     }
  187.     public function setSalePrice(?float $sale_price): self
  188.     {
  189.         $this->sale_price = $sale_price;
  190.         return $this;
  191.     }
  192.     public function __toString()
  193.     {
  194.         return $this->name;
  195.     }
  196.     public function getCurrentQuantity(){
  197.         $num = 0;
  198.         foreach ($this->inventoryItems as $key => $value) {
  199.            $num = $num + ($value->getQty() * $value->getType());
  200.         }
  201.         return $num;
  202.     }
  203.     public function getSupplier(): ?string
  204.     {
  205.         return $this->supplier;
  206.     }
  207.     public function setSupplier(?string $supplier): self
  208.     {
  209.         $this->supplier = $supplier;
  210.         return $this;
  211.     }
  212.     public function getNote(): ?string
  213.     {
  214.         return $this->note;
  215.     }
  216.     public function setNote(?string $note): self
  217.     {
  218.         $this->note = $note;
  219.         return $this;
  220.     }
  221. }