<?php
namespace App\Entity;
use App\Repository\FederationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=FederationRepository::class)
*/
class Federation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=155)
*/
private $nom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
private $telephone;
/**
* @ORM\OneToMany(targetEntity=Membre::class, mappedBy="federation")
*/
private $membres;
/**
* @ORM\ManyToOne(targetEntity=Province::class, inversedBy="federations")
*/
private $province;
/**
* @ORM\Column(type="string", length=175, nullable=true)
*/
private $president;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="federation", cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=Demande::class, mappedBy="federation")
*/
private $demandes;
/**
* @ORM\OneToMany(targetEntity=Communique::class, mappedBy="federation")
*/
private $communiques;
/**
* @ORM\OneToOne(targetEntity=Ville::class, inversedBy="federation", cascade={"persist", "remove"})
*/
private $ville;
private $cotisationMensuelle;
private $cotisationDernierMois;
private $cotisationProgression;
public function __construct()
{
$this->membres = new ArrayCollection();
$this->demandes = new ArrayCollection();
$this->communiques = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
/**
* @return Collection<int, Membre>
*/
public function getMembres(): Collection
{
return $this->membres;
}
public function addMembre(Membre $membre): self
{
if (!$this->membres->contains($membre)) {
$this->membres[] = $membre;
$membre->setFederation($this);
}
return $this;
}
public function removeMembre(Membre $membre): self
{
if ($this->membres->removeElement($membre)) {
// set the owning side to null (unless already changed)
if ($membre->getFederation() === $this) {
$membre->setFederation(null);
}
}
return $this;
}
public function getProvince(): ?Province
{
return $this->province;
}
public function setProvince(?Province $province): self
{
$this->province = $province;
return $this;
}
public function getPresident(): ?string
{
return $this->president;
}
public function setPresident(?string $president): self
{
$this->president = $president;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Demande>
*/
public function getDemandes(): Collection
{
return $this->demandes;
}
public function addDemande(Demande $demande): self
{
if (!$this->demandes->contains($demande)) {
$this->demandes[] = $demande;
$demande->setFederation($this);
}
return $this;
}
public function removeDemande(Demande $demande): self
{
if ($this->demandes->removeElement($demande)) {
// set the owning side to null (unless already changed)
if ($demande->getFederation() === $this) {
$demande->setFederation(null);
}
}
return $this;
}
/**
* @return Collection<int, Communique>
*/
public function getCommuniques(): Collection
{
return $this->communiques;
}
public function addCommunique(Communique $communique): self
{
if (!$this->communiques->contains($communique)) {
$this->communiques[] = $communique;
$communique->setFederation($this);
}
return $this;
}
public function removeCommunique(Communique $communique): self
{
if ($this->communiques->removeElement($communique)) {
// set the owning side to null (unless already changed)
if ($communique->getFederation() === $this) {
$communique->setFederation(null);
}
}
return $this;
}
public function getVille(): ?Ville
{
return $this->ville;
}
public function setVille(?Ville $ville): self
{
$this->ville = $ville;
return $this;
}
public function getCotisationMensuelle(){
$this->setCotisationMensuelle();
return $this->cotisationMensuelle;
}
public function setCotisationMensuelle(){
$dateLimiteF = new \Datetime();
$dateDepartF = new \Datetime();
$totalCotisation = 0;
$dateDepart = date("Y-m-d", strtotime("first day of this month"));
$dateLimite = date("Y-m-d", strtotime("last day of this month"));
foreach($this->membres as $membre){
foreach($membre->getCotisations() as $cotisation){
$dateFormat = $cotisation->getDate()->format('Y-m-d');
$dateCotisation = date('Y-m-d', strtotime($dateFormat));
if (($dateCotisation >= $dateDepart) && ($dateCotisation <= $dateLimite)){
$totalCotisation += $cotisation->getMontant();
}
}
}
$this->cotisationMensuelle = $totalCotisation;
}
public function getCotisationDernierMois(){
$this->setCotisationDernierMois();
return $this->cotisationDernierMois;
}
public function setCotisationDernierMois(){
$dateLimiteF = new \Datetime();
$dateDepartF = new \Datetime();
$totalCotisation = 0;
$dateDepart = date("Y-m-d", strtotime("first day of last month"));
$dateLimite = date("Y-m-d", strtotime("last day of last month"));
foreach($this->membres as $membre){
foreach($membre->getCotisations() as $cotisation){
$dateFormat = $cotisation->getDate()->format('Y-m-d');
$dateCotisation = date('Y-m-d', strtotime($dateFormat));
if (($dateCotisation >= $dateDepart) && ($dateCotisation <= $dateLimite)){
$totalCotisation += $cotisation->getMontant();
}
}
}
$this->cotisationDernierMois = $totalCotisation;
}
public function getCotisationProgression(){
$this->setCotisationProgression();
return $this->cotisationProgression;
}
public function setCotisationProgression(){
$difference = $this->getCotisationMensuelle() - $this->getCotisationDernierMois();
if ($this->getCotisationDernierMois() != 0){
$progression = ($difference / $this->getCotisationDernierMois() ) * 100;
}else{
$progression = null;
}
$this->cotisationProgression = $progression;
}
}