<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\DepenseCategorieRepository")
*/
class DepenseCategorie
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $nom;
/**
* @ORM\Column(type="string", length=7, nullable=true)
* Couleur hexadécimale ex: #6366f1
*/
private $couleur = '#6366f1';
/**
* @ORM\Column(type="string", length=50, nullable=true)
* Classe FontAwesome ex: fa-car, fa-utensils, fa-bolt
*/
private $icone = 'fa-tag';
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="integer", nullable=true)
* Ordre d'affichage
*/
private $ordre = 0;
/**
* @ORM\Column(type="boolean")
*/
private $actif = true;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $datecreation;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $datesuppression;
/**
* @ORM\OneToMany(targetEntity="Depense", mappedBy="categorieid")
*/
private Collection $depenses;
public function __construct()
{
$this->depenses = new ArrayCollection();
$this->datecreation = new \DateTime();
}
public function getId(): ?int { return $this->id; }
public function getNom(): ?string { return $this->nom; }
public function setNom(string $v): static { $this->nom = $v; return $this; }
public function getCouleur(): ?string { return $this->couleur; }
public function setCouleur(?string $v): static { $this->couleur = $v; return $this; }
public function getIcone(): ?string { return $this->icone; }
public function setIcone(?string $v): static { $this->icone = $v; return $this; }
public function getDescription(): ?string { return $this->description; }
public function setDescription(?string $v): static { $this->description = $v; return $this; }
public function getOrdre(): ?int { return $this->ordre; }
public function setOrdre(?int $v): static { $this->ordre = $v; return $this; }
public function isActif(): bool { return $this->actif; }
public function setActif(bool $v): static { $this->actif = $v; return $this; }
public function getDatecreation(): ?\DateTimeInterface { return $this->datecreation; }
public function setDatecreation(?\DateTimeInterface $v): static { $this->datecreation = $v; return $this; }
public function getDatesuppression(): ?\DateTimeInterface { return $this->datesuppression; }
public function setDatesuppression(?\DateTimeInterface $v): static { $this->datesuppression = $v; return $this; }
public function getDepenses(): Collection { return $this->depenses; }
/**
* Retourne la couleur de fond légère (pour les badges)
* Ex: #6366f1 → rgba(99,102,241,0.12)
*/
public function getCouleurBg(): string
{
$hex = ltrim($this->couleur ?? '#6366f1', '#');
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
return "rgba($r,$g,$b,0.12)";
}
/**
* Snapshot scalaire pour le journal d'actions (audit log).
*/
public function toArray(): array
{
return [
'id' => $this->id,
'nom' => $this->nom,
'couleur' => $this->couleur,
'icone' => $this->icone,
'description' => $this->description,
'ordre' => $this->ordre,
'actif' => $this->actif,
'datecreation' => $this->datecreation?->format(\DateTimeInterface::ATOM),
'datesuppression' => $this->datesuppression?->format(\DateTimeInterface::ATOM),
];
}
}