src/Entity/SchoolYear.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\ClassRoom;
  4. use App\Entity\Traits\Period;
  5. use App\Entity\PaymentPlan;
  6. use App\Repository\SchoolYearRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. /**
  13.  * @ORM\Entity(repositoryClass=SchoolYearRepository::class)
  14.  *  @UniqueEntity(fields={"code"}, message= "There is already a classroom  with this code")
  15.  */
  16. class SchoolYear
  17. {
  18.     use Period;
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="date", nullable=true)
  27.      */
  28.     private $registrationDeadline;
  29.     /**
  30.      * @var int
  31.      *
  32.      * @ORM\Column(name="rate", type="integer")
  33.      */
  34.     private $rate;
  35.     public function __toString()
  36.     {
  37.         $name = (is_null($this->getWording())) ? "" $this->getWording();
  38.         return (string) ($name);
  39.     }
  40.     public function unable()
  41.     {
  42.         $this->setActivated(true);
  43.         if (count($this->getQuaters()) > 0)
  44.             $this->getQuaters()[0]->unable();
  45.     }
  46.     public function disable()
  47.     {
  48.         $this->setActivated(false);
  49.         foreach ($this->getQuaters() as $quater) {
  50.             $quater->disable();
  51.         }
  52.     }
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=Quater::class, mappedBy="schoolYear", orphanRemoval=true, cascade={"persist"})
  55.      */
  56.     private $quaters;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="schoolYear")
  59.      */
  60.     private $subscriptions;
  61.     /**
  62.      * @ORM\OneToOne(targetEntity=PaymentPlan::class, mappedBy="schoolYear")
  63.      */
  64.     private $paymentPlan;
  65.     public function __construct()
  66.     {
  67.         $this->quaters = new ArrayCollection();
  68.         $this->activated true;
  69.         $this->subscriptions = new ArrayCollection();
  70.         $this->paymentPlans = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     /**
  77.      * Set rate
  78.      *
  79.      * @param integer $reductionPrime
  80.      *
  81.      * @return SchoolYear
  82.      */
  83.     public function setRate($reductionPrime)
  84.     {
  85.         $this->rate $reductionPrime;
  86.         return $this;
  87.     }
  88.     /**
  89.      * Get rate
  90.      *
  91.      * @return integer
  92.      */
  93.     public function getRate()
  94.     {
  95.         return $this->rate;
  96.     }
  97.     /**
  98.      * @return Collection|Quater[]
  99.      */
  100.     public function getQuaters(): Collection
  101.     {
  102.         return $this->quaters;
  103.     }
  104.     public function addQuater(Quater $quater): self
  105.     {
  106.         if (!$this->quaters->contains($quater)) {
  107.             $this->quaters[] = $quater;
  108.             $quater->setSchoolYear($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeQuater(Quater $quater): self
  113.     {
  114.         if ($this->quaters->removeElement($quater)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($quater->getSchoolYear() === $this) {
  117.                 $quater->setSchoolYear(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.      /**
  123.      * Get amountofTuition
  124.      *
  125.      * @param ClassRoom $room
  126.      *
  127.      * @return integer
  128.      */
  129.     public function amountofTuition(ClassRoom $room) {
  130.         
  131.     }
  132.     /**
  133.      * @return Collection|Subscription[]
  134.      */
  135.     public function getSubscriptions(): Collection
  136.     {
  137.         return $this->subscriptions;
  138.     }
  139.     public function addSubscription(Subscription $subscription): self
  140.     {
  141.         if (!$this->subscriptions->contains($subscription)) {
  142.             $this->subscriptions[] = $subscription;
  143.             $subscription->setSchoolYear($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeSubscription(Subscription $subscription): self
  148.     {
  149.         if ($this->subscriptions->removeElement($subscription)) {
  150.             // set the owning side to null (unless already changed)
  151.             if ($subscription->getSchoolYear() === $this) {
  152.                 $subscription->setSchoolYear(null);
  153.             }
  154.         }
  155.         return $this;
  156.     }
  157.     public function getPaymentPlan(): ?PaymentPlan
  158.     {
  159.         return $this->paymentPlan;
  160.     }
  161.     public function setPaymentPlan(?PaymentPlan $paymentPlan): static
  162.     {
  163.         // unset the owning side of the relation if necessary
  164.         if ($paymentPlan === null && $this->paymentPlan !== null) {
  165.             $this->paymentPlan->setSchoolYear(null);
  166.         }
  167.         // set the owning side of the relation if necessary
  168.         if ($paymentPlan !== null && $paymentPlan->getSchoolYear() !== $this) {
  169.             $paymentPlan->setSchoolYear($this);
  170.         }
  171.         $this->paymentPlan $paymentPlan;
  172.         return $this;
  173.     }
  174.     public function getRegistrationDeadline(): ?\DateTimeInterface
  175.     {
  176.         return $this->registrationDeadline;
  177.     }
  178.     public function setRegistrationDeadline(?\DateTimeInterface $registrationDeadline): static
  179.     {
  180.         $this->registrationDeadline $registrationDeadline;
  181.         return $this;
  182.     }
  183.     // the minimum amount that students in good standing must already have paid
  184.     public function paymentThresholdAmount(ClassRoom $room){
  185.         $sum 0;
  186.             try {
  187.             $installments =  $this->getPaymentPlan()->getInstallments();
  188.             $currentDate date("d F Y");
  189.             foreach($installments as $installment){
  190.                 if($installment->getClassRoom()==$room){
  191.                     if($installment->getDeadline()>=$currentDate){
  192.                         $sum += $installment->getAmount();
  193.                     }
  194.                 }
  195.             }
  196.         } catch (\Throwable $e) {
  197.             // Gérer l'erreur ici
  198.             $result null// Ou toute autre valeur par défaut que vous souhaitez définir
  199.         }
  200.         return $sum;
  201.     }
  202. }