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. * @return Collection|Subscription[]
  133. */
  134. public function getSubscriptions(): Collection
  135. {
  136. return $this->subscriptions;
  137. }
  138. public function addSubscription(Subscription $subscription): self
  139. {
  140. if (!$this->subscriptions->contains($subscription)) {
  141. $this->subscriptions[] = $subscription;
  142. $subscription->setSchoolYear($this);
  143. }
  144. return $this;
  145. }
  146. public function removeSubscription(Subscription $subscription): self
  147. {
  148. if ($this->subscriptions->removeElement($subscription)) {
  149. // set the owning side to null (unless already changed)
  150. if ($subscription->getSchoolYear() === $this) {
  151. $subscription->setSchoolYear(null);
  152. }
  153. }
  154. return $this;
  155. }
  156. public function getPaymentPlan(): ?PaymentPlan
  157. {
  158. return $this->paymentPlan;
  159. }
  160. public function setPaymentPlan(?PaymentPlan $paymentPlan): static
  161. {
  162. // unset the owning side of the relation if necessary
  163. if ($paymentPlan === null && $this->paymentPlan !== null) {
  164. $this->paymentPlan->setSchoolYear(null);
  165. }
  166. // set the owning side of the relation if necessary
  167. if ($paymentPlan !== null && $paymentPlan->getSchoolYear() !== $this) {
  168. $paymentPlan->setSchoolYear($this);
  169. }
  170. $this->paymentPlan = $paymentPlan;
  171. return $this;
  172. }
  173. public function getRegistrationDeadline(): ?\DateTimeInterface
  174. {
  175. return $this->registrationDeadline;
  176. }
  177. public function setRegistrationDeadline(?\DateTimeInterface $registrationDeadline): static
  178. {
  179. $this->registrationDeadline = $registrationDeadline;
  180. return $this;
  181. }
  182. // the minimum amount that students in good standing must already have paid
  183. public function paymentThresholdAmount(ClassRoom $room){
  184. $sum = 0;
  185. try {
  186. $installments = $this->getPaymentPlan()->getInstallments();
  187. $currentDate = date("d F Y");
  188. foreach($installments as $installment){
  189. if($installment->getClassRoom()==$room){
  190. if($installment->getDeadline()>=$currentDate){
  191. $sum += $installment->getAmount();
  192. }
  193. }
  194. }
  195. } catch (\Throwable $e) {
  196. // Gérer l'erreur ici
  197. $result = null; // Ou toute autre valeur par défaut que vous souhaitez définir
  198. }
  199. return $sum;
  200. }
  201. }