<?php
namespace App\Entity;
use App\Repository\PresenceRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PresenceRepository::class)]
class Presence
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'presences')]
#[ORM\JoinColumn(nullable: false)]
private ?Employe $employe = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $date = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $heureArrivee = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $heureDepart = null;
#[ORM\Column(length: 50)]
private ?string $statut = 'present'; // present, absent, retard, conge, maladie
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2, nullable: true)]
private ?string $heuresTravaillees = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = 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 getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): static
{
$this->date = $date;
return $this;
}
public function getHeureArrivee(): ?\DateTimeInterface
{
return $this->heureArrivee;
}
public function setHeureArrivee(?\DateTimeInterface $heureArrivee): static
{
$this->heureArrivee = $heureArrivee;
return $this;
}
public function getHeureDepart(): ?\DateTimeInterface
{
return $this->heureDepart;
}
public function setHeureDepart(?\DateTimeInterface $heureDepart): static
{
$this->heureDepart = $heureDepart;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(string $statut): static
{
$this->statut = $statut;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function getHeuresTravaillees(): ?string
{
return $this->heuresTravaillees;
}
public function setHeuresTravaillees(?string $heuresTravaillees): static
{
$this->heuresTravaillees = $heuresTravaillees;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function calculerHeuresTravaillees(): void
{
if ($this->heureArrivee && $this->heureDepart) {
$diff = $this->heureArrivee->diff($this->heureDepart);
$heures = $diff->h + ($diff->i / 60);
$this->heuresTravaillees = number_format($heures, 2);
}
}
public function __toString(): string
{
return ($this->employe ? $this->employe->getNomComplet() : '') . ' - ' . ($this->date ? $this->date->format('d/m/Y') : '');
}
}