src/Entity/Facture.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FactureRepository;
  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(repositoryClassFactureRepository::class)]
  9. class Facture
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $type null;
  17.     #[ORM\Column(length255nullabletrue)]
  18.     private ?string $statutPaiement null;
  19.     #[ORM\Column]
  20.     private ?float $montantTotal null;
  21.     #[ORM\ManyToOne(inversedBy'factures')]
  22.     private ?Vente $vente null;
  23.     #[ORM\OneToMany(mappedBy'facture'targetEntityEcheance::class)]
  24.     private Collection $echeance;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  26.     private ?\DateTimeInterface $createdAt null;
  27.     #[ORM\ManyToOne(inversedBy'facture')]
  28.     private ?Client $client null;
  29.     #[ORM\Column(nullabletrue)]
  30.     private ?float $montantPaye null;
  31.     #[ORM\Column(nullabletrue)]
  32.     private ?float $fraisTransport null;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?float $tva null;
  35.     public function __construct()
  36.     {
  37.         $this->createdAt = new \DateTime();
  38.         $this->echeance = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getType(): ?string
  45.     {
  46.         return $this->type;
  47.     }
  48.     public function setType(string $type): static
  49.     {
  50.         $this->type $type;
  51.         return $this;
  52.     }
  53.     public function getStatutPaiement(): ?string
  54.     {
  55.         return $this->statutPaiement;
  56.     }
  57.     public function setStatutPaiement(?string $statutPaiement): static
  58.     {
  59.         $this->statutPaiement $statutPaiement;
  60.         return $this;
  61.     }
  62.     public function getMontantTotal(): ?float
  63.     {
  64.         return $this->montantTotal;
  65.     }
  66.     public function setMontantTotal(float $montantTotal): static
  67.     {
  68.         $this->montantTotal $montantTotal;
  69.         return $this;
  70.     }
  71.     public function getVente(): ?Vente
  72.     {
  73.         return $this->vente;
  74.     }
  75.     public function setVente(?Vente $vente): static
  76.     {
  77.         $this->vente $vente;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection<int, Echeance>
  82.      */
  83.     public function getEcheance(): Collection
  84.     {
  85.         return $this->echeance;
  86.     }
  87.     public function addEcheance(Echeance $echeance): static
  88.     {
  89.         if (!$this->echeance->contains($echeance)) {
  90.             $this->echeance->add($echeance);
  91.             $echeance->setFacture($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeEcheance(Echeance $echeance): static
  96.     {
  97.         if ($this->echeance->removeElement($echeance)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($echeance->getFacture() === $this) {
  100.                 $echeance->setFacture(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105.     public function getCreatedAt(): ?\DateTimeInterface
  106.     {
  107.         return $this->createdAt;
  108.     }
  109.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  110.     {
  111.         $this->createdAt $createdAt;
  112.         return $this;
  113.     }
  114.     public function getClient(): ?Client
  115.     {
  116.         return $this->client;
  117.     }
  118.     public function setClient(?Client $client): static
  119.     {
  120.         $this->client $client;
  121.         return $this;
  122.     }
  123.     public function getMontantPaye(): ?float
  124.     {
  125.         return $this->montantPaye;
  126.     }
  127.     public function setMontantPaye(?float $montantPaye): static
  128.     {
  129.         $this->montantPaye $montantPaye;
  130.         return $this;
  131.     }
  132.     public function calculerMontantPaye(): float
  133.     {
  134.         $montantPaye 0;
  135.         foreach ($this->echeance as $echeance) {
  136.             if ($echeance->isIsPaid()) {
  137.                 $montantPaye += $echeance->getAmount();
  138.             }
  139.         }
  140.         return $montantPaye;
  141.     }
  142.     public function getResteAPayer(): float
  143.     {
  144.         // Inclure les frais de transport dans le calcul
  145.         $montantTotalAvecFrais $this->montantTotal + ($this->fraisTransport ?? 0);
  146.         return $montantTotalAvecFrais $this->calculerMontantPaye();
  147.     }
  148.     public function updateMontantPaye(): void
  149.     {
  150.         $this->montantPaye $this->calculerMontantPaye();
  151.     }
  152.     public function isCompletementPayee(): bool
  153.     {
  154.         // Inclure les frais de transport dans la vérification
  155.         $montantTotalAvecFrais $this->montantTotal + ($this->fraisTransport ?? 0);
  156.         return $this->calculerMontantPaye() >= $montantTotalAvecFrais;
  157.     }
  158.     public function getFraisTransport(): ?float
  159.     {
  160.         return $this->fraisTransport;
  161.     }
  162.     public function setFraisTransport(?float $fraisTransport): static
  163.     {
  164.         $this->fraisTransport $fraisTransport;
  165.         return $this;
  166.     }
  167.     public function getTva(): ?float
  168.     {
  169.         return $this->tva;
  170.     }
  171.     public function setTva(?float $tva): static
  172.     {
  173.         $this->tva $tva;
  174.         return $this;
  175.     }
  176.     /**
  177.      * Calcule le montant total avec frais de transport
  178.      */
  179.     public function getMontantTotalAvecFrais(): float
  180.     {
  181.         return $this->montantTotal + ($this->fraisTransport ?? 0);
  182.     }
  183.     /**
  184.      * Calcule le pourcentage de paiement en tenant compte des frais de transport
  185.      */
  186.     public function getPourcentagePaiement(): float
  187.     {
  188.         $montantTotalAvecFrais $this->getMontantTotalAvecFrais();
  189.         if ($montantTotalAvecFrais <= 0) {
  190.             return 0;
  191.         }
  192.         
  193.         $montantPaye $this->calculerMontantPaye();
  194.         return min(100, ($montantPaye $montantTotalAvecFrais) * 100);
  195.     }
  196. }