<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
* @ApiResource(
* normalizationContext={"groups"={"product:read"}},
* denormalizationContext={"groups"={"product:write"}}
* )
* @ApiFilter(SearchFilter::class, properties={"code":"exact"})
*/
class Product
{
public const DEFAULT_FIELDS = [
'id',
'name',
'code',
'price',
'qty',
'hold',
'shop_stock',
'description',
'productType',
'created_at',
'updated_at'
];
public const ADDITIONAL_FIELDS = [
'color',
'gsm',
'dimension1',
'dimension2',
'caliper_microns',
'broken_rate',
'packet_rate',
'packet_qty',
'bulk_rate',
'bulk_qty',
'sheet_reel_envelope',
'size',
];
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"product:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"product:read", "product:write"})
*/
private $name;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
* @Groups({"product:read", "product:write"})
*/
private $price;
/**
* @ORM\Column(type="integer")
* @Groups({"product:read", "product:write"})
*/
private $qty;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Groups({"product:read", "product:write"})
*/
private $code;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"product:read", "product:write"})
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=ProductType::class, inversedBy="products")
* @ORM\JoinColumn(nullable=true)
* @Groups({"product:read", "product:write"})
*/
private $productType;
/**
* @ORM\OneToMany(targetEntity=ProductField::class, mappedBy="product", cascade={"persist", "remove"}, orphanRemoval="true")
*/
private $productFields;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"product:read", "product:write"})
*/
private $hold;
/**
* @ORM\OneToMany(targetEntity=ProductIn::class, mappedBy="product")
*/
private $productIns;
/**
* @ORM\OneToMany(targetEntity=ProductOut::class, mappedBy="product")
*/
private $productOuts;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default" : 0})
* @Groups({"product:read", "product:write"})
*/
private $shopStock;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $size;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $color;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $gsm;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $caliperMicrons;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $dimension1;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $dimension2;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $brokenRate;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $packetRate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $packetQty;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $bulkRate;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $bulkQty;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $pricingUnits;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sheetReelEnvelope;
public function __construct()
{
$this->productFields = new ArrayCollection();
$this->productIns = new ArrayCollection();
$this->productOuts = new ArrayCollection();
}
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 getPrice(): ?string
{
return $this->price;
}
public function setPrice(?string $price): self
{
$this->price = $price;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(int $qty): self
{
$this->qty = $qty;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getProductType(): ?ProductType
{
return $this->productType;
}
public function setProductType(?ProductType $productType): self
{
$this->productType = $productType;
return $this;
}
/**
* @return Collection|ProductField[]
*/
public function getProductFields(): Collection
{
return $this->productFields;
}
public function addProductField(ProductField $productField): self
{
if (!$this->productFields->contains($productField)) {
$this->productFields[] = $productField;
$productField->setProduct($this);
}
return $this;
}
public function removeProductField(ProductField $productField): self
{
if ($this->productFields->removeElement($productField)) {
// set the owning side to null (unless already changed)
if ($productField->getProduct() === $this) {
$productField->setProduct(null);
}
}
return $this;
}
public function getHold(): ?int
{
return $this->hold;
}
public function setHold(?int $hold): self
{
$this->hold = $hold;
return $this;
}
/**
* @return Collection<int, ProductIn>
*/
public function getProductIns(): Collection
{
return $this->productIns;
}
public function addProductIn(ProductIn $productIn): self
{
if (!$this->productIns->contains($productIn)) {
$this->productIns[] = $productIn;
$productIn->setProduct($this);
}
return $this;
}
public function removeProductIn(ProductIn $productIn): self
{
if ($this->productIns->removeElement($productIn)) {
// set the owning side to null (unless already changed)
if ($productIn->getProduct() === $this) {
$productIn->setProduct(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductOut>
*/
public function getProductOuts(): Collection
{
return $this->productOuts;
}
public function addProductOut(ProductOut $productOut): self
{
if (!$this->productOuts->contains($productOut)) {
$this->productOuts[] = $productOut;
$productOut->setProduct($this);
}
return $this;
}
public function removeProductOut(ProductOut $productOut): self
{
if ($this->productOuts->removeElement($productOut)) {
// set the owning side to null (unless already changed)
if ($productOut->getProduct() === $this) {
$productOut->setProduct(null);
}
}
return $this;
}
public function __toString() {
return "[".$this->getCode()."] ".$this->getName();
}
public function getShopStock(): ?bool
{
return $this->shopStock;
}
public function setShopStock(?bool $shopStock): self
{
$this->shopStock = $shopStock;
return $this;
}
public function getSize(): ?string
{
return $this->size;
}
public function setSize(?string $size): self
{
$this->size = $size;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getGsm(): ?int
{
return $this->gsm;
}
public function setGsm(?int $gsm): self
{
$this->gsm = $gsm;
return $this;
}
public function getCaliperMicrons(): ?int
{
return $this->caliperMicrons;
}
public function setCaliperMicrons(?int $CaliperMicrons): self
{
$this->caliperMicrons = $CaliperMicrons;
return $this;
}
public function getDimension1(): ?int
{
return $this->dimension1;
}
public function setDimension1(?int $dimension1): self
{
$this->dimension1 = $dimension1;
return $this;
}
public function getDimension2(): ?int
{
return $this->dimension2;
}
public function setDimension2(?int $dimension2): self
{
$this->dimension2 = $dimension2;
return $this;
}
public function getBrokenRate(): ?string
{
return $this->brokenRate;
}
public function setBrokenRate(?string $brokenRate): self
{
$this->brokenRate = $brokenRate;
return $this;
}
public function getPacketRate(): ?string
{
return $this->packetRate;
}
public function setPacketRate(?string $packetRate): self
{
$this->packetRate = $packetRate;
return $this;
}
public function getPacketQty(): ?int
{
return $this->packetQty;
}
public function setPacketQty(?int $packetQty): self
{
$this->packetQty = $packetQty;
return $this;
}
public function getBulkRate(): ?string
{
return $this->bulkRate;
}
public function setBulkRate(?string $bulkRate): self
{
$this->bulkRate = $bulkRate;
return $this;
}
public function getBulkQty(): ?string
{
return $this->bulkQty;
}
public function setBulkQty(?string $bulkQty): self
{
$this->bulkQty = $bulkQty;
return $this;
}
public function getPricingUnits(): ?string
{
return $this->pricingUnits;
}
public function setPricingUnits(?string $pricingUnits): self
{
$this->pricingUnits = $pricingUnits;
return $this;
}
public function getSheetReelEnvelope(): ?string
{
return $this->sheetReelEnvelope;
}
public function setSheetReelEnvelope(?string $sheetReelEnvelope): self
{
$this->sheetReelEnvelope = $sheetReelEnvelope;
return $this;
}
public function getCalculatorPaperDisplayName():string
{
return '['.$this->gsm.' gsm]['.$this->dimension1.'x'.$this->dimension2.']['.$this->name.
']['.$this->description.']';
}
public function getCalculatorPaperSearchDisplayName():string
{
return '['.$this->gsm.' gsm]['.$this->name.']['.$this->description.']';
}
}