src/Entity/FactureFournisseur.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FactureFournisseurRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassFactureFournisseurRepository::class)]
  9. class FactureFournisseur
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length100uniquetrue)]
  16.     private ?string $numeroFacture null;
  17.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  18.     private ?\DateTimeInterface $dateFacture null;
  19.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  20.     private ?\DateTimeInterface $dateEcheance null;
  21.     #[ORM\ManyToOne(inversedBy'factures')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?Fournisseur $fournisseur null;
  24.     #[ORM\Column]
  25.     private ?float $montantHT null;
  26.     #[ORM\Column]
  27.     private ?float $montantTVA null;
  28.     #[ORM\Column]
  29.     private ?float $montantTTC null;
  30.     #[ORM\Column]
  31.     private ?float $montantPaye 0;
  32.     #[ORM\Column(length50)]
  33.     private ?string $statut 'EN_ATTENTE'// EN_ATTENTE, PARTIELLEMENT_PAYEE, PAYEE
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     private ?string $notes null;
  36.     #[ORM\ManyToOne]
  37.     private ?Boutique $boutique null;
  38.     #[ORM\ManyToOne]
  39.     private ?User $creePar null;
  40.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  41.     private ?\DateTimeInterface $createdAt null;
  42.     #[ORM\OneToMany(mappedBy'factureFournisseur'targetEntityPaiementFournisseur::class)]
  43.     private Collection $paiements;
  44.     #[ORM\OneToMany(mappedBy'factureFournisseur'targetEntityEntreeStock::class)]
  45.     private Collection $entreesStock;
  46.     public function __construct()
  47.     {
  48.         $this->paiements = new ArrayCollection();
  49.         $this->entreesStock = new ArrayCollection();
  50.         $this->createdAt = new \DateTime();
  51.         $this->dateFacture = new \DateTime();
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getNumeroFacture(): ?string
  58.     {
  59.         return $this->numeroFacture;
  60.     }
  61.     public function setNumeroFacture(string $numeroFacture): static
  62.     {
  63.         $this->numeroFacture $numeroFacture;
  64.         return $this;
  65.     }
  66.     public function getDateFacture(): ?\DateTimeInterface
  67.     {
  68.         return $this->dateFacture;
  69.     }
  70.     public function setDateFacture(\DateTimeInterface $dateFacture): static
  71.     {
  72.         $this->dateFacture $dateFacture;
  73.         return $this;
  74.     }
  75.     public function getDateEcheance(): ?\DateTimeInterface
  76.     {
  77.         return $this->dateEcheance;
  78.     }
  79.     public function setDateEcheance(?\DateTimeInterface $dateEcheance): static
  80.     {
  81.         $this->dateEcheance $dateEcheance;
  82.         return $this;
  83.     }
  84.     public function getFournisseur(): ?Fournisseur
  85.     {
  86.         return $this->fournisseur;
  87.     }
  88.     public function setFournisseur(?Fournisseur $fournisseur): static
  89.     {
  90.         $this->fournisseur $fournisseur;
  91.         return $this;
  92.     }
  93.     public function getMontantHT(): ?float
  94.     {
  95.         return $this->montantHT;
  96.     }
  97.     public function setMontantHT(float $montantHT): static
  98.     {
  99.         $this->montantHT $montantHT;
  100.         return $this;
  101.     }
  102.     public function getMontantTVA(): ?float
  103.     {
  104.         return $this->montantTVA;
  105.     }
  106.     public function setMontantTVA(float $montantTVA): static
  107.     {
  108.         $this->montantTVA $montantTVA;
  109.         return $this;
  110.     }
  111.     public function getMontantTTC(): ?float
  112.     {
  113.         return $this->montantTTC;
  114.     }
  115.     public function setMontantTTC(float $montantTTC): static
  116.     {
  117.         $this->montantTTC $montantTTC;
  118.         return $this;
  119.     }
  120.     public function getMontantPaye(): ?float
  121.     {
  122.         return $this->montantPaye;
  123.     }
  124.     public function setMontantPaye(float $montantPaye): static
  125.     {
  126.         $this->montantPaye $montantPaye;
  127.         return $this;
  128.     }
  129.     public function getStatut(): ?string
  130.     {
  131.         return $this->statut;
  132.     }
  133.     public function setStatut(string $statut): static
  134.     {
  135.         $this->statut $statut;
  136.         return $this;
  137.     }
  138.     public function getNotes(): ?string
  139.     {
  140.         return $this->notes;
  141.     }
  142.     public function setNotes(?string $notes): static
  143.     {
  144.         $this->notes $notes;
  145.         return $this;
  146.     }
  147.     public function getBoutique(): ?Boutique
  148.     {
  149.         return $this->boutique;
  150.     }
  151.     public function setBoutique(?Boutique $boutique): static
  152.     {
  153.         $this->boutique $boutique;
  154.         return $this;
  155.     }
  156.     public function getCreePar(): ?User
  157.     {
  158.         return $this->creePar;
  159.     }
  160.     public function setCreePar(?User $creePar): static
  161.     {
  162.         $this->creePar $creePar;
  163.         return $this;
  164.     }
  165.     public function getCreatedAt(): ?\DateTimeInterface
  166.     {
  167.         return $this->createdAt;
  168.     }
  169.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  170.     {
  171.         $this->createdAt $createdAt;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return Collection<int, PaiementFournisseur>
  176.      */
  177.     public function getPaiements(): Collection
  178.     {
  179.         return $this->paiements;
  180.     }
  181.     public function addPaiement(PaiementFournisseur $paiement): static
  182.     {
  183.         if (!$this->paiements->contains($paiement)) {
  184.             $this->paiements->add($paiement);
  185.             $paiement->setFactureFournisseur($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removePaiement(PaiementFournisseur $paiement): static
  190.     {
  191.         if ($this->paiements->removeElement($paiement)) {
  192.             if ($paiement->getFactureFournisseur() === $this) {
  193.                 $paiement->setFactureFournisseur(null);
  194.             }
  195.         }
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return Collection<int, EntreeStock>
  200.      */
  201.     public function getEntreesStock(): Collection
  202.     {
  203.         return $this->entreesStock;
  204.     }
  205.     public function addEntreeStock(EntreeStock $entreeStock): static
  206.     {
  207.         if (!$this->entreesStock->contains($entreeStock)) {
  208.             $this->entreesStock->add($entreeStock);
  209.             $entreeStock->setFactureFournisseur($this);
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeEntreeStock(EntreeStock $entreeStock): static
  214.     {
  215.         if ($this->entreesStock->removeElement($entreeStock)) {
  216.             if ($entreeStock->getFactureFournisseur() === $this) {
  217.                 $entreeStock->setFactureFournisseur(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222.     /**
  223.      * Calcule le reste à payer
  224.      */
  225.     public function getResteAPayer(): float
  226.     {
  227.         return $this->montantTTC $this->montantPaye;
  228.     }
  229.     /**
  230.      * Met à jour le montant payé en calculant depuis les paiements
  231.      */
  232.     public function updateMontantPaye(): void
  233.     {
  234.         $total 0;
  235.         foreach ($this->paiements as $paiement) {
  236.             $total += $paiement->getMontant();
  237.         }
  238.         $this->montantPaye $total;
  239.         
  240.         // Mettre à jour le statut
  241.         $this->updateStatut();
  242.     }
  243.     /**
  244.      * Met à jour le statut de la facture
  245.      */
  246.     public function updateStatut(): void
  247.     {
  248.         if ($this->montantPaye >= $this->montantTTC) {
  249.             $this->statut 'PAYEE';
  250.         } elseif ($this->montantPaye 0) {
  251.             $this->statut 'PARTIELLEMENT_PAYEE';
  252.         } else {
  253.             $this->statut 'EN_ATTENTE';
  254.         }
  255.     }
  256.     /**
  257.      * Vérifie si la facture est totalement payée
  258.      */
  259.     public function isPayee(): bool
  260.     {
  261.         return $this->statut === 'PAYEE';
  262.     }
  263.     /**
  264.      * Calcule le pourcentage de paiement
  265.      */
  266.     public function getPourcentagePaiement(): float
  267.     {
  268.         if ($this->montantTTC <= 0) {
  269.             return 0;
  270.         }
  271.         return min(100, ($this->montantPaye $this->montantTTC) * 100);
  272.     }
  273.     public function __toString(): string
  274.     {
  275.         return $this->numeroFacture ?? '';
  276.     }
  277. }