src/Entity/Fee.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FeeRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. /**
  8.  * @ORM\Entity(repositoryClass=FeeRepository::class)
  9.  */
  10. class Fee
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\ManyToMany(targetEntity=Promotion::class, inversedBy="fees")
  20.      * @ORM\JoinTable(name="fee_promotion")
  21.      */
  22.     private $promotions;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=SchoolYear::class, inversedBy="fees")
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $schoolYear;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=School::class, inversedBy="fees")
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $school;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $name;
  37.     /**
  38.      * @ORM\Column(type="decimal", precision=10, scale=2)
  39.      */
  40.     private $amount;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=Currency::class)
  43.      * @ORM\JoinColumn(nullable=false)
  44.      */
  45.     private $currency;
  46.     /**
  47.      * @ORM\Column(type="datetime_immutable")
  48.      */
  49.     private $createdAt;
  50.     /**
  51.      * @ORM\Column(type="datetime_immutable", nullable=true)
  52.      */
  53.     private $updatedAt;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="fee")
  56.      */
  57.     private $payments;
  58.     public function __construct()
  59.     {
  60.         $this->promotions = new ArrayCollection();
  61.         $this->payments = new ArrayCollection();
  62.     }
  63.     public function __toString(): string
  64.     {
  65.         return $this->name ' - ' $this->amount ' ' . ($this->currency $this->currency->getSymbol() : '');
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     /**
  72.      * @return Collection<int, Promotion>
  73.      */
  74.     public function getPromotions(): Collection
  75.     {
  76.         return $this->promotions;
  77.     }
  78.     public function addPromotion(Promotion $promotion): self
  79.     {
  80.         if (!$this->promotions->contains($promotion)) {
  81.             $this->promotions->add($promotion);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removePromotion(Promotion $promotion): self
  86.     {
  87.         $this->promotions->removeElement($promotion);
  88.         return $this;
  89.     }
  90.     public function getSchoolYear(): ?SchoolYear
  91.     {
  92.         return $this->schoolYear;
  93.     }
  94.     public function setSchoolYear(?SchoolYear $schoolYear): self
  95.     {
  96.         $this->schoolYear $schoolYear;
  97.         return $this;
  98.     }
  99.     public function getSchool(): ?School
  100.     {
  101.         return $this->school;
  102.     }
  103.     public function setSchool(?School $school): self
  104.     {
  105.         $this->school $school;
  106.         return $this;
  107.     }
  108.     public function getName(): ?string
  109.     {
  110.         return $this->name;
  111.     }
  112.     public function setName(string $name): self
  113.     {
  114.         $this->name $name;
  115.         return $this;
  116.     }
  117.     public function getAmount(): ?float
  118.     {
  119.         return $this->amount ? (float) $this->amount null;
  120.     }
  121.     public function setAmount(float $amount): self
  122.     {
  123.         $this->amount $amount;
  124.         return $this;
  125.     }
  126.     public function getCurrency(): ?Currency
  127.     {
  128.         return $this->currency;
  129.     }
  130.     public function setCurrency(?Currency $currency): self
  131.     {
  132.         $this->currency $currency;
  133.         return $this;
  134.     }
  135.     public function getCreatedAt(): ?\DateTimeImmutable
  136.     {
  137.         return $this->createdAt;
  138.     }
  139.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  140.     {
  141.         $this->createdAt $createdAt;
  142.         return $this;
  143.     }
  144.     public function getUpdatedAt(): ?\DateTimeImmutable
  145.     {
  146.         return $this->updatedAt;
  147.     }
  148.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  149.     {
  150.         $this->updatedAt $updatedAt;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return Collection<int, Payment>
  155.      */
  156.     public function getPayments(): Collection
  157.     {
  158.         return $this->payments;
  159.     }
  160.     public function addPayment(Payment $payment): self
  161.     {
  162.         if (!$this->payments->contains($payment)) {
  163.             $this->payments->add($payment);
  164.             $payment->setFee($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removePayment(Payment $payment): self
  169.     {
  170.         if ($this->payments->removeElement($payment)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($payment->getFee() === $this) {
  173.                 $payment->setFee(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     /**
  179.      * Calcule le montant total payé pour ce frais
  180.      */
  181.     public function getTotalAmountPaid(): float
  182.     {
  183.         $total 0;
  184.         foreach ($this->payments as $payment) {
  185.             $total += (float) $payment->getAmountPaid();
  186.         }
  187.         return $total;
  188.     }
  189.     /**
  190.      * Calcule le montant restant à payer
  191.      */
  192.     public function getRemainingAmount(): float
  193.     {
  194.         return (float) $this->amount $this->getTotalAmountPaid();
  195.     }
  196.     /**
  197.      * Vérifie si le frais est complètement payé
  198.      */
  199.     public function isFullyPaid(): bool
  200.     {
  201.         return $this->getRemainingAmount() <= 0;
  202.     }
  203.     /**
  204.      * Calcule le pourcentage de paiement
  205.      */
  206.     public function getPaymentPercentage(): float
  207.     {
  208.         if ((float) $this->amount <= 0) {
  209.             return 0;
  210.         }
  211.         return ($this->getTotalAmountPaid() / (float) $this->amount) * 100;
  212.     }