<?phpnamespace App\Entity;use App\Repository\FactureRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: FactureRepository::class)]class Facture{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 255)] private ?string $type = null; #[ORM\Column(length: 255, nullable: true)] private ?string $statutPaiement = null; #[ORM\Column] private ?float $montantTotal = null; #[ORM\ManyToOne(inversedBy: 'factures')] private ?Vente $vente = null; #[ORM\OneToMany(mappedBy: 'facture', targetEntity: Echeance::class)] private Collection $echeance; #[ORM\Column(type: Types::DATETIME_MUTABLE)] private ?\DateTimeInterface $createdAt = null; #[ORM\ManyToOne(inversedBy: 'facture')] private ?Client $client = null; #[ORM\Column(nullable: true)] private ?float $montantPaye = null; #[ORM\Column(length: 255, nullable: true)] private ?string $TypePaiement = null; public function __construct() { $this->createdAt = new \DateTime(); $this->echeance = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getType(): ?string { return $this->type; } public function setType(string $type): static { $this->type = $type; return $this; } public function getStatutPaiement(): ?string { return $this->statutPaiement; } public function setStatutPaiement(?string $statutPaiement): static { $this->statutPaiement = $statutPaiement; return $this; } public function getMontantTotal(): ?float { return $this->montantTotal; } public function setMontantTotal(float $montantTotal): static { $this->montantTotal = $montantTotal; return $this; } public function getVente(): ?Vente { return $this->vente; } public function setVente(?Vente $vente): static { $this->vente = $vente; return $this; } /** * @return Collection<int, Echeance> */ public function getEcheance(): Collection { return $this->echeance; } public function addEcheance(Echeance $echeance): static { if (!$this->echeance->contains($echeance)) { $this->echeance->add($echeance); $echeance->setFacture($this); } return $this; } public function removeEcheance(Echeance $echeance): static { if ($this->echeance->removeElement($echeance)) { // set the owning side to null (unless already changed) if ($echeance->getFacture() === $this) { $echeance->setFacture(null); } } return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(\DateTimeInterface $createdAt): static { $this->createdAt = $createdAt; return $this; } public function getClient(): ?Client { return $this->client; } public function setClient(?Client $client): static { $this->client = $client; return $this; } public function getMontantPaye(): ?float { return $this->montantPaye; } public function setMontantPaye(?float $montantPaye): static { $this->montantPaye = $montantPaye; return $this; } public function calculerMontantPaye(): float { $montantPaye = 0; foreach ($this->echeance as $echeance) { if ($echeance->isIsPaid()) { $montantPaye += $echeance->getAmount(); } } return $montantPaye; } public function getResteAPayer(): float { return $this->montantTotal - $this->calculerMontantPaye(); } public function getTypePaiement(): ?string { return $this->TypePaiement; } public function setTypePaiement(?string $TypePaiement): static { $this->TypePaiement = $TypePaiement; return $this; }}