src/Entity/DepenseCategorie.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\DepenseCategorieRepository")
  8.  */
  9. class DepenseCategorie
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=100)
  19.      */
  20.     private $nom;
  21.     /**
  22.      * @ORM\Column(type="string", length=7, nullable=true)
  23.      * Couleur hexadécimale ex: #6366f1
  24.      */
  25.     private $couleur '#6366f1';
  26.     /**
  27.      * @ORM\Column(type="string", length=50, nullable=true)
  28.      * Classe FontAwesome ex: fa-car, fa-utensils, fa-bolt
  29.      */
  30.     private $icone 'fa-tag';
  31.     /**
  32.      * @ORM\Column(type="text", nullable=true)
  33.      */
  34.     private $description;
  35.     /**
  36.      * @ORM\Column(type="integer", nullable=true)
  37.      * Ordre d'affichage
  38.      */
  39.     private $ordre 0;
  40.     /**
  41.      * @ORM\Column(type="boolean")
  42.      */
  43.     private $actif true;
  44.     /**
  45.      * @ORM\Column(type="datetime", nullable=true)
  46.      */
  47.     private $datecreation;
  48.     /**
  49.      * @ORM\Column(type="datetime", nullable=true)
  50.      */
  51.     private $datesuppression;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity="Depense", mappedBy="categorieid")
  54.      */
  55.     private Collection $depenses;
  56.     public function __construct()
  57.     {
  58.         $this->depenses    = new ArrayCollection();
  59.         $this->datecreation = new \DateTime();
  60.     }
  61.     public function getId(): ?int { return $this->id; }
  62.     public function getNom(): ?string { return $this->nom; }
  63.     public function setNom(string $v): static { $this->nom $v; return $this; }
  64.     public function getCouleur(): ?string { return $this->couleur; }
  65.     public function setCouleur(?string $v): static { $this->couleur $v; return $this; }
  66.     public function getIcone(): ?string { return $this->icone; }
  67.     public function setIcone(?string $v): static { $this->icone $v; return $this; }
  68.     public function getDescription(): ?string { return $this->description; }
  69.     public function setDescription(?string $v): static { $this->description $v; return $this; }
  70.     public function getOrdre(): ?int { return $this->ordre; }
  71.     public function setOrdre(?int $v): static { $this->ordre $v; return $this; }
  72.     public function isActif(): bool { return $this->actif; }
  73.     public function setActif(bool $v): static { $this->actif $v; return $this; }
  74.     public function getDatecreation(): ?\DateTimeInterface { return $this->datecreation; }
  75.     public function setDatecreation(?\DateTimeInterface $v): static { $this->datecreation $v; return $this; }
  76.     public function getDatesuppression(): ?\DateTimeInterface { return $this->datesuppression; }
  77.     public function setDatesuppression(?\DateTimeInterface $v): static { $this->datesuppression $v; return $this; }
  78.     public function getDepenses(): Collection { return $this->depenses; }
  79.     /**
  80.      * Retourne la couleur de fond légère (pour les badges)
  81.      * Ex: #6366f1 → rgba(99,102,241,0.12)
  82.      */
  83.     public function getCouleurBg(): string
  84.     {
  85.         $hex ltrim($this->couleur ?? '#6366f1''#');
  86.         $r   hexdec(substr($hex02));
  87.         $g   hexdec(substr($hex22));
  88.         $b   hexdec(substr($hex42));
  89.         return "rgba($r,$g,$b,0.12)";
  90.     }
  91.     /**
  92.      * Snapshot scalaire pour le journal d'actions (audit log).
  93.      */
  94.     public function toArray(): array
  95.     {
  96.         return [
  97.             'id'              => $this->id,
  98.             'nom'             => $this->nom,
  99.             'couleur'         => $this->couleur,
  100.             'icone'           => $this->icone,
  101.             'description'     => $this->description,
  102.             'ordre'           => $this->ordre,
  103.             'actif'           => $this->actif,
  104.             'datecreation'    => $this->datecreation?->format(\DateTimeInterface::ATOM),
  105.             'datesuppression' => $this->datesuppression?->format(\DateTimeInterface::ATOM),
  106.         ];
  107.     }
  108. }