src/Entity/Federation.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FederationRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=FederationRepository::class)
  9. */
  10. class Federation
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=155)
  20. */
  21. private $nom;
  22. /**
  23. * @ORM\Column(type="string", length=255, nullable=true)
  24. */
  25. private $adresse;
  26. /**
  27. * @ORM\Column(type="string", length=25, nullable=true)
  28. */
  29. private $telephone;
  30. /**
  31. * @ORM\OneToMany(targetEntity=Membre::class, mappedBy="federation")
  32. */
  33. private $membres;
  34. /**
  35. * @ORM\ManyToOne(targetEntity=Province::class, inversedBy="federations")
  36. */
  37. private $province;
  38. /**
  39. * @ORM\Column(type="string", length=175, nullable=true)
  40. */
  41. private $president;
  42. /**
  43. * @ORM\OneToOne(targetEntity=User::class, inversedBy="federation", cascade={"persist", "remove"})
  44. */
  45. private $user;
  46. /**
  47. * @ORM\OneToMany(targetEntity=Demande::class, mappedBy="federation")
  48. */
  49. private $demandes;
  50. /**
  51. * @ORM\OneToMany(targetEntity=Communique::class, mappedBy="federation")
  52. */
  53. private $communiques;
  54. /**
  55. * @ORM\OneToOne(targetEntity=Ville::class, inversedBy="federation", cascade={"persist", "remove"})
  56. */
  57. private $ville;
  58. private $cotisationMensuelle;
  59. private $cotisationDernierMois;
  60. private $cotisationProgression;
  61. public function __construct()
  62. {
  63. $this->membres = new ArrayCollection();
  64. $this->demandes = new ArrayCollection();
  65. $this->communiques = new ArrayCollection();
  66. }
  67. public function getId(): ?int
  68. {
  69. return $this->id;
  70. }
  71. public function getNom(): ?string
  72. {
  73. return $this->nom;
  74. }
  75. public function setNom(string $nom): self
  76. {
  77. $this->nom = $nom;
  78. return $this;
  79. }
  80. public function getAdresse(): ?string
  81. {
  82. return $this->adresse;
  83. }
  84. public function setAdresse(?string $adresse): self
  85. {
  86. $this->adresse = $adresse;
  87. return $this;
  88. }
  89. public function getTelephone(): ?string
  90. {
  91. return $this->telephone;
  92. }
  93. public function setTelephone(?string $telephone): self
  94. {
  95. $this->telephone = $telephone;
  96. return $this;
  97. }
  98. /**
  99. * @return Collection<int, Membre>
  100. */
  101. public function getMembres(): Collection
  102. {
  103. return $this->membres;
  104. }
  105. public function addMembre(Membre $membre): self
  106. {
  107. if (!$this->membres->contains($membre)) {
  108. $this->membres[] = $membre;
  109. $membre->setFederation($this);
  110. }
  111. return $this;
  112. }
  113. public function removeMembre(Membre $membre): self
  114. {
  115. if ($this->membres->removeElement($membre)) {
  116. // set the owning side to null (unless already changed)
  117. if ($membre->getFederation() === $this) {
  118. $membre->setFederation(null);
  119. }
  120. }
  121. return $this;
  122. }
  123. public function getProvince(): ?Province
  124. {
  125. return $this->province;
  126. }
  127. public function setProvince(?Province $province): self
  128. {
  129. $this->province = $province;
  130. return $this;
  131. }
  132. public function getPresident(): ?string
  133. {
  134. return $this->president;
  135. }
  136. public function setPresident(?string $president): self
  137. {
  138. $this->president = $president;
  139. return $this;
  140. }
  141. public function getUser(): ?User
  142. {
  143. return $this->user;
  144. }
  145. public function setUser(?User $user): self
  146. {
  147. $this->user = $user;
  148. return $this;
  149. }
  150. /**
  151. * @return Collection<int, Demande>
  152. */
  153. public function getDemandes(): Collection
  154. {
  155. return $this->demandes;
  156. }
  157. public function addDemande(Demande $demande): self
  158. {
  159. if (!$this->demandes->contains($demande)) {
  160. $this->demandes[] = $demande;
  161. $demande->setFederation($this);
  162. }
  163. return $this;
  164. }
  165. public function removeDemande(Demande $demande): self
  166. {
  167. if ($this->demandes->removeElement($demande)) {
  168. // set the owning side to null (unless already changed)
  169. if ($demande->getFederation() === $this) {
  170. $demande->setFederation(null);
  171. }
  172. }
  173. return $this;
  174. }
  175. /**
  176. * @return Collection<int, Communique>
  177. */
  178. public function getCommuniques(): Collection
  179. {
  180. return $this->communiques;
  181. }
  182. public function addCommunique(Communique $communique): self
  183. {
  184. if (!$this->communiques->contains($communique)) {
  185. $this->communiques[] = $communique;
  186. $communique->setFederation($this);
  187. }
  188. return $this;
  189. }
  190. public function removeCommunique(Communique $communique): self
  191. {
  192. if ($this->communiques->removeElement($communique)) {
  193. // set the owning side to null (unless already changed)
  194. if ($communique->getFederation() === $this) {
  195. $communique->setFederation(null);
  196. }
  197. }
  198. return $this;
  199. }
  200. public function getVille(): ?Ville
  201. {
  202. return $this->ville;
  203. }
  204. public function setVille(?Ville $ville): self
  205. {
  206. $this->ville = $ville;
  207. return $this;
  208. }
  209. public function getCotisationMensuelle(){
  210. $this->setCotisationMensuelle();
  211. return $this->cotisationMensuelle;
  212. }
  213. public function setCotisationMensuelle(){
  214. $dateLimiteF = new \Datetime();
  215. $dateDepartF = new \Datetime();
  216. $totalCotisation = 0;
  217. $dateDepart = date("Y-m-d", strtotime("first day of this month"));
  218. $dateLimite = date("Y-m-d", strtotime("last day of this month"));
  219. foreach($this->membres as $membre){
  220. foreach($membre->getCotisations() as $cotisation){
  221. $dateFormat = $cotisation->getDate()->format('Y-m-d');
  222. $dateCotisation = date('Y-m-d', strtotime($dateFormat));
  223. if (($dateCotisation >= $dateDepart) && ($dateCotisation <= $dateLimite)){
  224. $totalCotisation += $cotisation->getMontant();
  225. }
  226. }
  227. }
  228. $this->cotisationMensuelle = $totalCotisation;
  229. }
  230. public function getCotisationDernierMois(){
  231. $this->setCotisationDernierMois();
  232. return $this->cotisationDernierMois;
  233. }
  234. public function setCotisationDernierMois(){
  235. $dateLimiteF = new \Datetime();
  236. $dateDepartF = new \Datetime();
  237. $totalCotisation = 0;
  238. $dateDepart = date("Y-m-d", strtotime("first day of last month"));
  239. $dateLimite = date("Y-m-d", strtotime("last day of last month"));
  240. foreach($this->membres as $membre){
  241. foreach($membre->getCotisations() as $cotisation){
  242. $dateFormat = $cotisation->getDate()->format('Y-m-d');
  243. $dateCotisation = date('Y-m-d', strtotime($dateFormat));
  244. if (($dateCotisation >= $dateDepart) && ($dateCotisation <= $dateLimite)){
  245. $totalCotisation += $cotisation->getMontant();
  246. }
  247. }
  248. }
  249. $this->cotisationDernierMois = $totalCotisation;
  250. }
  251. public function getCotisationProgression(){
  252. $this->setCotisationProgression();
  253. return $this->cotisationProgression;
  254. }
  255. public function setCotisationProgression(){
  256. $difference = $this->getCotisationMensuelle() - $this->getCotisationDernierMois();
  257. if ($this->getCotisationDernierMois() != 0){
  258. $progression = ($difference / $this->getCotisationDernierMois() ) * 100;
  259. }else{
  260. $progression = null;
  261. }
  262. $this->cotisationProgression = $progression;
  263. }
  264. }