<?php
namespace App\Entity;
use App\Repository\ContratRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ContratRepository::class)]
class Contrat
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'contrats')]
#[ORM\JoinColumn(nullable: false)]
private ?Employe $employe = null;
#[ORM\Column(length: 50)]
private ?string $typeContrat = null; // CDI, CDD, Stage, Freelance
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateDebut = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateFin = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2)]
private ?string $salaireBase = null;
#[ORM\Column(length: 50)]
private ?string $statut = 'actif'; // actif, terminé, suspendu
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $clausesParticulieres = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $documentContrat = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $createdBy = 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 getTypeContrat(): ?string
{
return $this->typeContrat;
}
public function setTypeContrat(string $typeContrat): static
{
$this->typeContrat = $typeContrat;
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 getSalaireBase(): ?string
{
return $this->salaireBase;
}
public function setSalaireBase(string $salaireBase): static
{
$this->salaireBase = $salaireBase;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
public function getClausesParticulieres(): ?string
{
return $this->clausesParticulieres;
}
public function setClausesParticulieres(?string $clausesParticulieres): static
{
$this->clausesParticulieres = $clausesParticulieres;
return $this;
}
public function getDocumentContrat(): ?string
{
return $this->documentContrat;
}
public function setDocumentContrat(?string $documentContrat): static
{
$this->documentContrat = $documentContrat;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
public function getDuree(): int
{
if (!$this->dateDebut) {
return 0;
}
$dateFin = $this->dateFin ?? new \DateTime();
return $this->dateDebut->diff($dateFin)->days;
}
public function __toString(): string
{
return $this->typeContrat . ' - ' . ($this->employe ? $this->employe->getNomComplet() : '');
}
}