src/Entity/Engagement/TypeDepense.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Engagement;
  3. use App\Repository\TypeDepenseRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * Référentiel hiérarchique des types de dépenses (3 niveaux) :
  9.  *   - Niveau 1 : Code budget (ex. "DEVEX - HONORAIRES EXTERNES")
  10.  *   - Niveau 2 : Catégorie de dépense (ex. "ÉTUDES EXTERNES RÉGLEMENTAIRES")
  11.  *   - Niveau 3 : Ligne de dépense détaillée (ex. "Géomètre")
  12.  *
  13.  * @ORM\Entity(repositoryClass=TypeDepenseRepository::class)
  14.  * @ORM\Table(name="type_depense")
  15.  */
  16. class TypeDepense
  17. {
  18.     public const NIVEAU_CODE_BUDGET = 1;
  19.     public const NIVEAU_CATEGORIE   = 2;
  20.     public const NIVEAU_LIGNE       = 3;
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * Niveau hiérarchique : 1, 2 ou 3.
  29.      * @ORM\Column(type="smallint")
  30.      */
  31.     private $niveau;
  32.     /**
  33.      * Libellé affiché (code budget pour N1, catégorie pour N2, ligne pour N3).
  34.      * @ORM\Column(type="string", length=255)
  35.      */
  36.     private $libelle;
  37.     /**
  38.      * Code budget (renseigné sur le niveau 1 uniquement).
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $code;
  42.     /**
  43.      * Nom actuel sur l'ERP (niveau 1 uniquement).
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $nomErp;
  47.     /**
  48.      * Type comptable : CAPEX / DEVEX / OPEX.
  49.      * @ORM\Column(type="string", length=20, nullable=true)
  50.      */
  51.     private $type;
  52.     /**
  53.      * Priorité : Critique / Important / Secondaire.
  54.      * @ORM\Column(type="string", length=20, nullable=true)
  55.      */
  56.     private $priorite;
  57.     /**
  58.      * @ORM\Column(type="text", nullable=true)
  59.      */
  60.     private $commentaire;
  61.     /**
  62.      * Ligne suivie dans la gestion des engagements (false = "hors suivi des engagements").
  63.      * @ORM\Column(type="boolean", options={"default": true})
  64.      */
  65.     private $suiviEngagement = true;
  66.     /**
  67.      * Position d'affichage dans la fratrie.
  68.      * @ORM\Column(type="integer", options={"default": 0})
  69.      */
  70.     private $position = 0;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity="TypeDepense", inversedBy="children")
  73.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  74.      */
  75.     private $parent;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity="TypeDepense", mappedBy="parent")
  78.      * @ORM\OrderBy({"position" = "ASC", "libelle" = "ASC"})
  79.      * @var Collection|TypeDepense[]
  80.      */
  81.     private $children;
  82.     /**
  83.      * @ORM\Column(type="string", length=255)
  84.      */
  85.     private $classificationDepenseErpi;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity="TypeDepenseStatutAdministatif",mappedBy="typeDepense", cascade={"persist"})
  88.      */
  89.     private $typeDepenseStatutAdministatif;
  90.     public function __construct()
  91.     {
  92.         $this->children = new ArrayCollection();
  93.         $this->typeDepenseStatutAdministatif = new ArrayCollection();
  94.     }
  95.     public function getId(): ?int
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getNiveau(): ?int
  100.     {
  101.         return $this->niveau;
  102.     }
  103.     public function setNiveau(int $niveau): self
  104.     {
  105.         $this->niveau = $niveau;
  106.         return $this;
  107.     }
  108.     public function getLibelle(): ?string
  109.     {
  110.         return $this->libelle;
  111.     }
  112.     public function setLibelle(string $libelle): self
  113.     {
  114.         $this->libelle = $libelle;
  115.         return $this;
  116.     }
  117.     public function getCode(): ?string
  118.     {
  119.         return $this->code;
  120.     }
  121.     public function setCode(?string $code): self
  122.     {
  123.         $this->code = $code;
  124.         return $this;
  125.     }
  126.     public function getNomErp(): ?string
  127.     {
  128.         return $this->nomErp;
  129.     }
  130.     public function setNomErp(?string $nomErp): self
  131.     {
  132.         $this->nomErp = $nomErp;
  133.         return $this;
  134.     }
  135.     public function getType(): ?string
  136.     {
  137.         return $this->type;
  138.     }
  139.     public function setType(?string $type): self
  140.     {
  141.         $this->type = $type;
  142.         return $this;
  143.     }
  144.     public function getPriorite(): ?string
  145.     {
  146.         return $this->priorite;
  147.     }
  148.     public function setPriorite(?string $priorite): self
  149.     {
  150.         $this->priorite = $priorite;
  151.         return $this;
  152.     }
  153.     public function getCommentaire(): ?string
  154.     {
  155.         return $this->commentaire;
  156.     }
  157.     public function setCommentaire(?string $commentaire): self
  158.     {
  159.         $this->commentaire = $commentaire;
  160.         return $this;
  161.     }
  162.     public function getSuiviEngagement(): bool
  163.     {
  164.         return $this->suiviEngagement;
  165.     }
  166.     public function setSuiviEngagement(bool $suiviEngagement): self
  167.     {
  168.         $this->suiviEngagement = $suiviEngagement;
  169.         return $this;
  170.     }
  171.     public function getPosition(): int
  172.     {
  173.         return $this->position;
  174.     }
  175.     public function setPosition(int $position): self
  176.     {
  177.         $this->position = $position;
  178.         return $this;
  179.     }
  180.     public function getParent(): ?self
  181.     {
  182.         return $this->parent;
  183.     }
  184.     public function setParent(?self $parent): self
  185.     {
  186.         $this->parent = $parent;
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return Collection|TypeDepense[]
  191.      */
  192.     public function getChildren(): Collection
  193.     {
  194.         return $this->children;
  195.     }
  196.     public function addChild(self $child): self
  197.     {
  198.         if (!$this->children->contains($child)) {
  199.             $this->children[] = $child;
  200.             $child->setParent($this);
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeChild(self $child): self
  205.     {
  206.         if ($this->children->removeElement($child)) {
  207.             if ($child->getParent() === $this) {
  208.                 $child->setParent(null);
  209.             }
  210.         }
  211.         return $this;
  212.     }
  213.     /**
  214.      * Chemin complet "N1 / N2 / N3".
  215.      */
  216.     public function getCheminComplet(): string
  217.     {
  218.         $parts = [];
  219.         $node  = $this;
  220.         while ($node !== null) {
  221.             array_unshift($parts, $node->getLibelle());
  222.             $node = $node->getParent();
  223.         }
  224.         return implode(' / ', $parts);
  225.     }
  226.     public function getClassificationDepenseErpi(): ?string
  227.     {
  228.         return $this->classificationDepenseErpi;
  229.     }
  230.     public function setClassificationDepenseErpi(string $classificationDepenseErpi): self
  231.     {
  232.         $this->classificationDepenseErpi = $classificationDepenseErpi;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection|TypeDepenseStatutAdministatif[]
  237.      */
  238.     public function getTypeDepenseStatutAdministatif(): Collection
  239.     {
  240.         return $this->typeDepenseStatutAdministatif;
  241.     }
  242.     public function addTypeDepenseStatutAdministatif(TypeDepenseStatutAdministatif $typeDepenseStatutAdministatif): self
  243.     {
  244.         if (!$this->typeDepenseStatutAdministatif->contains($typeDepenseStatutAdministatif)) {
  245.             $this->typeDepenseStatutAdministatif[] = $typeDepenseStatutAdministatif;
  246.             $typeDepenseStatutAdministatif->setTypeDepense($this);
  247.         }
  248.         return $this;
  249.     }
  250.     public function removeTypeDepenseStatutAdministatif(TypeDepenseStatutAdministatif $typeDepenseStatutAdministatif): self
  251.     {
  252.         if ($this->typeDepenseStatutAdministatif->removeElement($typeDepenseStatutAdministatif)) {
  253.             // set the owning side to null (unless already changed)
  254.             if ($typeDepenseStatutAdministatif->getTypeDepense() === $this) {
  255.                 $typeDepenseStatutAdministatif->setTypeDepense(null);
  256.             }
  257.         }
  258.         return $this;
  259.     }
  260. }