<?php
namespace App\Entity;
use App\Repository\MembreRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=MembreRepository::class)
*/
class Membre
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Federation::class, inversedBy="membres")
*/
private $federation;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="membre", cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $adhesion;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* @ORM\OneToMany(targetEntity=Cotisation::class, mappedBy="membre")
*/
private $cotisations;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $cadre;
/**
* @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="membre")
*/
private $transactions;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $carte;
private $dette;
public function __construct()
{
$this->cotisations = new ArrayCollection();
$this->transactions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFederation(): ?Federation
{
return $this->federation;
}
public function setFederation(?Federation $federation): self
{
$this->federation = $federation;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getAdhesion(): ?\DateTimeInterface
{
return $this->adhesion;
}
public function setAdhesion(?\DateTimeInterface $adhesion): self
{
$this->adhesion = $adhesion;
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @return Collection<int, Cotisation>
*/
public function getCotisations(): Collection
{
return $this->cotisations;
}
public function addCotisation(Cotisation $cotisation): self
{
if (!$this->cotisations->contains($cotisation)) {
$this->cotisations[] = $cotisation;
$cotisation->setMembre($this);
}
return $this;
}
public function removeCotisation(Cotisation $cotisation): self
{
if ($this->cotisations->removeElement($cotisation)) {
// set the owning side to null (unless already changed)
if ($cotisation->getMembre() === $this) {
$cotisation->setMembre(null);
}
}
return $this;
}
public function setDette($cotisations){
$montant = 0;
foreach($cotisations as $cotisation){
$montant += $cotisation->getMontant();
}
$date1 = $this->getAdhesion();
$date1F = '2023-01-01';
$date2 = date("Y/m/d");
$ts1 = strtotime($date1F);
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
if($this->cadre == true){
$dette = $diff * 10000;
}else{
$dette = $diff * 2000;
}
$this->dette = $dette - $montant;
}
public function getDette(): ?int
{
$this->setDette($this->cotisations);
return $this->dette;
}
public function getCadre(): ?bool
{
return $this->cadre;
}
public function setCadre(?bool $cadre): self
{
$this->cadre = $cadre;
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): self
{
if (!$this->transactions->contains($transaction)) {
$this->transactions[] = $transaction;
$transaction->setMembre($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): self
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getMembre() === $this) {
$transaction->setMembre(null);
}
}
return $this;
}
public function getCarte(): ?bool
{
return $this->carte;
}
public function setCarte(?bool $carte): self
{
$this->carte = $carte;
return $this;
}
}