<?php
namespace App\Entity;
use App\Repository\FournisseurRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: FournisseurRepository::class)]
class Fournisseur
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $nom = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telephone = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $adresse = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $ville = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $codePostal = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $pays = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $numeroIdentification = null; // SIRET, IFU, etc.
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
#[ORM\Column]
private ?bool $estActif = true;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\OneToMany(mappedBy: 'fournisseur', targetEntity: AchatFournisseur::class)]
private Collection $achats;
#[ORM\OneToMany(mappedBy: 'fournisseur', targetEntity: DetteFournisseur::class)]
private Collection $dettes;
#[ORM\OneToMany(mappedBy: 'fournisseur', targetEntity: PaiementFournisseur::class)]
private Collection $paiements;
#[ORM\OneToMany(mappedBy: 'fournisseur', targetEntity: EntreeStock::class)]
private Collection $entreesStock;
#[ORM\OneToMany(mappedBy: 'fournisseur', targetEntity: CommandeFournisseur::class, orphanRemoval: true)]
private Collection $commandes;
public function __construct()
{
$this->achats = new ArrayCollection();
$this->dettes = new ArrayCollection();
$this->paiements = new ArrayCollection();
$this->entreesStock = new ArrayCollection();
$this->commandes = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): static
{
$this->telephone = $telephone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): static
{
$this->adresse = $adresse;
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(?string $ville): static
{
$this->ville = $ville;
return $this;
}
public function getCodePostal(): ?string
{
return $this->codePostal;
}
public function setCodePostal(?string $codePostal): static
{
$this->codePostal = $codePostal;
return $this;
}
public function getPays(): ?string
{
return $this->pays;
}
public function setPays(?string $pays): static
{
$this->pays = $pays;
return $this;
}
public function getNumeroIdentification(): ?string
{
return $this->numeroIdentification;
}
public function setNumeroIdentification(?string $numeroIdentification): static
{
$this->numeroIdentification = $numeroIdentification;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function isEstActif(): ?bool
{
return $this->estActif;
}
public function setEstActif(bool $estActif): static
{
$this->estActif = $estActif;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, AchatFournisseur>
*/
public function getAchats(): Collection
{
return $this->achats;
}
public function addAchat(AchatFournisseur $achat): static
{
if (!$this->achats->contains($achat)) {
$this->achats->add($achat);
$achat->setFournisseur($this);
}
return $this;
}
public function removeAchat(AchatFournisseur $achat): static
{
if ($this->achats->removeElement($achat)) {
if ($achat->getFournisseur() === $this) {
$achat->setFournisseur(null);
}
}
return $this;
}
/**
* @return Collection<int, DetteFournisseur>
*/
public function getDettes(): Collection
{
return $this->dettes;
}
public function addDette(DetteFournisseur $dette): static
{
if (!$this->dettes->contains($dette)) {
$this->dettes->add($dette);
$dette->setFournisseur($this);
}
return $this;
}
public function removeDette(DetteFournisseur $dette): static
{
if ($this->dettes->removeElement($dette)) {
if ($dette->getFournisseur() === $this) {
$dette->setFournisseur(null);
}
}
return $this;
}
/**
* @return Collection<int, PaiementFournisseur>
*/
public function getPaiements(): Collection
{
return $this->paiements;
}
public function addPaiement(PaiementFournisseur $paiement): static
{
if (!$this->paiements->contains($paiement)) {
$this->paiements->add($paiement);
$paiement->setFournisseur($this);
}
return $this;
}
public function removePaiement(PaiementFournisseur $paiement): static
{
if ($this->paiements->removeElement($paiement)) {
if ($paiement->getFournisseur() === $this) {
$paiement->setFournisseur(null);
}
}
return $this;
}
/**
* @return Collection<int, EntreeStock>
*/
public function getEntreesStock(): Collection
{
return $this->entreesStock;
}
public function addEntreeStock(EntreeStock $entreeStock): static
{
if (!$this->entreesStock->contains($entreeStock)) {
$this->entreesStock->add($entreeStock);
$entreeStock->setFournisseur($this);
}
return $this;
}
public function removeEntreeStock(EntreeStock $entreeStock): static
{
if ($this->entreesStock->removeElement($entreeStock)) {
if ($entreeStock->getFournisseur() === $this) {
$entreeStock->setFournisseur(null);
}
}
return $this;
}
/**
* Calcule le total des achats chez ce fournisseur
*/
public function getTotalAchats(): float
{
$total = 0;
foreach ($this->achats as $achat) {
$total += $achat->getMontantTotal();
}
return $total;
}
/**
* Calcule le total des dettes envers ce fournisseur
*/
public function getTotalDettes(): float
{
$total = 0;
foreach ($this->dettes as $dette) {
if (!$dette->isEstPayee()) {
$total += $dette->getMontantRestant();
}
}
return $total;
}
/**
* Calcule le total payé à ce fournisseur
*/
public function getTotalPaye(): float
{
$total = 0;
foreach ($this->paiements as $paiement) {
$total += $paiement->getMontant();
}
return $total;
}
/**
* @return Collection<int, CommandeFournisseur>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(CommandeFournisseur $commande): static
{
if (!$this->commandes->contains($commande)) {
$this->commandes->add($commande);
$commande->setFournisseur($this);
}
return $this;
}
public function removeCommande(CommandeFournisseur $commande): static
{
if ($this->commandes->removeElement($commande)) {
if ($commande->getFournisseur() === $this) {
$commande->setFournisseur(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->nom ?? '';
}
}