src/Entity/Produit.php line 764

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. use App\Entity\ProduitPromotionHistory;
  10. /**
  11.  * @ORM\Entity(repositoryClass=ProduitRepository::class)
  12.  */
  13. class Produit implements JsonSerializable
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     private $isNew false;
  22.     private $stock 0;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $reference;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $name;
  31.     /**
  32.      *
  33.      * @ORM\Column(type="text", nullable=true)
  34.      */
  35.     private $description;
  36.     /**
  37.      * @ORM\Column(type="integer")
  38.      */
  39.     private $usual_quantity;
  40.     /**
  41.      * @ORM\Column(name="buying_price_ht", type="decimal", precision=12, scale=3, options={"comment":"Prix d'achat HT (référence marge)"})
  42.      */
  43.     private string $buyingPriceHt '0.000';
  44.     /**
  45.      * @ORM\Column(name="buying_price_ttc", type="decimal", precision=12, scale=3, options={"comment":"Prix d'achat TTC (héritage)"})
  46.      */
  47.     private string $buyingPriceTtc '0.000';
  48.     public function getBuyingPriceTtc(): ?float
  49.     {
  50.         return $this->buyingPriceTtc;
  51.     }
  52.     public function setBuyingPriceTtc(float $buyingPriceTtc): self
  53.     {
  54.         $this->buyingPriceTtc $buyingPriceTtc;
  55.         return $this;
  56.     }
  57.     
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=Tva::class) @ORM\JoinColumn(name="buy_tva_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  60.      */
  61.     private ?Tva $tvaBuy null;
  62.     /**
  63.      *
  64.      * @ORM\Column(type="float")
  65.      */
  66.     private $price_ht;
  67.     /**
  68.      *
  69.      * @ORM\Column(type="float")
  70.      */
  71.     private $price_ttc;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="produits")
  74.      */
  75.     private $categories;
  76.     /**
  77.      * @ORM\ManyToOne(targetEntity=Tva::class, inversedBy="produits")
  78.      */
  79.     private $tva;
  80.     /**
  81.      * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="produits")
  82.      */
  83.     private $tags;
  84.     /**
  85.      * @ORM\Column(type="string", length=255)
  86.      */
  87.     private $unit;
  88.     /**
  89.      * @ORM\Column(type="boolean")
  90.      */
  91.     private $isStock;
  92.     /**
  93.      * @ORM\Column(type="boolean")
  94.      */
  95.     private $isDeclination;
  96.     /**
  97.      * @ORM\Column(type="datetime")
  98.      */
  99.     private $createdAt;
  100.     /**
  101.      * @ORM\ManyToMany(targetEntity=Declination::class, mappedBy="Produits")
  102.      */
  103.     private $declinations;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity=ProduitDeclinationValue::class, mappedBy="produit", orphanRemoval=true)
  106.      */
  107.     private $produitDeclinationValues;
  108.     /**
  109.      *
  110.      * @ORM\ManyToMany(targetEntity=File::class, cascade={"persist"})
  111.      */
  112.     private $picture;
  113.     public $image;
  114.     /**
  115.      * @ORM\OneToMany(targetEntity=DocumentProduit::class, mappedBy="produit")
  116.      */
  117.     private $documentProduits;
  118.     /**
  119.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="produit")
  120.      */
  121.     private $stocks;
  122.     /**
  123.      * @ORM\Column(type="integer", nullable=true)
  124.      */
  125.     private $uuid;
  126.     /**
  127.      * @ORM\ManyToOne(targetEntity=Promotion::class, inversedBy="produits")
  128.      */
  129.     private $promotion;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="produit")
  132.      */
  133.     private $activities;
  134.     /**
  135.      * @ORM\Column(type="text", nullable=true)
  136.      */
  137.     private $information;
  138.     /**
  139.      * @ORM\Column(type="boolean", nullable=true)
  140.      */
  141.     private $isArchived;
  142.     /**
  143.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="produit")
  144.      */
  145.     private $comments;
  146. //    /**
  147. //     * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="produitsCategory")
  148. //     */
  149. //    private $principalCategory;
  150.     /**
  151.      * @ORM\Column(type="datetime", nullable=true)
  152.      */
  153.     private $deletedAt;
  154.     /**
  155.      * @ORM\Column(type="text", nullable=true)
  156.      */
  157.     private $reasonOfDelete;
  158.     /**
  159.      * @ORM\ManyToMany(targetEntity=User::class, inversedBy="produits")
  160.      * @ORM\JoinTable(name="supplier_produit",
  161.      *      joinColumns={@ORM\JoinColumn(name="produit_id", referencedColumnName="id")},
  162.      *      inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
  163.      * )
  164.      */
  165.     private $users;
  166.     /**
  167.      * @ORM\Column(type="boolean", nullable=true)
  168.      */
  169.     private $bestSelection;
  170.     /**
  171.      * @ORM\Column(type="string", length=255, nullable=true)
  172.      */
  173.     private ?string $material null;
  174.     
  175.     /**
  176.      * @ORM\ManyToOne(targetEntity=Supplier::class)
  177.      * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=true)
  178.      */
  179.     private $supplier;
  180.     /** 
  181.      * @ORM\Column(name="supplier_reference", type="string", length=100, nullable=true)
  182.      */
  183.     private $supplierReference;
  184.     /**
  185.      * @ORM\Column(type="string", length=255, nullable=true)
  186.      */
  187.     private ?string $metaDescription null;
  188.    
  189.     /**
  190.      * @ORM\Column(type="boolean", options={"default" : true})
  191.      */
  192.     private $showInWebSite;
  193.     /** @ORM\OneToMany(
  194.      *   targetEntity=ProduitPromotionHistory::class,
  195.      *   mappedBy="product",
  196.      *   orphanRemoval=true
  197.      * )
  198.      * @ORM\OrderBy({"startedAt":"DESC"})
  199.      */
  200.     private Collection $promotionHistories;
  201.     public function __construct()
  202.     {
  203.         $this->tags = new ArrayCollection();
  204.         $this->declinations = new ArrayCollection();
  205.         $this->produitDeclinationValues = new ArrayCollection();
  206.         $this->picture = new ArrayCollection();
  207.         $this->documentProduits = new ArrayCollection();
  208.         $this->stocks = new ArrayCollection();
  209.         $this->activities = new ArrayCollection();
  210.         $this->comments = new ArrayCollection();
  211.         $this->users = new ArrayCollection();
  212.         $this->promotionHistories = new ArrayCollection();
  213.     }
  214.     public function getImage(): ?string
  215.     {
  216.         return $this->image;
  217.     }
  218.     public function getId(): ?int
  219.     {
  220.         return $this->id;
  221.     }
  222.     public function getReference(): ?string
  223.     {
  224.         return $this->reference;
  225.     }
  226.     public function setReference(string $reference): self
  227.     {
  228.         $this->reference $reference;
  229.         return $this;
  230.     }
  231.     public function getName(): ?string
  232.     {
  233.         return $this->name;
  234.     }
  235.     public function setName(string $name): self
  236.     {
  237.         $this->name $name;
  238.         return $this;
  239.     }
  240.     public function getDescription(): ?string
  241.     {
  242.         return $this->description;
  243.     }
  244.     public function setDescription(?string $description): self
  245.     {
  246.         $this->description $description;
  247.         return $this;
  248.     }
  249.     public function getUsualQuantity(): ?int
  250.     {
  251.         return $this->usual_quantity;
  252.     }
  253.     public function setUsualQuantity(int $usual_quantity): self
  254.     {
  255.         $this->usual_quantity $usual_quantity;
  256.         return $this;
  257.     }
  258.     public function getBuyingPriceHt(): ?float
  259.     {
  260.         return $this->buyingPriceHt;
  261.     }
  262.     public function setBuyingPriceHt(float $buyingPriceHt): self
  263.     {
  264.         $this->buyingPriceHt $buyingPriceHt;
  265.         return $this;
  266.     }
  267.    
  268.     public function getPriceHt(): ?float
  269.     {
  270.         return (float) $this->price_ht;
  271.     }
  272.     public function setPriceHt(float $price_ht): self
  273.     {
  274.         $this->price_ht $price_ht;
  275.         return $this;
  276.     }
  277.     public function getPriceTtc(): ?float
  278.     {
  279.         return $this->price_ttc;
  280.     }
  281.     public function setPriceTtc(float $price_ttc): self
  282.     {
  283.         $this->price_ttc $price_ttc;
  284.         return $this;
  285.     }
  286.     public function getTvaBuy(): ?Tva 
  287.     
  288.         return $this->tvaBuy
  289.     }
  290.     
  291.     public function setTvaBuy(?Tva $tva): self 
  292.     {
  293.          $this->tvaBuy $tva; return $this
  294.     }
  295.     /** @ORM\PrePersist @ORM\PreUpdate */
  296.     public function ensureBuyingCost(): void {
  297.         if ($this->buyingPriceHt === null || $this->buyingPriceHt === '') {
  298.             $rate $this->tvaBuy? (float)$this->tvaBuy->getNumber() : 0.0;
  299.             $ttc  = (float)$this->buyingPriceTtc;
  300.             $this->buyingPriceHt number_format($ttc/(1+$rate/100), 3'.''');
  301.         }
  302.     }
  303.     public function getCategories(): ?Category
  304.     {
  305.         return $this->categories;
  306.     }
  307.     public function setCategories(?Category $categories): self
  308.     {
  309.         $this->categories $categories;
  310.         return $this;
  311.     }
  312.     public function getTva(): ?Tva
  313.     {
  314.         return $this->tva;
  315.     }
  316.     public function setTva(?Tva $tva): self
  317.     {
  318.         $this->tva $tva;
  319.         return $this;
  320.     }
  321.     public function getSupplier(): ?Supplier
  322.     {
  323.         return $this->supplier;
  324.     }
  325.     public function setSupplier(?Supplier $supplier): self
  326.     {
  327.         $this->supplier $supplier;
  328.         return $this;
  329.     }
  330.    
  331.     /**
  332.      * @return Collection|Tag[]
  333.      */
  334.     public function getTags(): Collection
  335.     {
  336.         return $this->tags;
  337.     }
  338.     public function addTag(Tag $tag): self
  339.     {
  340.         if( !$this->tags->contains($tag)) {
  341.             $this->tags[] = $tag;
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeTag(Tag $tag): self
  346.     {
  347.         $this->tags->removeElement($tag);
  348.         return $this;
  349.     }
  350.     public function getUnit(): ?string
  351.     {
  352.         return $this->unit;
  353.     }
  354.     public function setUnit(string $unit): self
  355.     {
  356.         $this->unit $unit;
  357.         return $this;
  358.     }
  359.     public function getIsStock(): ?bool
  360.     {
  361.         return $this->isStock;
  362.     }
  363.     public function setIsStock(bool $isStock): self
  364.     {
  365.         $this->isStock $isStock;
  366.         return $this;
  367.     }
  368.     public function getIsDeclination(): ?bool
  369.     {
  370.         return $this->isDeclination;
  371.     }
  372.     public function setIsDeclination(bool $isDeclination): self
  373.     {
  374.         $this->isDeclination $isDeclination;
  375.         return $this;
  376.     }
  377.     public function getCreatedAt(): ?\DateTimeInterface
  378.     {
  379.         return $this->createdAt;
  380.     }
  381.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  382.     {
  383.         $this->createdAt $createdAt;
  384.         return $this;
  385.     }
  386.     /**
  387.      * @return Collection|Declination[]
  388.      */
  389.     public function getDeclinations(): Collection
  390.     {
  391.         return $this->declinations;
  392.     }
  393.     public function addDeclination(Declination $declination): self
  394.     {
  395.         if( !$this->declinations->contains($declination)) {
  396.             $this->declinations[] = $declination;
  397.             $declination->addProduit($this);
  398.         }
  399.         return $this;
  400.     }
  401.     public function removeDeclination(Declination $declination): self
  402.     {
  403.         if( $this->declinations->removeElement($declination)) {
  404.             $declination->removeProduit($this);
  405.         }
  406.         return $this;
  407.     }
  408.     /**
  409.      * @return Collection|ProduitDeclinationValue[]
  410.      */
  411.     public function getProduitDeclinationValues(): Collection
  412.     {
  413.         return $this->produitDeclinationValues;
  414.     }
  415.     public function addProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  416.     {
  417.         if( !$this->produitDeclinationValues->contains($produitDeclinationValue)) {
  418.             $this->produitDeclinationValues[] = $produitDeclinationValue;
  419.             $produitDeclinationValue->setProduit($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removeProduitDeclinationValue(ProduitDeclinationValue $produitDeclinationValue): self
  424.     {
  425.         if( $this->produitDeclinationValues->removeElement($produitDeclinationValue)) {
  426.             // set the owning side to null (unless already changed)
  427.             if( $produitDeclinationValue->getProduit() === $this) {
  428.                 $produitDeclinationValue->setProduit(null);
  429.             }
  430.         }
  431.         return $this;
  432.     }
  433.     /**
  434.      * @return Collection|File[]
  435.      */
  436.     public function getPicture(): Collection
  437.     {
  438.         return $this->picture;
  439.     }
  440.     public function addPicture(File $picture): self
  441.     {
  442.         if( !$this->picture->contains($picture))
  443.             $this->picture[] = $picture;
  444.         return $this;
  445.     }
  446.     public function removePicture(File $picture): self
  447.     {
  448.         $this->picture->removeElement($picture);
  449.         return $this;
  450.     }
  451.     /**
  452.      * @return Collection|DocumentProduit[]
  453.      */
  454.     public function getDocumentProduits(): Collection
  455.     {
  456.         return $this->documentProduits;
  457.     }
  458.     public function addDocumentProduit(DocumentProduit $documentProduit): self
  459.     {
  460.         if( !$this->documentProduits->contains($documentProduit)) {
  461.             $this->documentProduits[] = $documentProduit;
  462.             $documentProduit->setProduit($this);
  463.         }
  464.         return $this;
  465.     }
  466.     public function removeDocumentProduit(DocumentProduit $documentProduit): self
  467.     {
  468.         if( $this->documentProduits->removeElement($documentProduit))
  469.             // set the owning side to null (unless already changed)
  470.             if( $documentProduit->getProduit() === $this)
  471.                 $documentProduit->setProduit(null);
  472.         return $this;
  473.     }
  474.     /**
  475.      * @return Collection|Stock[]
  476.      */
  477.     public function getStocks(): Collection
  478.     {
  479.         return $this->stocks;
  480.     }
  481.     public function addStock(Stock $stock): self
  482.     {
  483.         if( !$this->stocks->contains($stock)) {
  484.             $this->stocks[] = $stock;
  485.             $stock->setProduit($this);
  486.         }
  487.         return $this;
  488.     }
  489.     public function removeStock(Stock $stock): self
  490.     {
  491.         if( $this->stocks->removeElement($stock))
  492.             // set the owning side to null (unless already changed)
  493.             if( $stock->getProduit() === $this)
  494.                 $stock->setProduit(null);
  495.         return $this;
  496.     }
  497.     public function getUuid(): ?int
  498.     {
  499.         return $this->uuid;
  500.     }
  501.     public function setUuid(?int $uuid): self
  502.     {
  503.         $this->uuid $uuid;
  504.         return $this;
  505.     }
  506.     public function getPromotion(): ?Promotion
  507.     {
  508.         return $this->promotion;
  509.     }
  510.     public function setPromotion(?Promotion $promotion): self
  511.     {
  512.         $this->promotion $promotion;
  513.         return $this;
  514.     }
  515.     /**
  516.      * @return Collection|Activity[]
  517.      */
  518.     public function getActivities(): Collection
  519.     {
  520.         return $this->activities;
  521.     }
  522.     public function addActivity(Activity $activity): self
  523.     {
  524.         if( !$this->activities->contains($activity)) {
  525.             $this->activities[] = $activity;
  526.             $activity->setProduit($this);
  527.         }
  528.         return $this;
  529.     }
  530.     public function removeActivity(Activity $activity): self
  531.     {
  532.         if( $this->activities->removeElement($activity))
  533.             // set the owning side to null (unless already changed)
  534.             if( $activity->getProduit() === $this)
  535.                 $activity->setProduit(null);
  536.         return $this;
  537.     }
  538.     public function getInformation(): ?string
  539.     {
  540.         return $this->information;
  541.     }
  542.     public function setInformation(?string $information): self
  543.     {
  544.         $this->information $information;
  545.         return $this;
  546.     }
  547.     public function getIsArchived(): ?bool
  548.     {
  549.         return $this->isArchived;
  550.     }
  551.     public function setIsArchived(?bool $isArchived): self
  552.     {
  553.         $this->isArchived $isArchived;
  554.         return $this;
  555.     }
  556.     public function isArchived(): bool
  557.     {
  558.         return $this->deletedAt !== null;
  559.     }
  560.     /**
  561.      * @return Collection|Comment[]
  562.      */
  563.     public function getComments(): Collection
  564.     {
  565.         return $this->comments;
  566.     }
  567.     public function addComment(Comment $comment): self
  568.     {
  569.         if( !$this->comments->contains($comment)) {
  570.             $this->comments[] = $comment;
  571.             $comment->setProduit($this);
  572.         }
  573.         return $this;
  574.     }
  575.     public function removeComment(Comment $comment): self
  576.     {
  577.         if( $this->comments->removeElement($comment))
  578.             // set the owning side to null (unless already changed)
  579.             if( $comment->getProduit() === $this)
  580.                 $comment->setProduit(null);
  581.         return $this;
  582.     }
  583.     public function getIsNew(): ?bool
  584.     {
  585.         return $this->isNew;
  586.     }
  587.     public function setIsNew(bool $isNew): self
  588.     {
  589.         $this->isNew $isNew;
  590.         return $this;
  591.     }
  592.     public function getStock(): ?int
  593.     {
  594.         foreach ($this->getStocks() as $stock) {
  595.             $this->stock += $stock->getQtStock() - $stock->getQtReserved();
  596.         }
  597.         return $this->stock;
  598.     }
  599.     public function setStock($stock): self
  600.     {
  601.         $this->stock $stock;
  602.         return $this;
  603.     }
  604.     public function isNew()
  605.     {
  606.         // On va chercher les produit nouveau dont la date de création ne dépasse pas 90 jours
  607.         $date = new \DateTime('now');
  608.         $date->modify('-90 day');
  609.         if( $this->getCreatedAt() >= $date) {
  610.             $this->setIsNew(true);
  611.         }
  612.         return $this->isNew;
  613.     }
  614.     public function getBestSelection(): ?bool
  615.     {
  616.         return $this->bestSelection;
  617.     }
  618.     public function setBestSelection(bool $bestSelection): self
  619.     {
  620.         $this->bestSelection $bestSelection;
  621.         return $this;
  622.     }
  623.     public function jsonSerialize()
  624.     {
  625.         $tabPictures = [];
  626.         foreach ($this->getPicture() as $picture) {
  627.             array_push($tabPictures$picture->getImageName());
  628.         }
  629.         return array(
  630.             'id' => $this->getId(),
  631.             'name' => $this->getName(),
  632.             'description' => $this->getDescription(),
  633.             'specification' => $this->getInformation(),
  634.             'picture' => $tabPictures,
  635.             'image' => $this->getImage(),
  636.             'priceHT' => $this->getPriceHt(),
  637.             'priceTTC' => $this->getPriceTtc(),
  638.             'category' => $this->getCategories() ? $this->getCategories()->getId() : 0,
  639.             //'produitDeclinationValues' => $this->getProduitDeclinationValues()->toArray(),
  640.             'promo' => $this->getPromotion(),
  641.             'isNew' => $this->isNew(),
  642.             'stock' => $this->getStock(),
  643.             //'tags' => $this->getTags()->toArray(),
  644.         );
  645.     }
  646.     public function getPrincipalCategory(): ?Category
  647.     {
  648.         return $this->principalCategory;
  649.     }
  650.     public function setPrincipalCategory(?Category $principalCategory): self
  651.     {
  652.         $this->principalCategory $principalCategory;
  653.         return $this;
  654.     }
  655.     public function getDeletedAt(): ?\DateTimeInterface
  656.     {
  657.         return $this->deletedAt;
  658.     }
  659.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  660.     {
  661.         $this->deletedAt $deletedAt;
  662.         return $this;
  663.     }
  664.     public function getReasonOfDelete(): ?string
  665.     {
  666.         return $this->reasonOfDelete;
  667.     }
  668.     public function setReasonOfDelete(?string $reasonOfDelete): self
  669.     {
  670.         $this->reasonOfDelete $reasonOfDelete;
  671.         return $this;
  672.     }
  673.     /**
  674.      * @return Collection|User[]
  675.      */
  676.     public function getUsers(): Collection
  677.     {
  678.         return $this->users;
  679.     }
  680.     public function addUser(User $user): self
  681.     {
  682.         if( !$this->users->contains($user)) {
  683.             $this->users[] = $user;
  684.         }
  685.         return $this;
  686.     }
  687.     public function removeUser(User $user): self
  688.     {
  689.         if( $this->users->contains($user)) {
  690.             $this->users->removeElement($user);
  691.         }
  692.         return $this;
  693.     }
  694.     public function getShowInWebsite(): ?bool
  695.     {
  696.         return $this->showInWebSite;
  697.     }
  698.     public function setShowInWebSite(?bool $showInWebSite): self
  699.     {
  700.         $this->showInWebSite $showInWebSite;
  701.         return $this;
  702.     }
  703.     public function getMaterial(): ?string 
  704.     
  705.         return $this->material
  706.     }
  707.     public function setMaterial(?string $material): self 
  708.     
  709.         $this->material $material; return $this
  710.     }
  711.      /**
  712.      * @return string|null
  713.      */
  714.     public function getSupplierReference(): ?string
  715.     {
  716.         return $this->supplierReference;
  717.     }
  718.     /**
  719.      * @param string|null $supplierReference
  720.      * @return self
  721.      */
  722.     public function setSupplierReference(?string $supplierReference): self
  723.     {
  724.         $this->supplierReference $supplierReference;
  725.         return $this;
  726.     }
  727.     
  728.     public function getPromotionHistories(): Collection {
  729.         return $this->promotionHistories;
  730.     }
  731.      public function getMetaDescription(): ?string
  732.     {
  733.         return $this->metaDescription;
  734.     }
  735.     public function setMetaDescription(?string $metaDescription): self
  736.     {
  737.         $this->metaDescription $metaDescription;
  738.         return $this;
  739.     }
  740. }