<?php
namespace App\Entity;
use App\Repository\ProduitRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProduitRepository::class)
*/
class Produit
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reference;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $puht;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $remise;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $npuht;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $nb;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $prixht;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $tva;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $code_barre;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="produit")
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Fournisseur::class, inversedBy="produits")
*/
private $fournisseur;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nature_stock;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $num_bl;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $piece;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $marque;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $modele;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $immatriculation;
/**
* @ORM\OneToMany(targetEntity=Entrees::class, mappedBy="id_produit")
*/
private $entrees;
/**
* @ORM\OneToMany(targetEntity=Sorties::class, mappedBy="id_produit")
*/
private $sorties;
/**
* @ORM\OneToMany(targetEntity=Stock::class, mappedBy="id_produit")
*/
private $stocks;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $date_commande;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nom_fournisseur;
/**
* @ORM\OneToMany(targetEntity=DevisLine::class, mappedBy="produit")
*/
private $devisLines;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Categorie", inversedBy="produits")
* @ORM\JoinColumn(nullable=true)
*/
private $categorie;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $imageUrl;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $topVente = false;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, options={"default": 0})
*/
private $prixVente = 0;
/**
* @ORM\Column(type="string", length=10, options={"default": "produit"})
*/
private $type = 'produit';
// Dans App\Entity\Produit
/**
* @ORM\Column(type="float", nullable=true, options={"default": 19})
*/
private $tvaRate = 19.0;
/**
* @ORM\Column(type="float", nullable=true, options={"default": 0})
*/
private $discountRate = 0.0;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $unite;
/**
* Commission salarié (%) sur la vente de ce produit — optionnel, laissé à null si aucune commission.
*
* @ORM\Column(type="float", nullable=true)
*/
private $commissionRate;
public function __construct()
{
$this->entrees = new ArrayCollection();
$this->sorties = new ArrayCollection();
$this->stocks = new ArrayCollection();
$this->devisLines = new ArrayCollection();
}
// Ajout des getters et setters
public function getTvaRate(): float
{
return (float) ($this->tvaRate ?? 19.0);
}
public function setTvaRate(?float $tvaRate): self
{
$this->tvaRate = $tvaRate;
return $this;
}
public function getDiscountRate(): float
{
return (float) ($this->discountRate ?? 0.0);
}
public function setDiscountRate(?float $discountRate): self
{
$this->discountRate = $discountRate;
return $this;
}
public function getUnite(): ?string
{
return $this->unite;
}
public function setUnite(?string $unite): self
{
$this->unite = $unite;
return $this;
}
public function getCommissionRate(): ?float
{
return $this->commissionRate;
}
public function setCommissionRate(?float $commissionRate): self
{
$this->commissionRate = $commissionRate;
return $this;
}
// Méthodes utilitaires pour les calculs
public function getPrixHTAfterDiscount(): float
{
$prix = (float) ($this->puht ?? $this->prixVente ?? 0);
$discount = (float) ($this->discountRate ?? 0);
return round($prix * (1 - ($discount / 100)), 3);
}
public function getPrixTTC(): float
{
$prixHT = $this->getPrixHTAfterDiscount();
$tvaRate = (float) ($this->tvaRate ?? 19.0);
return round($prixHT * (1 + ($tvaRate / 100)), 3);
}
public function getMontantTVA(): float
{
$prixHT = $this->getPrixHTAfterDiscount();
$tvaRate = (float) ($this->tvaRate ?? 19.0);
return round($prixHT * ($tvaRate / 100), 3);
}
/**
* @return string
*/
public function __toString()
{
return $this->reference . ' - ' . ($this->description ?? '');
}
public function getId(): ?int
{
return $this->id;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPuht(): ?float
{
return $this->puht !== null ? (float) $this->puht : null;
}
public function setPuht(?float $puht): self
{
$this->puht = $puht;
return $this;
}
public function getRemise(): ?float
{
return $this->remise !== null ? (float) $this->remise : null;
}
public function setRemise(?float $remise): self
{
$this->remise = $remise;
return $this;
}
public function getNpuht(): ?float
{
return $this->npuht !== null ? (float) $this->npuht : null;
}
public function setNpuht(?float $npuht): self
{
$this->npuht = $npuht;
return $this;
}
public function getNb(): ?float
{
return $this->nb;
}
public function setNb(?float $nb): self
{
$this->nb = $nb;
return $this;
}
public function getPrixht(): ?float
{
return $this->prixht !== null ? (float) $this->prixht : null;
}
public function setPrixht(?float $prixht): self
{
$this->prixht = $prixht;
return $this;
}
public function getTva(): ?float
{
return $this->tva !== null ? (float) $this->tva : null;
}
public function setTva(?float $tva): self
{
$this->tva = $tva;
return $this;
}
public function getCodeBarre(): ?string
{
return $this->code_barre;
}
public function setCodeBarre(?string $code_barre): self
{
$this->code_barre = $code_barre;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getFournisseur(): ?Fournisseur
{
return $this->fournisseur;
}
public function setFournisseur(?Fournisseur $fournisseur): self
{
$this->fournisseur = $fournisseur;
return $this;
}
public function getNatureStock(): ?string
{
return $this->nature_stock;
}
public function setNatureStock(?string $nature_stock): self
{
$this->nature_stock = $nature_stock;
return $this;
}
public function getNumBl(): ?string
{
return $this->num_bl;
}
public function setNumBl(?string $num_bl): self
{
$this->num_bl = $num_bl;
return $this;
}
public function getPiece(): ?string
{
return $this->piece;
}
public function setPiece(?string $piece): self
{
$this->piece = $piece;
return $this;
}
public function getMarque(): ?string
{
return $this->marque;
}
public function setMarque(?string $marque): self
{
$this->marque = $marque;
return $this;
}
public function getModele(): ?string
{
return $this->modele;
}
public function setModele(?string $modele): self
{
$this->modele = $modele;
return $this;
}
public function getImmatriculation(): ?string
{
return $this->immatriculation;
}
public function setImmatriculation(?string $immatriculation): self
{
$this->immatriculation = $immatriculation;
return $this;
}
/**
* @return Collection|Entrees[]
*/
public function getEntrees(): Collection
{
return $this->entrees;
}
public function addEntree(Entrees $entree): self
{
if (!$this->entrees->contains($entree)) {
$this->entrees[] = $entree;
$entree->setIdProduit($this);
}
return $this;
}
public function removeEntree(Entrees $entree): self
{
if ($this->entrees->removeElement($entree)) {
// set the owning side to null (unless already changed)
if ($entree->getIdProduit() === $this) {
$entree->setIdProduit(null);
}
}
return $this;
}
/**
* @return Collection|Sorties[]
*/
public function getSorties(): Collection
{
return $this->sorties;
}
public function addSorty(Sorties $sorty): self
{
if (!$this->sorties->contains($sorty)) {
$this->sorties[] = $sorty;
$sorty->setIdProduit($this);
}
return $this;
}
public function removeSorty(Sorties $sorty): self
{
if ($this->sorties->removeElement($sorty)) {
// set the owning side to null (unless already changed)
if ($sorty->getIdProduit() === $this) {
$sorty->setIdProduit(null);
}
}
return $this;
}
/**
* @return Collection|Stock[]
*/
public function getStocks(): Collection
{
return $this->stocks;
}
public function addStock(Stock $stock): self
{
if (!$this->stocks->contains($stock)) {
$this->stocks[] = $stock;
$stock->setIdProduit($this);
}
return $this;
}
public function removeStock(Stock $stock): self
{
if ($this->stocks->removeElement($stock)) {
// set the owning side to null (unless already changed)
if ($stock->getIdProduit() === $this) {
$stock->setIdProduit(null);
}
}
return $this;
}
public function getDateCommande(): ?\DateTimeInterface
{
return $this->date_commande;
}
public function setDateCommande(?\DateTimeInterface $date_commande): self
{
$this->date_commande = $date_commande;
return $this;
}
public function getNomFournisseur(): ?string
{
return $this->nom_fournisseur;
}
public function setNomFournisseur(?string $nom_fournisseur): self
{
$this->nom_fournisseur = $nom_fournisseur;
return $this;
}
/**
* @return Collection<int, DevisLine>
*/
public function getDevisLines(): Collection
{
return $this->devisLines;
}
public function addDevisLine(DevisLine $devisLine): self
{
if (!$this->devisLines->contains($devisLine)) {
$this->devisLines[] = $devisLine;
$devisLine->setProduit($this);
}
return $this;
}
public function removeDevisLine(DevisLine $devisLine): self
{
if ($this->devisLines->removeElement($devisLine)) {
// set the owning side to null (unless already changed)
if ($devisLine->getProduit() === $this) {
$devisLine->setProduit(null);
}
}
return $this;
}
public function getCategorie(): ?Categorie
{
return $this->categorie;
}
public function setCategorie(?Categorie $categorie): self
{
$this->categorie = $categorie;
return $this;
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
public function setImageUrl(?string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
public function isTopVente(): bool
{
return $this->topVente;
}
public function setTopVente(bool $topVente): self
{
$this->topVente = $topVente;
return $this;
}
public function getPrixVente(): float
{
return (float) $this->prixVente;
}
public function setPrixVente(float $prixVente): self
{
$this->prixVente = $prixVente;
return $this;
}
// Ajoutez les getters et setters correspondants
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getTopVente(): ?bool
{
return $this->topVente;
}
}