src/Entity/Paper.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Entity\Helpers\BaseEntity;
  5. use App\Repository\PaperRepository;
  6. use App\Entity\Helpers\TraitStockable;
  7. use App\Entity\Helpers\TraitPaperModel;
  8. use App\Entity\Helpers\TraitPriceUnity;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. #[ORM\Entity(repositoryClassPaperRepository::class)]
  12. class Paper extends BaseEntity
  13. {
  14.     use TraitPaperModel;
  15.     use TraitPriceUnity;
  16.     use TraitStockable;
  17.     const TYPE_REEL 0;
  18.     const TYPE_BLOCK 1;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255)]
  24.     private $reference;
  25.     #[ORM\Column(type'string'length255)]
  26.     private $referenceInternal;
  27.     #[ORM\Column(type'integer')]
  28.     private $quantityMin 0;
  29.     #[ORM\Column(type'decimal'precision15scale4)]
  30.     private $priceUnityInitial 0;
  31.     #[ORM\ManyToOne(targetEntityProvider::class, inversedBy'papers')]
  32.     #[ORM\JoinColumn(nullablefalse)]
  33.     private $provider;
  34.     #[ORM\OneToMany(mappedBy'paper'targetEntityPaperProduct::class, orphanRemovaltruecascade: ['all'])]
  35.     private $paperProducts;
  36.     #[ORM\OneToMany(mappedBy'paper'targetEntityPaperStock::class, orphanRemovaltruecascade: ['all'])]
  37.     private $paperStocks;
  38.     #[ORM\OneToMany(mappedBy'paper'targetEntityPaperStockGroup::class, orphanRemovaltruecascade: ['all'])]
  39.     private $paperStockGroups;
  40.     #[ORM\Column(type'integer')]
  41.     private $paperQuality 0;
  42.     #[ORM\Column(type'integer')]
  43.     private $paperQualityPercent 0;
  44.     #[ORM\ManyToOne(targetEntityPaperCategory::class, inversedBy'papers')]
  45.     private $paperCategory;
  46.     #[ORM\Column(type'boolean')]
  47.     private $outOfStock false;
  48.     #[ORM\Column(type'date_immutable'nullabletrue)]
  49.     private $outOfStockAt;
  50.     #[ORM\Column(type'integer'nullabletrue)]
  51.     private $outOfStockQuantity;
  52.     #[ORM\Column(type'date_immutable'nullabletrue)]
  53.     private $lowestOutOfStockAt;
  54.     #[ORM\Column(type'integer'nullabletrue)]
  55.     private $lowestOutOfStockQuantity;
  56.     public function __construct()
  57.     {
  58.         parent::__construct();
  59.         $this->paperProducts = new ArrayCollection();
  60.         $this->paperStocks = new ArrayCollection();
  61.         $this->paperStockGroups = new ArrayCollection();
  62.     }
  63.     public function __toString()
  64.     {
  65.         $name $this->getReference();
  66.         if ($this->getArchived()) $name .= " (archivĂ©)";
  67.         return $name;
  68.     }
  69.     public function getOutOfStockAtDisplay() 
  70.     { 
  71.         return $this->getOutOfStockDisplay($this->getOutOfStockAt());
  72.     }
  73.     public function getLowestOutOfStockAtDisplay() 
  74.     { 
  75.         return $this->getOutOfStockDisplay($this->getLowestOutOfStockAt());
  76.     }
  77.     public function getOutOfStockDisplay($outOfStockAt
  78.     {   
  79.         if (!$outOfStockAt) return null;
  80.         $outOfStockAt $outOfStockAt->setTime(0,0,0);
  81.         $now = (new \DateTimeImmutable())->setTime(0,0,0);
  82.         $interval $now->diff($outOfStockAt);
  83.         return $interval->format('%a') . 'J';
  84.         
  85.     }
  86.     public function getPaperQualityDisplay()
  87.     {
  88.         return $this->getPaperQuality() == Provider::QUALITY_PEFC 'PEFC' 'FSC';
  89.     }
  90.     public function setQuantity(int $quantity): self
  91.     {
  92.         $this->quantity $quantity;
  93.         $this->setOutOfStock($quantity <= $this->getQuantityMin());
  94.         return $this;
  95.     }
  96.     public function setPriceUnity(string $priceUnity): self
  97.     {
  98.         $this->priceUnity $priceUnity;
  99.         if(null === $this->getPriceUnityInitial()) $this->priceUnityInitial $priceUnity;
  100.         return $this;
  101.     }
  102.     public function isStockInDanger(): bool
  103.     {
  104.         return $this->getOutOfStock() || $this->getOutOfStockAt();
  105.     }
  106.     public function getStatusDisplay(): string
  107.     {   
  108.         if($this->getOutOfStock()) return 'Rupture';
  109.         return $this->getOutOfStockAt() ? 'Rupture le ' $this->getOutOfStockAt()->format('d/m/Y') : 'En stock';
  110.     }
  111.     // ##################################################################### //
  112.     // ##################################################################### //
  113.     // ##################################################################### //
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getReference(): ?string
  119.     {
  120.         return $this->reference;
  121.     }
  122.     public function setReference(string $reference): self
  123.     {
  124.         $this->reference $reference;
  125.         return $this;
  126.     }
  127.     public function getReferenceInternal(): ?string
  128.     {
  129.         return $this->referenceInternal;
  130.     }
  131.     public function setReferenceInternal(string $referenceInternal): self
  132.     {
  133.         $this->referenceInternal $referenceInternal;
  134.         return $this;
  135.     }
  136.     public function getQuantityMin(): ?int
  137.     {
  138.         return $this->quantityMin;
  139.     }
  140.     public function setQuantityMin(int $quantityMin): self
  141.     {
  142.         $this->quantityMin $quantityMin;
  143.         return $this;
  144.     }
  145.     public function getOutOfStock(): ?bool
  146.     {
  147.         return $this->outOfStock;
  148.     }
  149.     public function setOutOfStock(bool $outOfStock): self
  150.     {
  151.         $this->outOfStock $outOfStock;
  152.         return $this;
  153.     }
  154.     public function getOutOfStockAt(): ?\DateTimeImmutable
  155.     {
  156.         return $this->outOfStockAt;
  157.     }
  158.     public function setOutOfStockAt(?\DateTimeImmutable $outOfStockAt): self
  159.     {
  160.         $this->outOfStockAt $outOfStockAt;
  161.         return $this;
  162.     }
  163.     public function getPriceUnityInitial(): ?string
  164.     {
  165.         return $this->priceUnityInitial;
  166.     }
  167.     public function setPriceUnityInitial(string $priceUnityInitial): self
  168.     {
  169.         $this->priceUnityInitial $priceUnityInitial;
  170.         return $this;
  171.     }
  172.     public function getProvider(): ?Provider
  173.     {
  174.         return $this->provider;
  175.     }
  176.     public function setProvider(?Provider $provider): self
  177.     {
  178.         $this->provider $provider;
  179.         $this->setPaperQuality($this->getProvider()->getPaperQuality());
  180.         $this->setPaperQualityPercent($this->getProvider()->getPaperQualityPercent());
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection|PaperProduct[]
  185.      */
  186.     public function getPaperProducts(): Collection
  187.     {
  188.         return $this->paperProducts;
  189.     }
  190.     public function addPaperProduct(PaperProduct $paperProduct): self
  191.     {
  192.         if (!$this->paperProducts->contains($paperProduct)) {
  193.             $this->paperProducts[] = $paperProduct;
  194.             $paperProduct->setPaper($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removePaperProduct(PaperProduct $paperProduct): self
  199.     {
  200.         if ($this->paperProducts->removeElement($paperProduct)) {
  201.             // set the owning side to null (unless already changed)
  202.             if ($paperProduct->getPaper() === $this) {
  203.                 $paperProduct->setPaper(null);
  204.             }
  205.         }
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return Collection|PaperStock[]
  210.      */
  211.     public function getPaperStocks(): Collection
  212.     {
  213.         return $this->paperStocks;
  214.     }
  215.     public function addPaperStock(PaperStock $paperStock): self
  216.     {
  217.         if (!$this->paperStocks->contains($paperStock)) {
  218.             $this->paperStocks[] = $paperStock;
  219.             $paperStock->setPaper($this);
  220.         }
  221.         return $this;
  222.     }
  223.     public function removePaperStock(PaperStock $paperStock): self
  224.     {
  225.         if ($this->paperStocks->removeElement($paperStock)) {
  226.             // set the owning side to null (unless already changed)
  227.             if ($paperStock->getPaper() === $this) {
  228.                 $paperStock->setPaper(null);
  229.             }
  230.         }
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection|PaperStockGroup[]
  235.      */
  236.     public function getPaperStockGroups(): Collection
  237.     {
  238.         return $this->paperStockGroups;
  239.     }
  240.     public function addPaperStockGroup(PaperStockGroup $paperStockGroup): self
  241.     {
  242.         if (!$this->paperStockGroups->contains($paperStockGroup)) {
  243.             $this->paperStockGroups[] = $paperStockGroup;
  244.             $paperStockGroup->setPaper($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removePaperStockGroup(PaperStockGroup $paperStockGroup): self
  249.     {
  250.         if ($this->paperStockGroups->removeElement($paperStockGroup)) {
  251.             // set the owning side to null (unless already changed)
  252.             if ($paperStockGroup->getPaper() === $this) {
  253.                 $paperStockGroup->setPaper(null);
  254.             }
  255.         }
  256.         return $this;
  257.     }
  258.     public function getPaperQuality(): ?int
  259.     {
  260.         return $this->paperQuality;
  261.     }
  262.     public function setPaperQuality(int $paperQuality): self
  263.     {
  264.         $this->paperQuality $paperQuality;
  265.         return $this;
  266.     }
  267.     public function getPaperQualityPercent(): ?int
  268.     {
  269.         return $this->paperQualityPercent;
  270.     }
  271.     public function setPaperQualityPercent(int $paperQualityPercent): self
  272.     {
  273.         $this->paperQualityPercent $paperQualityPercent;
  274.         return $this;
  275.     }
  276.     public function getPaperCategory(): ?PaperCategory
  277.     {
  278.         return $this->paperCategory;
  279.     }
  280.     public function setPaperCategory(?PaperCategory $paperCategory): self
  281.     {
  282.         $this->paperCategory $paperCategory;
  283.         return $this;
  284.     }
  285.     public function getOutOfStockQuantity(): ?int
  286.     {
  287.         return $this->outOfStockQuantity;
  288.     }
  289.     public function setOutOfStockQuantity(?int $outOfStockQuantity): self
  290.     {
  291.         $this->outOfStockQuantity $outOfStockQuantity;
  292.         return $this;
  293.     }
  294.     public function getLowestOutOfStockAt(): ?\DateTimeImmutable
  295.     {
  296.         return $this->lowestOutOfStockAt;
  297.     }
  298.     public function setLowestOutOfStockAt(?\DateTimeImmutable $lowestOutOfStockAt): self
  299.     {
  300.         $this->lowestOutOfStockAt $lowestOutOfStockAt;
  301.         return $this;
  302.     }
  303.     public function getLowestOutOfStockQuantity(): ?int
  304.     {
  305.         return $this->lowestOutOfStockQuantity;
  306.     }
  307.     public function setLowestOutOfStockQuantity(?int $lowestOutOfStockQuantity): self
  308.     {
  309.         $this->lowestOutOfStockQuantity $lowestOutOfStockQuantity;
  310.         return $this;
  311.     }
  312.  
  313. }