src/Entity/Produit.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProduitRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JsonSerializable;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ORM\Entity(repositoryClass=ProduitRepository::class)
  11.  */
  12. class Produit implements JsonSerializable
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     private $isNew false;
  21.     private $stock 0;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $reference;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $name;
  30.     /**
  31.      *
  32.      * @ORM\Column(type="text", nullable=true)
  33.      */
  34.     private $description;
  35.     /**
  36.      * @ORM\Column(type="integer")
  37.      */
  38.     private $usual_quantity;
  39.     /**
  40.      * @ORM\Column(type="float")
  41.      */
  42.     private $buying_price;
  43.     /**
  44.      *
  45.      * @ORM\Column(type="float")
  46.      */
  47.     private $price_ht;
  48.     /**
  49.      *
  50.      * @ORM\Column(type="float")
  51.      */
  52.     private $price_ttc;
  53.     /**
  54.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="produits")
  55.      */
  56.     private $categories;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity=Tva::class, inversedBy="produits")
  59.      */
  60.     private $tva;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="produits")
  63.      */
  64.     private $tags;
  65.     /**
  66.      * @ORM\Column(type="string", length=255)
  67.      */
  68.     private $unit;
  69.     /**
  70.      * @ORM\Column(type="boolean")
  71.      */
  72.     private $isStock;
  73.     /**
  74.      * @ORM\Column(type="boolean")
  75.      */
  76.     private $isDeclination;
  77.     /**
  78.      * @ORM\Column(type="datetime")
  79.      */
  80.     private $createdAt;
  81.     /**
  82.      * @ORM\ManyToMany(targetEntity=Declination::class, mappedBy="Produits")
  83.      */
  84.     private $declinations;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity=ProduitDeclinationValue::class, mappedBy="produit", orphanRemoval=true)
  87.      */
  88.     private $produitDeclinationValues;
  89.     /**
  90.      *
  91.      * @ORM\ManyToMany(targetEntity=File::class, cascade={"persist"})
  92.      */
  93.     private $picture;
  94.     public $image;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity=DocumentProduit::class, mappedBy="produit")
  97.      */
  98.     private $documentProduits;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="produit")
  101.      */
  102.     private $stocks;
  103.     /**
  104.      * @ORM\Column(type="integer", nullable=true)
  105.      */
  106.     private $uuid;
  107.     /**
  108.      * @ORM\ManyToOne(targetEntity=Promotion::class, inversedBy="produits")
  109.      */
  110.     private $promotion;
  111.     /**
  112.      * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="produit")
  113.      */
  114.     private $activities;
  115.     /**
  116.      * @ORM\Column(type="text", nullable=true)
  117.      */
  118.     private $information;
  119.     /**
  120.      * @ORM\Column(type="boolean", nullable=true)
  121.      */
  122.     private $isArchived;
  123.     /**
  124.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="produit")
  125.      */
  126.     private $comments;
  127. //    /**
  128. //     * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="produitsCategory")
  129. //     */
  130. //    private $principalCategory;
  131.     /**
  132.      * @ORM\Column(type="datetime", nullable=true)
  133.      */
  134.     private $deletedAt;
  135.     /**
  136.      * @ORM\Column(type="text", nullable=true)
  137.      */
  138.     private $reasonOfDelete;
  139.     public function __construct()
  140.     {
  141.         $this->tags = new ArrayCollection();
  142.         $this->declinations = new ArrayCollection();
  143.         $this->produitDeclinationValues = new ArrayCollection();
  144.         $this->picture = new ArrayCollection();
  145.         $this->documentProduits = new ArrayCollection();
  146.         $this->stocks = new ArrayCollection();
  147.         $this->activities = new ArrayCollection();
  148.         $this->comments = new ArrayCollection();
  149.     }
  150.     public function getImage(): ?string
  151.     {
  152.         return $this->image;
  153.     }
  154.     public function getId(): ?int
  155.     {
  156.         return $this->id;
  157.     }
  158.     public function getReference(): ?string
  159.     {
  160.         return $this->reference;
  161.     }
  162.     public function setReference(string $reference): self
  163.     {
  164.         $this->reference $reference;
  165.         return $this;
  166.     }
  167.     public function getName(): ?string
  168.     {
  169.         return $this->name;
  170.     }
  171.     public function setName(string $name): self
  172.     {
  173.         $this->name $name;
  174.         return $this;
  175.     }
  176.     public function getDescription(): ?string
  177.     {
  178.         return $this->description;
  179.     }
  180.     public function setDescription(?string $description): self
  181.     {
  182.         $this->description $description;
  183.         return $this;
  184.     }
  185.     public function getUsualQuantity(): ?int
  186.     {
  187.         return $this->usual_quantity;
  188.     }
  189.     public function setUsualQuantity(int $usual_quantity): self
  190.     {
  191.         $this->usual_quantity $usual_quantity;
  192.         return $this;
  193.     }
  194.     public function getBuyingPrice(): ?float
  195.     {
  196.         return $this->buying_price;
  197.     }
  198.     public function setBuyingPrice(float $buying_price): self
  199.     {
  200.         $this->buying_price $buying_price;
  201.         return $this;
  202.     }
  203.     public function getPriceHt(): ?float
  204.     {
  205.         return (float) $this->price_ht;
  206.     }
  207.     public function setPriceHt(float $price_ht): self
  208.     {
  209.         $this->price_ht $price_ht;
  210.         return $this;
  211.     }
  212.     public function getPriceTtc(): ?float
  213.     {
  214.         return $this->price_ttc;
  215.     }
  216.     public function setPriceTtc(float $price_ttc): self
  217.     {
  218.         $this->price_ttc $price_ttc;
  219.         return $this;
  220.     }
  221.     public function getCategories(): ?Category
  222.     {
  223.         return $this->categories;
  224.     }
  225.     public function setCategories(?Category $categories): self
  226.     {
  227.         $this->categories $categories;
  228.         return $this;
  229.     }
  230.     public function getTva(): ?Tva
  231.     {
  232.         return $this->tva;
  233.     }
  234.     public function setTva(?Tva $tva): self
  235.     {
  236.         $this->tva $tva;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection|Tag[]
  241.      */
  242.     public function getTags(): Collection
  243.     {
  244.         return $this->tags;
  245.     }
  246.     public function addTag(Tag $tag): self
  247.     {
  248.         if (!$this->tags->contains($tag)) {
  249.             $this->tags[] = $tag;
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeTag(Tag $tag): self
  254.     {
  255.         $this->tags->removeElement($tag);
  256.         return $this;
  257.     }
  258.     public function getUnit(): ?string
  259.     {
  260.         return $this->unit;
  261.     }
  262.     public function setUnit(string $unit): self
  263.     {
  264.         $this->unit $unit;
  265.         return $this;
  266.     }
  267.     public function getIsStock(): ?bool
  268.     {
  269.         return $this->isStock;
  270.     }
  271.     public function setIsStock(bool $isStock): self
  272.     {
  273.         $this->isStock $isStock;
  274.         return $this;
  275.     }
  276.     public function getIsDeclination(): ?bool
  277.     {
  278.         return $this->isDeclination;
  279.     }
  280.     public function setIsDeclination(bool $isDeclination): self
  281.     {
  282.         $this->isDeclination $isDeclination;
  283.         return $this;
  284.     }
  285.     public function getCreatedAt(): ?\DateTimeInterface
  286.     {
  287.         return $this->createdAt;
  288.     }
  289.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  290.     {
  291.         $this->createdAt $createdAt;
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection|Declination[]
  296.      */
  297.     public function getDeclinations(): Collection
  298.     {
  299.         return $this->declinations;
  300.     }
  301.     public function addDeclination(Declination $declination): self
  302.     {
  303.         if (!$this->declinations->contains($declination)) {
  304.             $this->declinations[] = $declination;
  305.             $declination->addProduit($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeDeclination(Declination $declination): self
  310.     {
  311.         if ($this->declinations->removeElement($declination)) {
  312.             $declination->removeProduit($this);
  313.         }
  314.         return $this;
  315.     }
  316.     /**
  317.      * @return Collection|ProduitDeclinationValue[]
  318.      */
  319.     public function getProduitDeclinationValues(): Collection
  320.     {
  321.         return $this->produitDeclinationValues;
  322.     }
  323.     public function addProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  324.     {
  325.         if (!$this->produitDeclinationValues->contains($produitDeclinationValue)) {
  326.             $this->produitDeclinationValues[] = $produitDeclinationValue;
  327.             $produitDeclinationValue->setProduit($this);
  328.         }
  329.         return $this;
  330.     }
  331.     public function removeProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  332.     {
  333.         if ($this->produitDeclinationValues->removeElement($produitDeclinationValue)) {
  334.             // set the owning side to null (unless already changed)
  335.             if ($produitDeclinationValue->getProduit() === $this) {
  336.                 $produitDeclinationValue->setProduit(null);
  337.             }
  338.         }
  339.         return $this;
  340.     }
  341.     /**
  342.      * @return Collection|File[]
  343.      */
  344.     public function getPicture(): Collection
  345.     {
  346.         return $this->picture;
  347.     }
  348.     public function addPicture(File $picture): self
  349.     {
  350.         if (!$this->picture->contains($picture))
  351.             $this->picture[] = $picture;
  352.         return $this;
  353.     }
  354.     public function removePicture(File $picture): self
  355.     {
  356.         $this->picture->removeElement($picture);
  357.         return $this;
  358.     }
  359.     /**
  360.      * @return Collection|DocumentProduit[]
  361.      */
  362.     public function getDocumentProduits(): Collection
  363.     {
  364.         return $this->documentProduits;
  365.     }
  366.     public function addDocumentProduit(DocumentProduit $documentProduit): self
  367.     {
  368.         if (!$this->documentProduits->contains($documentProduit)) {
  369.             $this->documentProduits[] = $documentProduit;
  370.             $documentProduit->setProduit($this);
  371.         }
  372.         return $this;
  373.     }
  374.     public function removeDocumentProduit(DocumentProduit $documentProduit): self
  375.     {
  376.         if ($this->documentProduits->removeElement($documentProduit))
  377.             // set the owning side to null (unless already changed)
  378.             if ($documentProduit->getProduit() === $this)
  379.                 $documentProduit->setProduit(null);
  380.         return $this;
  381.     }
  382.     /**
  383.      * @return Collection|Stock[]
  384.      */
  385.     public function getStocks(): Collection
  386.     {
  387.         return $this->stocks;
  388.     }
  389.     public function addStock(Stock $stock): self
  390.     {
  391.         if (!$this->stocks->contains($stock)) {
  392.             $this->stocks[] = $stock;
  393.             $stock->setProduit($this);
  394.         }
  395.         return $this;
  396.     }
  397.     public function removeStock(Stock $stock): self
  398.     {
  399.         if ($this->stocks->removeElement($stock))
  400.             // set the owning side to null (unless already changed)
  401.             if ($stock->getProduit() === $this)
  402.                 $stock->setProduit(null);
  403.         return $this;
  404.     }
  405.     public function getUuid(): ?int
  406.     {
  407.         return $this->uuid;
  408.     }
  409.     public function setUuid(?int $uuid): self
  410.     {
  411.         $this->uuid $uuid;
  412.         return $this;
  413.     }
  414.     public function getPromotion(): ?Promotion
  415.     {
  416.         return $this->promotion;
  417.     }
  418.     public function setPromotion(?Promotion $promotion): self
  419.     {
  420.         $this->promotion $promotion;
  421.         return $this;
  422.     }
  423.     /**
  424.      * @return Collection|Activity[]
  425.      */
  426.     public function getActivities(): Collection
  427.     {
  428.         return $this->activities;
  429.     }
  430.     public function addActivity(Activity $activity): self
  431.     {
  432.         if (!$this->activities->contains($activity)) {
  433.             $this->activities[] = $activity;
  434.             $activity->setProduit($this);
  435.         }
  436.         return $this;
  437.     }
  438.     public function removeActivity(Activity $activity): self
  439.     {
  440.         if ($this->activities->removeElement($activity))
  441.             // set the owning side to null (unless already changed)
  442.             if ($activity->getProduit() === $this)
  443.                 $activity->setProduit(null);
  444.         return $this;
  445.     }
  446.     public function getInformation(): ?string
  447.     {
  448.         return $this->information;
  449.     }
  450.     public function setInformation(?string $information): self
  451.     {
  452.         $this->information $information;
  453.         return $this;
  454.     }
  455.     public function getIsArchived(): ?bool
  456.     {
  457.         return $this->isArchived;
  458.     }
  459.     public function setIsArchived(?bool $isArchived): self
  460.     {
  461.         $this->isArchived $isArchived;
  462.         return $this;
  463.     }
  464.     /**
  465.      * @return Collection|Comment[]
  466.      */
  467.     public function getComments(): Collection
  468.     {
  469.         return $this->comments;
  470.     }
  471.     public function addComment(Comment $comment): self
  472.     {
  473.         if (!$this->comments->contains($comment)) {
  474.             $this->comments[] = $comment;
  475.             $comment->setProduit($this);
  476.         }
  477.         return $this;
  478.     }
  479.     public function removeComment(Comment $comment): self
  480.     {
  481.         if ($this->comments->removeElement($comment))
  482.             // set the owning side to null (unless already changed)
  483.             if ($comment->getProduit() === $this)
  484.                 $comment->setProduit(null);
  485.         return $this;
  486.     }
  487.     public function getIsNew(): ?bool
  488.     {
  489.         return $this->isNew;
  490.     }
  491.     public function setIsNew(bool $isNew): self
  492.     {
  493.         $this->isNew $isNew;
  494.         return $this;
  495.     }
  496.     public function getStock(): ?int
  497.     {
  498.         foreach ($this->getStocks() as $stock) {
  499.             $this->stock += $stock->getQtAvailable() - $stock->getQtReserved();
  500.         }
  501.         return $this->stock;
  502.     }
  503.     public function setStock($stock): self
  504.     {
  505.         $this->stock $stock;
  506.         return $this;
  507.     }
  508.     public function isNew()
  509.     {
  510.         // On va chercher les produit nouveau dont la date de création ne dépasse pas 90 jours
  511.         $date = new \DateTime('now');
  512.         $date->modify('-90 day');
  513.         if ($this->getCreatedAt() >= $date) {
  514.             $this->setIsNew(true);
  515.         }
  516.         return $this->isNew;
  517.     }
  518.     public function jsonSerialize()
  519.     {
  520.         $tabPictures = [];
  521.         foreach ($this->getPicture() as $picture) {
  522.             array_push($tabPictures$picture->getImageName());
  523.         }
  524.         return array(
  525.             'id' => $this->getId(),
  526.             'name' => $this->getName(),
  527.             'description' => $this->getDescription(),
  528.             'picture' => $tabPictures,
  529.             'image' => $this->getImage(),
  530.             'priceHT' => $this->getPriceHt(),
  531.             'priceTTC' => $this->getPriceTtc(),
  532.             'category' => $this->getCategories() ? $this->getCategories()->getId() : 0,
  533.             //'produitDeclinationValues' => $this->getProduitDeclinationValues()->toArray(),
  534.             'promo' => $this->getPromotion(),
  535.             'isNew' => $this->isNew(),
  536.             'stock' => $this->getStock(),
  537.             //'tags' => $this->getTags()->toArray(),
  538.         );
  539.     }
  540.     public function getPrincipalCategory(): ?Category
  541.     {
  542.         return $this->principalCategory;
  543.     }
  544.     public function setPrincipalCategory(?Category $principalCategory): self
  545.     {
  546.         $this->principalCategory $principalCategory;
  547.         return $this;
  548.     }
  549.     public function getDeletedAt(): ?\DateTimeInterface
  550.     {
  551.         return $this->deletedAt;
  552.     }
  553.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  554.     {
  555.         $this->deletedAt $deletedAt;
  556.         return $this;
  557.     }
  558.     public function getReasonOfDelete(): ?string
  559.     {
  560.         return $this->reasonOfDelete;
  561.     }
  562.     public function setReasonOfDelete(?string $reasonOfDelete): self
  563.     {
  564.         $this->reasonOfDelete $reasonOfDelete;
  565.         return $this;
  566.     }
  567. }