<?php
namespace App\Entity;
use App\Repository\InventoryProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\Comparison;
/**
* @ORM\Entity(repositoryClass=InventoryProductRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class InventoryProduct
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sku;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $manufacturer;
/**
* @ORM\Column(type="string", length=255)
*/
private $quantity_type;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updated_at;
/**
* @ORM\OneToMany(targetEntity=InventoryItems::class, cascade={"persist"}, mappedBy="product")
*/
private $inventoryItems;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $purchase_price;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $sale_price;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $supplier;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $note;
public function __construct()
{
$this->inventoryItems = new ArrayCollection();
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue(): void
{
$this->created_at = new \DateTimeImmutable();
$this->setUpdatedAtValue();
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue(): void
{
$this->updated_at = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSku(): ?string
{
return $this->sku;
}
public function setSku(?string $sku): self
{
$this->sku = $sku;
return $this;
}
public function getManufacturer(): ?string
{
return $this->manufacturer;
}
public function setManufacturer(?string $manufacturer): self
{
$this->manufacturer = $manufacturer;
return $this;
}
public function getQuantityType(): ?string
{
return $this->quantity_type;
}
public function setQuantityType(string $quantity_type): self
{
$this->quantity_type = $quantity_type;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
/**
* @return Collection<int, InventoryItems>
*/
public function getInventoryItems(): Collection
{
$criteria = new Criteria();
//$criteria->orderBy(['id' => Order::Descending]);
$comparison = new Comparison('type', Comparison::EQ, 1);
$criteria->where($comparison);
return $this->inventoryItems->matching($criteria);
return $this->inventoryItems;
}
public function addInventoryItem(InventoryItems $inventoryItem): self
{
if (!$this->inventoryItems->contains($inventoryItem)) {
$this->inventoryItems[] = $inventoryItem;
$inventoryItem->setProduct($this);
//$inventoryItem->setPurchasePrice($this->getPurchasePrice());
//$inventoryItem->setSalePrice($this->getSalePrice());
}
return $this;
}
public function removeInventoryItem(InventoryItems $inventoryItem): self
{
if ($this->inventoryItems->removeElement($inventoryItem)) {
// set the owning side to null (unless already changed)
if ($inventoryItem->getProduct() === $this) {
$inventoryItem->setProduct(null);
}
}
return $this;
}
public function getPurchasePrice(): ?float
{
return $this->purchase_price;
}
public function setPurchasePrice(?float $purchase_price): self
{
$this->purchase_price = $purchase_price;
return $this;
}
public function getSalePrice(): ?float
{
return $this->sale_price;
}
public function setSalePrice(?float $sale_price): self
{
$this->sale_price = $sale_price;
return $this;
}
public function __toString()
{
return $this->name;
}
public function getCurrentQuantity(){
$num = 0;
foreach ($this->inventoryItems as $key => $value) {
$num = $num + ($value->getQty() * $value->getType());
}
return $num;
}
public function getSupplier(): ?string
{
return $this->supplier;
}
public function setSupplier(?string $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
}