<?php
namespace App\Entity\Engagement;
use App\Repository\TypeDepenseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Référentiel hiérarchique des types de dépenses (3 niveaux) :
* - Niveau 1 : Code budget (ex. "DEVEX - HONORAIRES EXTERNES")
* - Niveau 2 : Catégorie de dépense (ex. "ÉTUDES EXTERNES RÉGLEMENTAIRES")
* - Niveau 3 : Ligne de dépense détaillée (ex. "Géomètre")
*
* @ORM\Entity(repositoryClass=TypeDepenseRepository::class)
* @ORM\Table(name="type_depense")
*/
class TypeDepense
{
public const NIVEAU_CODE_BUDGET = 1;
public const NIVEAU_CATEGORIE = 2;
public const NIVEAU_LIGNE = 3;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* Niveau hiérarchique : 1, 2 ou 3.
* @ORM\Column(type="smallint")
*/
private $niveau;
/**
* Libellé affiché (code budget pour N1, catégorie pour N2, ligne pour N3).
* @ORM\Column(type="string", length=255)
*/
private $libelle;
/**
* Code budget (renseigné sur le niveau 1 uniquement).
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $code;
/**
* Nom actuel sur l'ERP (niveau 1 uniquement).
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nomErp;
/**
* Type comptable : CAPEX / DEVEX / OPEX.
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $type;
/**
* Priorité : Critique / Important / Secondaire.
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $priorite;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $commentaire;
/**
* Ligne suivie dans la gestion des engagements (false = "hors suivi des engagements").
* @ORM\Column(type="boolean", options={"default": true})
*/
private $suiviEngagement = true;
/**
* Position d'affichage dans la fratrie.
* @ORM\Column(type="integer", options={"default": 0})
*/
private $position = 0;
/**
* @ORM\ManyToOne(targetEntity="TypeDepense", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="TypeDepense", mappedBy="parent")
* @ORM\OrderBy({"position" = "ASC", "libelle" = "ASC"})
* @var Collection|TypeDepense[]
*/
private $children;
/**
* @ORM\Column(type="string", length=255)
*/
private $classificationDepenseErpi;
/**
* @ORM\OneToMany(targetEntity="TypeDepenseStatutAdministatif",mappedBy="typeDepense", cascade={"persist"})
*/
private $typeDepenseStatutAdministatif;
public function __construct()
{
$this->children = new ArrayCollection();
$this->typeDepenseStatutAdministatif = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNiveau(): ?int
{
return $this->niveau;
}
public function setNiveau(int $niveau): self
{
$this->niveau = $niveau;
return $this;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(string $libelle): self
{
$this->libelle = $libelle;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getNomErp(): ?string
{
return $this->nomErp;
}
public function setNomErp(?string $nomErp): self
{
$this->nomErp = $nomErp;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getPriorite(): ?string
{
return $this->priorite;
}
public function setPriorite(?string $priorite): self
{
$this->priorite = $priorite;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
public function getSuiviEngagement(): bool
{
return $this->suiviEngagement;
}
public function setSuiviEngagement(bool $suiviEngagement): self
{
$this->suiviEngagement = $suiviEngagement;
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|TypeDepense[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
/**
* Chemin complet "N1 / N2 / N3".
*/
public function getCheminComplet(): string
{
$parts = [];
$node = $this;
while ($node !== null) {
array_unshift($parts, $node->getLibelle());
$node = $node->getParent();
}
return implode(' / ', $parts);
}
public function getClassificationDepenseErpi(): ?string
{
return $this->classificationDepenseErpi;
}
public function setClassificationDepenseErpi(string $classificationDepenseErpi): self
{
$this->classificationDepenseErpi = $classificationDepenseErpi;
return $this;
}
/**
* @return Collection|TypeDepenseStatutAdministatif[]
*/
public function getTypeDepenseStatutAdministatif(): Collection
{
return $this->typeDepenseStatutAdministatif;
}
public function addTypeDepenseStatutAdministatif(TypeDepenseStatutAdministatif $typeDepenseStatutAdministatif): self
{
if (!$this->typeDepenseStatutAdministatif->contains($typeDepenseStatutAdministatif)) {
$this->typeDepenseStatutAdministatif[] = $typeDepenseStatutAdministatif;
$typeDepenseStatutAdministatif->setTypeDepense($this);
}
return $this;
}
public function removeTypeDepenseStatutAdministatif(TypeDepenseStatutAdministatif $typeDepenseStatutAdministatif): self
{
if ($this->typeDepenseStatutAdministatif->removeElement($typeDepenseStatutAdministatif)) {
// set the owning side to null (unless already changed)
if ($typeDepenseStatutAdministatif->getTypeDepense() === $this) {
$typeDepenseStatutAdministatif->setTypeDepense(null);
}
}
return $this;
}
}