<?php
namespace App\Entity;
use App\Repository\EmployeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmployeRepository::class)]
class Employe
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 20, unique: true)]
private ?string $matricule = null;
#[ORM\Column(length: 100)]
private ?string $nom = null;
#[ORM\Column(length: 100)]
private ?string $prenom = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $email = null;
#[ORM\Column(length: 20)]
private ?string $telephone = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $adresse = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateNaissance = null;
#[ORM\Column(length: 50)]
private ?string $lieuNaissance = null;
#[ORM\Column(length: 10)]
private ?string $sexe = null; // M ou F
#[ORM\Column(length: 50, nullable: true)]
private ?string $situationMatrimoniale = null;
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $nombreEnfants = 0;
#[ORM\Column(length: 100, nullable: true)]
private ?string $numeroSecuriteSociale = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateEmbauche = null;
#[ORM\Column(length: 50)]
private ?string $statut = 'actif'; // actif, suspendu, démission, licencié
#[ORM\ManyToOne(inversedBy: 'employes')]
#[ORM\JoinColumn(nullable: false)]
private ?Departement $departement = null;
#[ORM\ManyToOne(inversedBy: 'employes')]
#[ORM\JoinColumn(nullable: false)]
private ?Poste $poste = null;
#[ORM\OneToOne(inversedBy: 'employe', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: true)]
private ?User $user = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\OneToMany(mappedBy: 'employe', targetEntity: Contrat::class, orphanRemoval: true)]
private Collection $contrats;
#[ORM\OneToMany(mappedBy: 'employe', targetEntity: Conge::class, orphanRemoval: true)]
private Collection $conges;
#[ORM\OneToMany(mappedBy: 'employe', targetEntity: Presence::class, orphanRemoval: true)]
private Collection $presences;
#[ORM\OneToMany(mappedBy: 'employe', targetEntity: Paie::class, orphanRemoval: true)]
private Collection $paies;
#[ORM\Column(length: 255, nullable: true)]
private ?string $photo = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
public function __construct()
{
$this->contrats = new ArrayCollection();
$this->conges = new ArrayCollection();
$this->presences = new ArrayCollection();
$this->paies = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getMatricule(): ?string
{
return $this->matricule;
}
public function setMatricule(string $matricule): static
{
$this->matricule = $matricule;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): static
{
$this->prenom = $prenom;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): static
{
$this->telephone = $telephone;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): static
{
$this->adresse = $adresse;
return $this;
}
public function getDateNaissance(): ?\DateTimeInterface
{
return $this->dateNaissance;
}
public function setDateNaissance(\DateTimeInterface $dateNaissance): static
{
$this->dateNaissance = $dateNaissance;
return $this;
}
public function getLieuNaissance(): ?string
{
return $this->lieuNaissance;
}
public function setLieuNaissance(string $lieuNaissance): static
{
$this->lieuNaissance = $lieuNaissance;
return $this;
}
public function getSexe(): ?string
{
return $this->sexe;
}
public function setSexe(string $sexe): static
{
$this->sexe = $sexe;
return $this;
}
public function getSituationMatrimoniale(): ?string
{
return $this->situationMatrimoniale;
}
public function setSituationMatrimoniale(?string $situationMatrimoniale): static
{
$this->situationMatrimoniale = $situationMatrimoniale;
return $this;
}
public function getNombreEnfants(): ?int
{
return $this->nombreEnfants;
}
public function setNombreEnfants(?int $nombreEnfants): static
{
$this->nombreEnfants = $nombreEnfants;
return $this;
}
public function getNumeroSecuriteSociale(): ?string
{
return $this->numeroSecuriteSociale;
}
public function setNumeroSecuriteSociale(?string $numeroSecuriteSociale): static
{
$this->numeroSecuriteSociale = $numeroSecuriteSociale;
return $this;
}
public function getDateEmbauche(): ?\DateTimeInterface
{
return $this->dateEmbauche;
}
public function setDateEmbauche(\DateTimeInterface $dateEmbauche): static
{
$this->dateEmbauche = $dateEmbauche;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
public function getDepartement(): ?Departement
{
return $this->departement;
}
public function setDepartement(?Departement $departement): static
{
$this->departement = $departement;
return $this;
}
public function getPoste(): ?Poste
{
return $this->poste;
}
public function setPoste(?Poste $poste): static
{
$this->poste = $poste;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, Contrat>
*/
public function getContrats(): Collection
{
return $this->contrats;
}
public function addContrat(Contrat $contrat): static
{
if (!$this->contrats->contains($contrat)) {
$this->contrats->add($contrat);
$contrat->setEmploye($this);
}
return $this;
}
public function removeContrat(Contrat $contrat): static
{
if ($this->contrats->removeElement($contrat)) {
if ($contrat->getEmploye() === $this) {
$contrat->setEmploye(null);
}
}
return $this;
}
/**
* @return Collection<int, Conge>
*/
public function getConges(): Collection
{
return $this->conges;
}
public function addConge(Conge $conge): static
{
if (!$this->conges->contains($conge)) {
$this->conges->add($conge);
$conge->setEmploye($this);
}
return $this;
}
public function removeConge(Conge $conge): static
{
if ($this->conges->removeElement($conge)) {
if ($conge->getEmploye() === $this) {
$conge->setEmploye(null);
}
}
return $this;
}
/**
* @return Collection<int, Presence>
*/
public function getPresences(): Collection
{
return $this->presences;
}
public function addPresence(Presence $presence): static
{
if (!$this->presences->contains($presence)) {
$this->presences->add($presence);
$presence->setEmploye($this);
}
return $this;
}
public function removePresence(Presence $presence): static
{
if ($this->presences->removeElement($presence)) {
if ($presence->getEmploye() === $this) {
$presence->setEmploye(null);
}
}
return $this;
}
/**
* @return Collection<int, Paie>
*/
public function getPaies(): Collection
{
return $this->paies;
}
public function addPaie(Paie $paie): static
{
if (!$this->paies->contains($paie)) {
$this->paies->add($paie);
$paie->setEmploye($this);
}
return $this;
}
public function removePaie(Paie $paie): static
{
if ($this->paies->removeElement($paie)) {
if ($paie->getEmploye() === $this) {
$paie->setEmploye(null);
}
}
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): static
{
$this->photo = $photo;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function getNomComplet(): string
{
return $this->prenom . ' ' . $this->nom;
}
public function getAge(): int
{
return $this->dateNaissance ? $this->dateNaissance->diff(new \DateTime())->y : 0;
}
public function getAnciennete(): int
{
return $this->dateEmbauche ? $this->dateEmbauche->diff(new \DateTime())->y : 0;
}
public function getContratActif(): ?Contrat
{
foreach ($this->contrats as $contrat) {
if ($contrat->getStatut() === 'actif') {
return $contrat;
}
}
return null;
}
public function __toString(): string
{
return $this->getNomComplet();
}
}