src/Entity/Produit.php line 665

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.     /**
  140.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="produits")
  141.      * @ORM\JoinTable(name="supplier_produit",
  142.      *      joinColumns={@ORM\JoinColumn(name="produit_id", referencedColumnName="id")},
  143.      *      inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
  144.      * )
  145.      */
  146.     private $users;
  147.     /**
  148.      * @ORM\Column(type="boolean", nullable=true)
  149.      */
  150.     private $bestSelection;
  151.     /**
  152.      * @ORM\Column(type="boolean", options={"default" : true})
  153.      */
  154.     private $showInWebSite;
  155.     public function __construct()
  156.     {
  157.         $this->tags = new ArrayCollection();
  158.         $this->declinations = new ArrayCollection();
  159.         $this->produitDeclinationValues = new ArrayCollection();
  160.         $this->picture = new ArrayCollection();
  161.         $this->documentProduits = new ArrayCollection();
  162.         $this->stocks = new ArrayCollection();
  163.         $this->activities = new ArrayCollection();
  164.         $this->comments = new ArrayCollection();
  165.         $this->users = new ArrayCollection();
  166.     }
  167.     public function getImage(): ?string
  168.     {
  169.         return $this->image;
  170.     }
  171.     public function getId(): ?int
  172.     {
  173.         return $this->id;
  174.     }
  175.     public function getReference(): ?string
  176.     {
  177.         return $this->reference;
  178.     }
  179.     public function setReference(string $reference): self
  180.     {
  181.         $this->reference $reference;
  182.         return $this;
  183.     }
  184.     public function getName(): ?string
  185.     {
  186.         return $this->name;
  187.     }
  188.     public function setName(string $name): self
  189.     {
  190.         $this->name $name;
  191.         return $this;
  192.     }
  193.     public function getDescription(): ?string
  194.     {
  195.         return $this->description;
  196.     }
  197.     public function setDescription(?string $description): self
  198.     {
  199.         $this->description $description;
  200.         return $this;
  201.     }
  202.     public function getUsualQuantity(): ?int
  203.     {
  204.         return $this->usual_quantity;
  205.     }
  206.     public function setUsualQuantity(int $usual_quantity): self
  207.     {
  208.         $this->usual_quantity $usual_quantity;
  209.         return $this;
  210.     }
  211.     public function getBuyingPrice(): ?float
  212.     {
  213.         return $this->buying_price;
  214.     }
  215.     public function setBuyingPrice(float $buying_price): self
  216.     {
  217.         $this->buying_price $buying_price;
  218.         return $this;
  219.     }
  220.     public function getPriceHt(): ?float
  221.     {
  222.         return (float) $this->price_ht;
  223.     }
  224.     public function setPriceHt(float $price_ht): self
  225.     {
  226.         $this->price_ht $price_ht;
  227.         return $this;
  228.     }
  229.     public function getPriceTtc(): ?float
  230.     {
  231.         return $this->price_ttc;
  232.     }
  233.     public function setPriceTtc(float $price_ttc): self
  234.     {
  235.         $this->price_ttc $price_ttc;
  236.         return $this;
  237.     }
  238.     public function getCategories(): ?Category
  239.     {
  240.         return $this->categories;
  241.     }
  242.     public function setCategories(?Category $categories): self
  243.     {
  244.         $this->categories $categories;
  245.         return $this;
  246.     }
  247.     public function getTva(): ?Tva
  248.     {
  249.         return $this->tva;
  250.     }
  251.     public function setTva(?Tva $tva): self
  252.     {
  253.         $this->tva $tva;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return Collection|Tag[]
  258.      */
  259.     public function getTags(): Collection
  260.     {
  261.         return $this->tags;
  262.     }
  263.     public function addTag(Tag $tag): self
  264.     {
  265.         if( !$this->tags->contains($tag)) {
  266.             $this->tags[] = $tag;
  267.         }
  268.         return $this;
  269.     }
  270.     public function removeTag(Tag $tag): self
  271.     {
  272.         $this->tags->removeElement($tag);
  273.         return $this;
  274.     }
  275.     public function getUnit(): ?string
  276.     {
  277.         return $this->unit;
  278.     }
  279.     public function setUnit(string $unit): self
  280.     {
  281.         $this->unit $unit;
  282.         return $this;
  283.     }
  284.     public function getIsStock(): ?bool
  285.     {
  286.         return $this->isStock;
  287.     }
  288.     public function setIsStock(bool $isStock): self
  289.     {
  290.         $this->isStock $isStock;
  291.         return $this;
  292.     }
  293.     public function getIsDeclination(): ?bool
  294.     {
  295.         return $this->isDeclination;
  296.     }
  297.     public function setIsDeclination(bool $isDeclination): self
  298.     {
  299.         $this->isDeclination $isDeclination;
  300.         return $this;
  301.     }
  302.     public function getCreatedAt(): ?\DateTimeInterface
  303.     {
  304.         return $this->createdAt;
  305.     }
  306.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  307.     {
  308.         $this->createdAt $createdAt;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection|Declination[]
  313.      */
  314.     public function getDeclinations(): Collection
  315.     {
  316.         return $this->declinations;
  317.     }
  318.     public function addDeclination(Declination $declination): self
  319.     {
  320.         if( !$this->declinations->contains($declination)) {
  321.             $this->declinations[] = $declination;
  322.             $declination->addProduit($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeDeclination(Declination $declination): self
  327.     {
  328.         if( $this->declinations->removeElement($declination)) {
  329.             $declination->removeProduit($this);
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return Collection|ProduitDeclinationValue[]
  335.      */
  336.     public function getProduitDeclinationValues(): Collection
  337.     {
  338.         return $this->produitDeclinationValues;
  339.     }
  340.     public function addProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  341.     {
  342.         if( !$this->produitDeclinationValues->contains($produitDeclinationValue)) {
  343.             $this->produitDeclinationValues[] = $produitDeclinationValue;
  344.             $produitDeclinationValue->setProduit($this);
  345.         }
  346.         return $this;
  347.     }
  348.     public function removeProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  349.     {
  350.         if( $this->produitDeclinationValues->removeElement($produitDeclinationValue)) {
  351.             // set the owning side to null (unless already changed)
  352.             if( $produitDeclinationValue->getProduit() === $this) {
  353.                 $produitDeclinationValue->setProduit(null);
  354.             }
  355.         }
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Collection|File[]
  360.      */
  361.     public function getPicture(): Collection
  362.     {
  363.         return $this->picture;
  364.     }
  365.     public function addPicture(File $picture): self
  366.     {
  367.         if( !$this->picture->contains($picture))
  368.             $this->picture[] = $picture;
  369.         return $this;
  370.     }
  371.     public function removePicture(File $picture): self
  372.     {
  373.         $this->picture->removeElement($picture);
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection|DocumentProduit[]
  378.      */
  379.     public function getDocumentProduits(): Collection
  380.     {
  381.         return $this->documentProduits;
  382.     }
  383.     public function addDocumentProduit(DocumentProduit $documentProduit): self
  384.     {
  385.         if( !$this->documentProduits->contains($documentProduit)) {
  386.             $this->documentProduits[] = $documentProduit;
  387.             $documentProduit->setProduit($this);
  388.         }
  389.         return $this;
  390.     }
  391.     public function removeDocumentProduit(DocumentProduit $documentProduit): self
  392.     {
  393.         if( $this->documentProduits->removeElement($documentProduit))
  394.             // set the owning side to null (unless already changed)
  395.             if( $documentProduit->getProduit() === $this)
  396.                 $documentProduit->setProduit(null);
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection|Stock[]
  401.      */
  402.     public function getStocks(): Collection
  403.     {
  404.         return $this->stocks;
  405.     }
  406.     public function addStock(Stock $stock): self
  407.     {
  408.         if( !$this->stocks->contains($stock)) {
  409.             $this->stocks[] = $stock;
  410.             $stock->setProduit($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeStock(Stock $stock): self
  415.     {
  416.         if( $this->stocks->removeElement($stock))
  417.             // set the owning side to null (unless already changed)
  418.             if( $stock->getProduit() === $this)
  419.                 $stock->setProduit(null);
  420.         return $this;
  421.     }
  422.     public function getUuid(): ?int
  423.     {
  424.         return $this->uuid;
  425.     }
  426.     public function setUuid(?int $uuid): self
  427.     {
  428.         $this->uuid $uuid;
  429.         return $this;
  430.     }
  431.     public function getPromotion(): ?Promotion
  432.     {
  433.         return $this->promotion;
  434.     }
  435.     public function setPromotion(?Promotion $promotion): self
  436.     {
  437.         $this->promotion $promotion;
  438.         return $this;
  439.     }
  440.     /**
  441.      * @return Collection|Activity[]
  442.      */
  443.     public function getActivities(): Collection
  444.     {
  445.         return $this->activities;
  446.     }
  447.     public function addActivity(Activity $activity): self
  448.     {
  449.         if( !$this->activities->contains($activity)) {
  450.             $this->activities[] = $activity;
  451.             $activity->setProduit($this);
  452.         }
  453.         return $this;
  454.     }
  455.     public function removeActivity(Activity $activity): self
  456.     {
  457.         if( $this->activities->removeElement($activity))
  458.             // set the owning side to null (unless already changed)
  459.             if( $activity->getProduit() === $this)
  460.                 $activity->setProduit(null);
  461.         return $this;
  462.     }
  463.     public function getInformation(): ?string
  464.     {
  465.         return $this->information;
  466.     }
  467.     public function setInformation(?string $information): self
  468.     {
  469.         $this->information $information;
  470.         return $this;
  471.     }
  472.     public function getIsArchived(): ?bool
  473.     {
  474.         return $this->isArchived;
  475.     }
  476.     public function setIsArchived(?bool $isArchived): self
  477.     {
  478.         $this->isArchived $isArchived;
  479.         return $this;
  480.     }
  481.     /**
  482.      * @return Collection|Comment[]
  483.      */
  484.     public function getComments(): Collection
  485.     {
  486.         return $this->comments;
  487.     }
  488.     public function addComment(Comment $comment): self
  489.     {
  490.         if( !$this->comments->contains($comment)) {
  491.             $this->comments[] = $comment;
  492.             $comment->setProduit($this);
  493.         }
  494.         return $this;
  495.     }
  496.     public function removeComment(Comment $comment): self
  497.     {
  498.         if( $this->comments->removeElement($comment))
  499.             // set the owning side to null (unless already changed)
  500.             if( $comment->getProduit() === $this)
  501.                 $comment->setProduit(null);
  502.         return $this;
  503.     }
  504.     public function getIsNew(): ?bool
  505.     {
  506.         return $this->isNew;
  507.     }
  508.     public function setIsNew(bool $isNew): self
  509.     {
  510.         $this->isNew $isNew;
  511.         return $this;
  512.     }
  513.     public function getStock(): ?int
  514.     {
  515.         foreach ($this->getStocks() as $stock) {
  516.             $this->stock += $stock->getQtAvailable() - $stock->getQtReserved();
  517.         }
  518.         return $this->stock;
  519.     }
  520.     public function setStock($stock): self
  521.     {
  522.         $this->stock $stock;
  523.         return $this;
  524.     }
  525.     public function isNew()
  526.     {
  527.         // On va chercher les produit nouveau dont la date de création ne dépasse pas 90 jours
  528.         $date = new \DateTime('now');
  529.         $date->modify('-90 day');
  530.         if( $this->getCreatedAt() >= $date) {
  531.             $this->setIsNew(true);
  532.         }
  533.         return $this->isNew;
  534.     }
  535.     public function getBestSelection(): ?bool
  536.     {
  537.         return $this->bestSelection;
  538.     }
  539.     public function setBestSelection(bool $bestSelection): self
  540.     {
  541.         $this->bestSelection $bestSelection;
  542.         return $this;
  543.     }
  544.     public function jsonSerialize()
  545.     {
  546.         $tabPictures = [];
  547.         foreach ($this->getPicture() as $picture) {
  548.             array_push($tabPictures$picture->getImageName());
  549.         }
  550.         return array(
  551.             'id' => $this->getId(),
  552.             'name' => $this->getName(),
  553.             'description' => $this->getDescription(),
  554.             'specification' => $this->getInformation(),
  555.             'picture' => $tabPictures,
  556.             'image' => $this->getImage(),
  557.             'priceHT' => $this->getPriceHt(),
  558.             'priceTTC' => $this->getPriceTtc(),
  559.             'category' => $this->getCategories() ? $this->getCategories()->getId() : 0,
  560.             //'produitDeclinationValues' => $this->getProduitDeclinationValues()->toArray(),
  561.             'promo' => $this->getPromotion(),
  562.             'isNew' => $this->isNew(),
  563.             'stock' => $this->getStock(),
  564.             //'tags' => $this->getTags()->toArray(),
  565.         );
  566.     }
  567.     public function getPrincipalCategory(): ?Category
  568.     {
  569.         return $this->principalCategory;
  570.     }
  571.     public function setPrincipalCategory(?Category $principalCategory): self
  572.     {
  573.         $this->principalCategory $principalCategory;
  574.         return $this;
  575.     }
  576.     public function getDeletedAt(): ?\DateTimeInterface
  577.     {
  578.         return $this->deletedAt;
  579.     }
  580.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  581.     {
  582.         $this->deletedAt $deletedAt;
  583.         return $this;
  584.     }
  585.     public function getReasonOfDelete(): ?string
  586.     {
  587.         return $this->reasonOfDelete;
  588.     }
  589.     public function setReasonOfDelete(?string $reasonOfDelete): self
  590.     {
  591.         $this->reasonOfDelete $reasonOfDelete;
  592.         return $this;
  593.     }
  594.     /**
  595.      * @return Collection|User[]
  596.      */
  597.     public function getUsers(): Collection
  598.     {
  599.         return $this->users;
  600.     }
  601.     public function addUser(User $user): self
  602.     {
  603.         if( !$this->users->contains($user)) {
  604.             $this->users[] = $user;
  605.         }
  606.         return $this;
  607.     }
  608.     public function removeUser(User $user): self
  609.     {
  610.         if( $this->users->contains($user)) {
  611.             $this->users->removeElement($user);
  612.         }
  613.         return $this;
  614.     }
  615.     public function getShowInWebsite(): ?bool
  616.     {
  617.         return $this->showInWebSite;
  618.     }
  619.     public function setShowInWebSite(?bool $showInWebSite): self
  620.     {
  621.         $this->showInWebSite $showInWebSite;
  622.         return $this;
  623.     }
  624. }