src/Entity/Product.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\ProductRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  14.  * @ApiResource(
  15.  *  normalizationContext={"groups"={"product:read"}},
  16.  *  denormalizationContext={"groups"={"product:write"}}
  17.  * )
  18.  * @ApiFilter(SearchFilter::class, properties={"code":"exact"})
  19.  */
  20. class Product
  21. {
  22.     public const DEFAULT_FIELDS = [
  23.         'id',
  24.         'name',
  25.         'code',
  26.         'price',
  27.         'qty',
  28.         'hold',
  29.         'shop_stock',
  30.         'description',
  31.         'productType',
  32.         'created_at',
  33.         'updated_at'
  34.     ];
  35.     public const ADDITIONAL_FIELDS = [
  36.         'color',
  37.         'gsm',
  38.         'dimension1',
  39.         'dimension2',
  40.         'caliper_microns',
  41.         'broken_rate',
  42.         'packet_rate',
  43.         'packet_qty',
  44.         'bulk_rate',
  45.         'bulk_qty',
  46.         'sheet_reel_envelope',
  47.         'size',
  48.     ];
  49.     use TimestampableEntity;
  50.     /**
  51.      * @ORM\Id
  52.      * @ORM\GeneratedValue
  53.      * @ORM\Column(type="integer")
  54.      * @Groups({"product:read"})
  55.      */
  56.     private $id;
  57.     /**
  58.      * @ORM\Column(type="string", length=255)
  59.      * @Groups({"product:read", "product:write"})
  60.      */
  61.     private $name;
  62.     /**
  63.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  64.      * @Groups({"product:read", "product:write"})
  65.      */
  66.     private $price;
  67.     /**
  68.      * @ORM\Column(type="integer")
  69.      * @Groups({"product:read", "product:write"})
  70.      */
  71.     private $qty;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, unique=true)
  74.      * @Groups({"product:read", "product:write"})
  75.      */
  76.     private $code;
  77.     /**
  78.      * @ORM\Column(type="text", nullable=true)
  79.      * @Groups({"product:read", "product:write"})
  80.      */
  81.     private $description;
  82.     /**
  83.      * @ORM\ManyToOne(targetEntity=ProductType::class, inversedBy="products")
  84.      * @ORM\JoinColumn(nullable=true)
  85.      * @Groups({"product:read", "product:write"})
  86.      */
  87.     private $productType;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=ProductField::class, mappedBy="product", cascade={"persist", "remove"}, orphanRemoval="true")
  90.      */
  91.     private $productFields;
  92.     /**
  93.      * @ORM\Column(type="integer", nullable=true)
  94.      * @Groups({"product:read", "product:write"})
  95.      */
  96.     private $hold;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity=ProductIn::class, mappedBy="product")
  99.      */
  100.     private $productIns;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity=ProductOut::class, mappedBy="product")
  103.      */
  104.     private $productOuts;
  105.     /**
  106.      * @ORM\Column(type="boolean", nullable=true, options={"default" : 0})
  107.      * @Groups({"product:read", "product:write"})
  108.      */
  109.     private $shopStock;
  110.     /**
  111.      * @ORM\Column(type="string", length=255, nullable=true)
  112.      */
  113.     private $size;
  114.     /**
  115.      * @ORM\Column(type="string", length=255, nullable=true)
  116.      */
  117.     private $color;
  118.     /**
  119.      * @ORM\Column(type="integer", nullable=true)
  120.      */
  121.     private $gsm;
  122.     /**
  123.      * @ORM\Column(type="integer", nullable=true)
  124.      */
  125.     private $caliperMicrons;
  126.     /**
  127.      * @ORM\Column(type="integer", nullable=true)
  128.      */
  129.     private $dimension1;
  130.     /**
  131.      * @ORM\Column(type="integer", nullable=true)
  132.      */
  133.     private $dimension2;
  134.     /**
  135.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  136.      */
  137.     private $brokenRate;
  138.     /**
  139.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  140.      */
  141.     private $packetRate;
  142.     /**
  143.      * @ORM\Column(type="integer", nullable=true)
  144.      */
  145.     private $packetQty;
  146.     /**
  147.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  148.      */
  149.     private $bulkRate;
  150.     /**
  151.      * @ORM\Column(type="string", length=255, nullable=true)
  152.      */
  153.     private $bulkQty;
  154.     /**
  155.      * @ORM\Column(type="string", nullable=true)
  156.      */
  157.     private $pricingUnits;
  158.     /**
  159.      * @ORM\Column(type="string", length=255, nullable=true)
  160.      */
  161.     private $sheetReelEnvelope;
  162.     public function __construct()
  163.     {
  164.         $this->productFields = new ArrayCollection();
  165.         $this->productIns = new ArrayCollection();
  166.         $this->productOuts = new ArrayCollection();
  167.     }
  168.     public function getId(): ?int
  169.     {
  170.         return $this->id;
  171.     }
  172.     public function getName(): ?string
  173.     {
  174.         return $this->name;
  175.     }
  176.     public function setName(string $name): self
  177.     {
  178.         $this->name $name;
  179.         return $this;
  180.     }
  181.     public function getPrice(): ?string
  182.     {
  183.         return $this->price;
  184.     }
  185.     public function setPrice(?string $price): self
  186.     {
  187.         $this->price $price;
  188.         return $this;
  189.     }
  190.     public function getQty(): ?int
  191.     {
  192.         return $this->qty;
  193.     }
  194.     public function setQty(int $qty): self
  195.     {
  196.         $this->qty $qty;
  197.         return $this;
  198.     }
  199.     public function getCode(): ?string
  200.     {
  201.         return $this->code;
  202.     }
  203.     public function setCode(string $code): self
  204.     {
  205.         $this->code $code;
  206.         return $this;
  207.     }
  208.     public function getDescription(): ?string
  209.     {
  210.         return $this->description;
  211.     }
  212.     public function setDescription(?string $description): self
  213.     {
  214.         $this->description $description;
  215.         return $this;
  216.     }
  217.     public function getProductType(): ?ProductType
  218.     {
  219.         return $this->productType;
  220.     }
  221.     public function setProductType(?ProductType $productType): self
  222.     {
  223.         $this->productType $productType;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection|ProductField[]
  228.      */
  229.     public function getProductFields(): Collection
  230.     {
  231.         return $this->productFields;
  232.     }
  233.     public function addProductField(ProductField $productField): self
  234.     {
  235.         if (!$this->productFields->contains($productField)) {
  236.             $this->productFields[] = $productField;
  237.             $productField->setProduct($this);
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeProductField(ProductField $productField): self
  242.     {
  243.         if ($this->productFields->removeElement($productField)) {
  244.             // set the owning side to null (unless already changed)
  245.             if ($productField->getProduct() === $this) {
  246.                 $productField->setProduct(null);
  247.             }
  248.         }
  249.         return $this;
  250.     }
  251.     public function getHold(): ?int
  252.     {
  253.         return $this->hold;
  254.     }
  255.     public function setHold(?int $hold): self
  256.     {
  257.         $this->hold $hold;
  258.         return $this;
  259.     }
  260.     /**
  261.      * @return Collection<int, ProductIn>
  262.      */
  263.     public function getProductIns(): Collection
  264.     {
  265.         return $this->productIns;
  266.     }
  267.     public function addProductIn(ProductIn $productIn): self
  268.     {
  269.         if (!$this->productIns->contains($productIn)) {
  270.             $this->productIns[] = $productIn;
  271.             $productIn->setProduct($this);
  272.         }
  273.         return $this;
  274.     }
  275.     public function removeProductIn(ProductIn $productIn): self
  276.     {
  277.         if ($this->productIns->removeElement($productIn)) {
  278.             // set the owning side to null (unless already changed)
  279.             if ($productIn->getProduct() === $this) {
  280.                 $productIn->setProduct(null);
  281.             }
  282.         }
  283.         return $this;
  284.     }
  285.     /**
  286.      * @return Collection<int, ProductOut>
  287.      */
  288.     public function getProductOuts(): Collection
  289.     {
  290.         return $this->productOuts;
  291.     }
  292.     public function addProductOut(ProductOut $productOut): self
  293.     {
  294.         if (!$this->productOuts->contains($productOut)) {
  295.             $this->productOuts[] = $productOut;
  296.             $productOut->setProduct($this);
  297.         }
  298.         return $this;
  299.     }
  300.     public function removeProductOut(ProductOut $productOut): self
  301.     {
  302.         if ($this->productOuts->removeElement($productOut)) {
  303.             // set the owning side to null (unless already changed)
  304.             if ($productOut->getProduct() === $this) {
  305.                 $productOut->setProduct(null);
  306.             }
  307.         }
  308.         return $this;
  309.     }
  310.     public function __toString() {
  311.         return "[".$this->getCode()."] ".$this->getName();
  312.     }
  313.     public function getShopStock(): ?bool
  314.     {
  315.         return $this->shopStock;
  316.     }
  317.     public function setShopStock(?bool $shopStock): self
  318.     {
  319.         $this->shopStock $shopStock;
  320.         return $this;
  321.     }
  322.     public function getSize(): ?string
  323.     {
  324.         return $this->size;
  325.     }
  326.     public function setSize(?string $size): self
  327.     {
  328.         $this->size $size;
  329.         return $this;
  330.     }
  331.     public function getColor(): ?string
  332.     {
  333.         return $this->color;
  334.     }
  335.     public function setColor(?string $color): self
  336.     {
  337.         $this->color $color;
  338.         return $this;
  339.     }
  340.     public function getGsm(): ?int
  341.     {
  342.         return $this->gsm;
  343.     }
  344.     public function setGsm(?int $gsm): self
  345.     {
  346.         $this->gsm $gsm;
  347.         return $this;
  348.     }
  349.     public function getCaliperMicrons(): ?int
  350.     {
  351.         return $this->caliperMicrons;
  352.     }
  353.     public function setCaliperMicrons(?int $CaliperMicrons): self
  354.     {
  355.         $this->caliperMicrons $CaliperMicrons;
  356.         return $this;
  357.     }
  358.     public function getDimension1(): ?int
  359.     {
  360.         return $this->dimension1;
  361.     }
  362.     public function setDimension1(?int $dimension1): self
  363.     {
  364.         $this->dimension1 $dimension1;
  365.         return $this;
  366.     }
  367.     public function getDimension2(): ?int
  368.     {
  369.         return $this->dimension2;
  370.     }
  371.     public function setDimension2(?int $dimension2): self
  372.     {
  373.         $this->dimension2 $dimension2;
  374.         return $this;
  375.     }
  376.     public function getBrokenRate(): ?string
  377.     {
  378.         return $this->brokenRate;
  379.     }
  380.     public function setBrokenRate(?string $brokenRate): self
  381.     {
  382.         $this->brokenRate $brokenRate;
  383.         return $this;
  384.     }
  385.     public function getPacketRate(): ?string
  386.     {
  387.         return $this->packetRate;
  388.     }
  389.     public function setPacketRate(?string $packetRate): self
  390.     {
  391.         $this->packetRate $packetRate;
  392.         return $this;
  393.     }
  394.     public function getPacketQty(): ?int
  395.     {
  396.         return $this->packetQty;
  397.     }
  398.     public function setPacketQty(?int $packetQty): self
  399.     {
  400.         $this->packetQty $packetQty;
  401.         return $this;
  402.     }
  403.     public function getBulkRate(): ?string
  404.     {
  405.         return $this->bulkRate;
  406.     }
  407.     public function setBulkRate(?string $bulkRate): self
  408.     {
  409.         $this->bulkRate $bulkRate;
  410.         return $this;
  411.     }
  412.     public function getBulkQty(): ?string
  413.     {
  414.         return $this->bulkQty;
  415.     }
  416.     public function setBulkQty(?string $bulkQty): self
  417.     {
  418.         $this->bulkQty $bulkQty;
  419.         return $this;
  420.     }
  421.     public function getPricingUnits(): ?string
  422.     {
  423.         return $this->pricingUnits;
  424.     }
  425.     public function setPricingUnits(?string $pricingUnits): self
  426.     {
  427.         $this->pricingUnits $pricingUnits;
  428.         return $this;
  429.     }
  430.     public function getSheetReelEnvelope(): ?string
  431.     {
  432.         return $this->sheetReelEnvelope;
  433.     }
  434.     public function setSheetReelEnvelope(?string $sheetReelEnvelope): self
  435.     {
  436.         $this->sheetReelEnvelope $sheetReelEnvelope;
  437.         return $this;
  438.     }
  439.     public function getCalculatorPaperDisplayName():string
  440.     {
  441.         return '['.$this->gsm.' gsm]['.$this->dimension1.'x'.$this->dimension2.']['.$this->name.
  442.             ']['.$this->description.']';
  443.     }
  444.     public function getCalculatorPaperSearchDisplayName():string
  445.     {
  446.         return '['.$this->gsm.' gsm]['.$this->name.']['.$this->description.']';
  447.     }
  448. }