<?php
// src/Entity/DeclarationConducteur.php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(
* name="declaration_conducteur",
* indexes={
* @ORM\Index(name="idx_immat", columns={"immatriculation"}),
* @ORM\Index(name="idx_client", columns={"nom_client"}),
* @ORM\Index(name="idx_periode", columns={"date_debut", "date_fin"}),
* @ORM\Index(name="idx_status", columns={"status"})
* }
* )
*/
class DeclarationConducteur
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\OneToOne(targetEntity=UploadBatch::class, inversedBy="declaration")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?UploadBatch $uploadBatch = null;
// ───── En-tête ─────
/** @ORM\Column(type="string", length=150, nullable=true) */
private ?string $agence = null;
/** @ORM\Column(type="string", length=50, nullable=true) */
private ?string $immatriculation = null;
/** @ORM\Column(type="string", length=100, nullable=true) */
private ?string $numero_licence = null;
/** @ORM\Column(type="string", length=150, nullable=true) */
private ?string $nom_client = null;
/** @ORM\Column(type="date", nullable=true) */
private ?\DateTimeInterface $date_debut = null;
/** @ORM\Column(type="date", nullable=true) */
private ?\DateTimeInterface $date_fin = null;
/** @ORM\Column(type="string", length=20, options={"default":"pending"}) */
private string $status = 'pending';
// ───── Dates automatiques ─────
/**
* @ORM\Column(type="datetime_immutable")
*/
private \DateTimeImmutable $createdAt;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private ?\DateTimeImmutable $processedAt = null;
// ───── Lignes ─────
/**
* @ORM\OneToMany(
* targetEntity=DeclarationLigne::class,
* mappedBy="declaration",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
*/
private Collection $lignes;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->lignes = new ArrayCollection();
}
// ───── Getters & Setters ─────
public function getId(): ?int { return $this->id; }
public function getUploadBatch(): ?UploadBatch { return $this->uploadBatch; }
public function setUploadBatch(?UploadBatch $uploadBatch): self { $this->uploadBatch = $uploadBatch; return $this; }
public function getAgence(): ?string { return $this->agence; }
public function setAgence(?string $agence): self { $this->agence = $agence; return $this; }
public function getImmatriculation(): ?string { return $this->immatriculation; }
public function setImmatriculation(?string $immatriculation): self { $this->immatriculation = $immatriculation; return $this; }
public function getNumeroLicence(): ?string { return $this->numero_licence; }
public function setNumeroLicence(?string $numero_licence): self { $this->numero_licence = $numero_licence; return $this; }
public function getNomClient(): ?string { return $this->nom_client; }
public function setNomClient(?string $nom_client): self { $this->nom_client = $nom_client; return $this; }
public function getDateDebut(): ?\DateTimeInterface { return $this->date_debut; }
public function setDateDebut(?\DateTimeInterface $date_debut): self { $this->date_debut = $date_debut; return $this; }
public function getDateFin(): ?\DateTimeInterface { return $this->date_fin; }
public function setDateFin(?\DateTimeInterface $date_fin): self { $this->date_fin = $date_fin; return $this; }
public function getStatus(): string { return $this->status; }
public function setStatus(string $status): self { $this->status = $status; return $this; }
public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
// PAS DE setCreatedAt() → c’est immuable, fixé dans le constructeur
public function getProcessedAt(): ?\DateTimeImmutable { return $this->processedAt; }
public function setProcessedAt(?\DateTimeImmutable $processedAt): self { $this->processedAt = $processedAt; return $this; }
public function getLignes(): Collection { return $this->lignes; }
public function addLigne(DeclarationLigne $ligne): self
{
if (!$this->lignes->contains($ligne)) {
$this->lignes[] = $ligne;
$ligne->setDeclaration($this);
}
return $this;
}
public function removeLigne(DeclarationLigne $ligne): self
{
$this->lignes->removeElement($ligne);
return $this;
}
}