src/Entity/Produit.php line 13

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. /**
  8.  * @ORM\Entity(repositoryClass=ProduitRepository::class)
  9.  */
  10. class Produit
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.   
  19.     /**
  20.      * @ORM\Column(type="string", length=255, nullable=true)
  21.      */
  22.     private $reference;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, nullable=true)
  25.      */
  26.     private $description;
  27.     /**
  28.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  29.      */
  30.     private $puht;
  31.     /**
  32.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  33.      */
  34.     private $remise;
  35.     /**
  36.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  37.      */
  38.     private $npuht;
  39.     /**
  40.      * @ORM\Column(type="float", nullable=true)
  41.      */
  42.     private $nb;
  43.     /**
  44.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  45.      */
  46.     private $prixht;
  47.     /**
  48.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  49.      */
  50.     private $tva;
  51.     
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private $code_barre;
  56.  
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="produit")
  59.      *  @ORM\JoinColumn(onDelete="SET NULL")
  60.      */
  61.     private $user;
  62.     
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=Fournisseur::class, inversedBy="produits")
  65.      */
  66.     private $fournisseur;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $nature_stock;
  71.      
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     private $num_bl;
  76.      
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $piece;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private $marque;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private $modele;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      */
  92.     private $immatriculation;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Entrees::class, mappedBy="id_produit")
  95.      */
  96.     private $entrees;
  97.     /**
  98.      * @ORM\OneToMany(targetEntity=Sorties::class, mappedBy="id_produit")
  99.      */
  100.     private $sorties;
  101.     /**
  102.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="id_produit")
  103.      */
  104.     private $stocks;
  105.     /**
  106.      * @ORM\Column(type="date", nullable=true)
  107.      */
  108.     private $date_commande;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, nullable=true)
  111.      */
  112.     private $nom_fournisseur;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=DevisLine::class, mappedBy="produit")
  115.      */
  116.     private $devisLines;
  117.     
  118.     /**
  119.      * @ORM\ManyToOne(targetEntity="App\Entity\Categorie", inversedBy="produits")
  120.      * @ORM\JoinColumn(nullable=true)
  121.      */
  122.     private $categorie;
  123.     /**
  124.      * @ORM\Column(type="string", length=255, nullable=true)
  125.      */
  126.     private $imageUrl;
  127.     /**
  128.      * @ORM\Column(type="boolean", options={"default": false})
  129.      */
  130.     private $topVente = false;
  131.     /**
  132.      * @ORM\Column(type="decimal", precision=10, scale=3, options={"default": 0})
  133.      */
  134.     private $prixVente = 0;
  135.     /**
  136.      * @ORM\Column(type="string", length=10, options={"default": "produit"})
  137.      */
  138.     private $type = 'produit';
  139.     // Dans App\Entity\Produit
  140. /**
  141.  * @ORM\Column(type="float", nullable=true, options={"default": 19})
  142.  */
  143. private $tvaRate = 19.0;
  144. /**
  145.  * @ORM\Column(type="float", nullable=true, options={"default": 0})
  146.  */
  147. private $discountRate = 0.0;
  148. /**
  149.  * @ORM\Column(type="string", length=50, nullable=true)
  150.  */
  151. private $unite;
  152. /**
  153.  * Commission salarié (%) sur la vente de ce produit — optionnel, laissé à null si aucune commission.
  154.  *
  155.  * @ORM\Column(type="float", nullable=true)
  156.  */
  157. private $commissionRate;
  158.     public function __construct()
  159.     {
  160.         $this->entrees = new ArrayCollection();
  161.         $this->sorties = new ArrayCollection();
  162.         $this->stocks = new ArrayCollection();
  163.         $this->devisLines = new ArrayCollection();
  164.     }
  165.   
  166.     // Ajout des getters et setters
  167. public function getTvaRate(): float
  168. {
  169.     return (float) ($this->tvaRate ?? 19.0);
  170. }
  171. public function setTvaRate(?float $tvaRate): self
  172. {
  173.     $this->tvaRate = $tvaRate;
  174.     return $this;
  175. }
  176.     
  177. public function getDiscountRate(): float
  178. {
  179.     return (float) ($this->discountRate ?? 0.0);
  180. }
  181. public function setDiscountRate(?float $discountRate): self
  182. {
  183.     $this->discountRate = $discountRate;
  184.     return $this;
  185. }
  186. public function getUnite(): ?string
  187. {
  188.     return $this->unite;
  189. }
  190. public function setUnite(?string $unite): self
  191. {
  192.     $this->unite = $unite;
  193.     return $this;
  194. }
  195. public function getCommissionRate(): ?float
  196. {
  197.     return $this->commissionRate;
  198. }
  199. public function setCommissionRate(?float $commissionRate): self
  200. {
  201.     $this->commissionRate = $commissionRate;
  202.     return $this;
  203. }
  204. // Méthodes utilitaires pour les calculs
  205. public function getPrixHTAfterDiscount(): float
  206. {
  207.     $prix = (float) ($this->puht ?? $this->prixVente ?? 0);
  208.     $discount = (float) ($this->discountRate ?? 0);
  209.     return round($prix * (1 - ($discount / 100)), 3);
  210. }
  211. public function getPrixTTC(): float
  212. {
  213.     $prixHT = $this->getPrixHTAfterDiscount();
  214.     $tvaRate = (float) ($this->tvaRate ?? 19.0);
  215.     return round($prixHT * (1 + ($tvaRate / 100)), 3);
  216. }
  217. public function getMontantTVA(): float
  218. {
  219.     $prixHT = $this->getPrixHTAfterDiscount();
  220.     $tvaRate = (float) ($this->tvaRate ?? 19.0);
  221.     return round($prixHT * ($tvaRate / 100), 3);
  222. }
  223.     /**
  224.      * @return string
  225.      */
  226.     public function __toString()
  227.     {
  228.         return $this->reference . ' - ' . ($this->description ?? '');
  229.     }
  230.    
  231.     public function getId(): ?int
  232.     {
  233.         return $this->id;
  234.     }
  235.  
  236.     public function getReference(): ?string
  237.     {
  238.         return $this->reference;
  239.     }
  240.     public function setReference(?string $reference): self
  241.     {
  242.         $this->reference = $reference;
  243.         return $this;
  244.     }
  245.     public function getDescription(): ?string
  246.     {
  247.         return $this->description;
  248.     }
  249.     public function setDescription(?string $description): self
  250.     {
  251.         $this->description = $description;
  252.         return $this;
  253.     }
  254.     public function getPuht(): ?float
  255.     {
  256.         return $this->puht !== null ? (float) $this->puht : null;
  257.     }
  258.     public function setPuht(?float $puht): self
  259.     {
  260.         $this->puht = $puht;
  261.         return $this;
  262.     }
  263.     public function getRemise(): ?float
  264.     {
  265.         return $this->remise !== null ? (float) $this->remise : null;
  266.     }
  267.     public function setRemise(?float $remise): self
  268.     {
  269.         $this->remise = $remise;
  270.         return $this;
  271.     }
  272.     public function getNpuht(): ?float
  273.     {
  274.         return $this->npuht !== null ? (float) $this->npuht : null;
  275.     }
  276.     public function setNpuht(?float $npuht): self
  277.     {
  278.         $this->npuht = $npuht;
  279.         return $this;
  280.     }
  281.     public function getNb(): ?float
  282.     {
  283.         return $this->nb;
  284.     }
  285.     public function setNb(?float $nb): self
  286.     {
  287.         $this->nb = $nb;
  288.         return $this;
  289.     }
  290.     public function getPrixht(): ?float
  291.     {
  292.         return $this->prixht !== null ? (float) $this->prixht : null;
  293.     }
  294.     public function setPrixht(?float $prixht): self
  295.     {
  296.         $this->prixht = $prixht;
  297.         return $this;
  298.     }
  299.     public function getTva(): ?float
  300.     {
  301.         return $this->tva !== null ? (float) $this->tva : null;
  302.     }
  303.     public function setTva(?float $tva): self
  304.     {
  305.         $this->tva = $tva;
  306.         return $this;
  307.     }
  308.   
  309.     public function getCodeBarre(): ?string
  310.     {
  311.         return $this->code_barre;
  312.     }
  313.     public function setCodeBarre(?string $code_barre): self
  314.     {
  315.         $this->code_barre = $code_barre;
  316.         return $this;
  317.     }
  318.     
  319.     public function getUser(): ?User
  320.     {
  321.         return $this->user;
  322.     }
  323.     public function setUser(?User $user): self
  324.     {
  325.         $this->user = $user;
  326.         return $this;
  327.     }
  328.     public function getFournisseur(): ?Fournisseur
  329.     {
  330.         return $this->fournisseur;
  331.     }
  332.     public function setFournisseur(?Fournisseur $fournisseur): self
  333.     {
  334.         $this->fournisseur = $fournisseur;
  335.         return $this;
  336.     }
  337.     public function getNatureStock(): ?string
  338.     {
  339.         return $this->nature_stock;
  340.     }
  341.     public function setNatureStock(?string $nature_stock): self
  342.     {
  343.         $this->nature_stock = $nature_stock;
  344.         return $this;
  345.     }
  346.     
  347.   
  348.     public function getNumBl(): ?string
  349.     {
  350.         return $this->num_bl;
  351.     }
  352.     public function setNumBl(?string $num_bl): self
  353.     {
  354.         $this->num_bl = $num_bl;
  355.         return $this;
  356.     }
  357.  
  358.     public function getPiece(): ?string
  359.     {
  360.         return $this->piece;
  361.     }
  362.     public function setPiece(?string $piece): self
  363.     {
  364.         $this->piece = $piece;
  365.         return $this;
  366.     }
  367.     public function getMarque(): ?string
  368.     {
  369.         return $this->marque;
  370.     }
  371.     public function setMarque(?string $marque): self
  372.     {
  373.         $this->marque = $marque;
  374.         return $this;
  375.     }
  376.     public function getModele(): ?string
  377.     {
  378.         return $this->modele;
  379.     }
  380.     public function setModele(?string $modele): self
  381.     {
  382.         $this->modele = $modele;
  383.         return $this;
  384.     }
  385.     public function getImmatriculation(): ?string
  386.     {
  387.         return $this->immatriculation;
  388.     }
  389.     public function setImmatriculation(?string $immatriculation): self
  390.     {
  391.         $this->immatriculation = $immatriculation;
  392.         return $this;
  393.     }
  394.     /**
  395.      * @return Collection|Entrees[]
  396.      */
  397.     public function getEntrees(): Collection
  398.     {
  399.         return $this->entrees;
  400.     }
  401.     public function addEntree(Entrees $entree): self
  402.     {
  403.         if (!$this->entrees->contains($entree)) {
  404.             $this->entrees[] = $entree;
  405.             $entree->setIdProduit($this);
  406.         }
  407.         return $this;
  408.     }
  409.     public function removeEntree(Entrees $entree): self
  410.     {
  411.         if ($this->entrees->removeElement($entree)) {
  412.             // set the owning side to null (unless already changed)
  413.             if ($entree->getIdProduit() === $this) {
  414.                 $entree->setIdProduit(null);
  415.             }
  416.         }
  417.         return $this;
  418.     }
  419.     /**
  420.      * @return Collection|Sorties[]
  421.      */
  422.     public function getSorties(): Collection
  423.     {
  424.         return $this->sorties;
  425.     }
  426.     public function addSorty(Sorties $sorty): self
  427.     {
  428.         if (!$this->sorties->contains($sorty)) {
  429.             $this->sorties[] = $sorty;
  430.             $sorty->setIdProduit($this);
  431.         }
  432.         return $this;
  433.     }
  434.     public function removeSorty(Sorties $sorty): self
  435.     {
  436.         if ($this->sorties->removeElement($sorty)) {
  437.             // set the owning side to null (unless already changed)
  438.             if ($sorty->getIdProduit() === $this) {
  439.                 $sorty->setIdProduit(null);
  440.             }
  441.         }
  442.         return $this;
  443.     }
  444.     /**
  445.      * @return Collection|Stock[]
  446.      */
  447.     public function getStocks(): Collection
  448.     {
  449.         return $this->stocks;
  450.     }
  451.     public function addStock(Stock $stock): self
  452.     {
  453.         if (!$this->stocks->contains($stock)) {
  454.             $this->stocks[] = $stock;
  455.             $stock->setIdProduit($this);
  456.         }
  457.         return $this;
  458.     }
  459.     public function removeStock(Stock $stock): self
  460.     {
  461.         if ($this->stocks->removeElement($stock)) {
  462.             // set the owning side to null (unless already changed)
  463.             if ($stock->getIdProduit() === $this) {
  464.                 $stock->setIdProduit(null);
  465.             }
  466.         }
  467.         return $this;
  468.     }
  469.     public function getDateCommande(): ?\DateTimeInterface
  470.     {
  471.         return $this->date_commande;
  472.     }
  473.     public function setDateCommande(?\DateTimeInterface $date_commande): self
  474.     {
  475.         $this->date_commande = $date_commande;
  476.         return $this;
  477.     }
  478.     public function getNomFournisseur(): ?string
  479.     {
  480.         return $this->nom_fournisseur;
  481.     }
  482.     public function setNomFournisseur(?string $nom_fournisseur): self
  483.     {
  484.         $this->nom_fournisseur = $nom_fournisseur;
  485.         return $this;
  486.     }
  487.     /**
  488.      * @return Collection<int, DevisLine>
  489.      */
  490.     public function getDevisLines(): Collection
  491.     {
  492.         return $this->devisLines;
  493.     }
  494.     public function addDevisLine(DevisLine $devisLine): self
  495.     {
  496.         if (!$this->devisLines->contains($devisLine)) {
  497.             $this->devisLines[] = $devisLine;
  498.             $devisLine->setProduit($this);
  499.         }
  500.         return $this;
  501.     }
  502.     public function removeDevisLine(DevisLine $devisLine): self
  503.     {
  504.         if ($this->devisLines->removeElement($devisLine)) {
  505.             // set the owning side to null (unless already changed)
  506.             if ($devisLine->getProduit() === $this) {
  507.                 $devisLine->setProduit(null);
  508.             }
  509.         }
  510.         return $this;
  511.     }
  512.  
  513.     public function getCategorie(): ?Categorie
  514.     {
  515.         return $this->categorie;
  516.     }
  517.     public function setCategorie(?Categorie $categorie): self
  518.     {
  519.         $this->categorie = $categorie;
  520.         return $this;
  521.     }
  522.    
  523.     
  524.     public function getImageUrl(): ?string
  525.     {
  526.         return $this->imageUrl;
  527.     }
  528.     public function setImageUrl(?string $imageUrl): self
  529.     {
  530.         $this->imageUrl = $imageUrl;
  531.         return $this;
  532.     }
  533.     public function isTopVente(): bool
  534.     {
  535.         return $this->topVente;
  536.     }
  537.     public function setTopVente(bool $topVente): self
  538.     {
  539.         $this->topVente = $topVente;
  540.         return $this;
  541.     }
  542.     public function getPrixVente(): float
  543.     {
  544.         return (float) $this->prixVente;
  545.     }
  546.     public function setPrixVente(float $prixVente): self
  547.     {
  548.         $this->prixVente = $prixVente;
  549.         return $this;
  550.     }
  551.     
  552.     // Ajoutez les getters et setters correspondants
  553.     public function getType(): ?string
  554.     {
  555.         return $this->type;
  556.     }
  557.     public function setType(string $type): self
  558.     {
  559.         $this->type = $type;
  560.         return $this;
  561.     }
  562.     public function getTopVente(): ?bool
  563.     {
  564.         return $this->topVente;
  565.     }
  566. }