<?php
namespace App\Entity;
use App\Repository\CongeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CongeRepository::class)]
class Conge
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'conges')]
#[ORM\JoinColumn(nullable: false)]
private ?Employe $employe = null;
#[ORM\Column(length: 50)]
private ?string $typeConge = null; // Annuel, Maladie, Maternité, Sans solde
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateDebut = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateFin = null;
#[ORM\Column(type: Types::INTEGER)]
private ?int $nombreJours = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $motif = null;
#[ORM\Column(length: 50)]
private ?string $statut = 'en_attente'; // en_attente, approuvé, refusé, annulé
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $commentaireValidation = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateValidation = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $validePar = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $documentJustificatif = null;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmploye(): ?Employe
{
return $this->employe;
}
public function setEmploye(?Employe $employe): static
{
$this->employe = $employe;
return $this;
}
public function getTypeConge(): ?string
{
return $this->typeConge;
}
public function setTypeConge(string $typeConge): static
{
$this->typeConge = $typeConge;
return $this;
}
public function getDateDebut(): ?\DateTimeInterface
{
return $this->dateDebut;
}
public function setDateDebut(\DateTimeInterface $dateDebut): static
{
$this->dateDebut = $dateDebut;
return $this;
}
public function getDateFin(): ?\DateTimeInterface
{
return $this->dateFin;
}
public function setDateFin(\DateTimeInterface $dateFin): static
{
$this->dateFin = $dateFin;
return $this;
}
public function getNombreJours(): ?int
{
return $this->nombreJours;
}
public function setNombreJours(int $nombreJours): static
{
$this->nombreJours = $nombreJours;
return $this;
}
public function getMotif(): ?string
{
return $this->motif;
}
public function setMotif(?string $motif): static
{
$this->motif = $motif;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
public function getCommentaireValidation(): ?string
{
return $this->commentaireValidation;
}
public function setCommentaireValidation(?string $commentaireValidation): static
{
$this->commentaireValidation = $commentaireValidation;
return $this;
}
public function getDateValidation(): ?\DateTimeInterface
{
return $this->dateValidation;
}
public function setDateValidation(?\DateTimeInterface $dateValidation): static
{
$this->dateValidation = $dateValidation;
return $this;
}
public function getValidePar(): ?User
{
return $this->validePar;
}
public function setValidePar(?User $validePar): static
{
$this->validePar = $validePar;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getDocumentJustificatif(): ?string
{
return $this->documentJustificatif;
}
public function setDocumentJustificatif(?string $documentJustificatif): static
{
$this->documentJustificatif = $documentJustificatif;
return $this;
}
public function calculerNombreJours(): void
{
if ($this->dateDebut && $this->dateFin) {
$this->nombreJours = $this->dateDebut->diff($this->dateFin)->days + 1;
}
}
public function __toString(): string
{
return $this->typeConge . ' - ' . ($this->employe ? $this->employe->getNomComplet() : '');
}
}