<?php
namespace App\Entity;
use App\Repository\InventoryItemsRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* @ORM\Entity(repositoryClass=InventoryItemsRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class InventoryItems
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=InventoryProduct::class, inversedBy="inventoryItems")
* @ORM\JoinColumn(nullable=false)
*/
private $product;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $qty;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $sale_price;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $updated_at;
/**
* @ORM\Column(type="integer")
*/
private $type = -1;
/**
* @ORM\OneToMany(targetEntity=RepairItems::class, mappedBy="material")
*/
private $repairItems;
public static $types = [
'Bevételezés' => 1,
'Kivételezés' => -1,
];
/**
* @ORM\ManyToOne(targetEntity=Repairs::class, inversedBy="inventoryItem")
*/
private $repairs;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $purchase_price;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $price_sum;
public function __construct(){
if($this->created_at == null){
$this->created_at = new \DateTimeImmutable();
}
$this->repairItems = 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 getProduct(): ?InventoryProduct
{
return $this->product;
}
public function setProduct(?InventoryProduct $product): self
{
$this->product = $product;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(?int $qty): self
{
$this->qty = $qty;
return $this;
}
public function getPurchasePrice(): ?float
{
return $this->purchase_price;
}
public function getPurchasePriceNum(): ?float
{
return $this->purchase_price / 100;
}
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 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;
}
public function __toString()
{
return $this->qty;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, RepairItems>
*/
public function getRepairItems(): Collection
{
return $this->repairItems;
}
public function addRepairItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$this->repairItems[] = $repairItem;
$repairItem->setMaterial($this);
}
return $this;
}
public function removeRepairItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getMaterial() === $this) {
$repairItem->setMaterial(null);
}
}
return $this;
}
public function getRepairs(): ?Repairs
{
return $this->repairs;
}
public function setRepairs(?Repairs $repairs): self
{
$this->repairs = $repairs;
return $this;
}
public function getPriceSum(): ?float
{
return $this->sale_price * $this->qty;
}
public function setPriceSum(int $price_sum): self
{
$this->price_sum = $price_sum;
return $this;
}
}