src/Entity/CompteComptable.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompteComptableRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassCompteComptableRepository::class)]
  9. class CompteComptable
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length20uniquetrue)]
  16.     private ?string $numero null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $libelle null;
  19.     #[ORM\Column(length50)]
  20.     private ?string $classe null// 1-9: Classe du compte SYSCOHADA
  21.     #[ORM\Column(length50)]
  22.     private ?string $nature null// ACTIF, PASSIF, CHARGE, PRODUIT
  23.     #[ORM\Column]
  24.     private ?bool $estActif true;
  25.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  26.     private ?string $description null;
  27.     #[ORM\OneToMany(mappedBy'compteDebit'targetEntityLigneEcriture::class)]
  28.     private Collection $lignesDebit;
  29.     #[ORM\OneToMany(mappedBy'compteCredit'targetEntityLigneEcriture::class)]
  30.     private Collection $lignesCredit;
  31.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'sousComptes')]
  32.     #[ORM\JoinColumn(nullabletrue)]
  33.     private ?self $compteParent null;
  34.     #[ORM\OneToMany(mappedBy'compteParent'targetEntityself::class)]
  35.     private Collection $sousComptes;
  36.     #[ORM\Column]
  37.     private ?float $soldeInitial 0;
  38.     public function __construct()
  39.     {
  40.         $this->lignesDebit = new ArrayCollection();
  41.         $this->lignesCredit = new ArrayCollection();
  42.         $this->sousComptes = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getNumero(): ?string
  49.     {
  50.         return $this->numero;
  51.     }
  52.     public function setNumero(string $numero): static
  53.     {
  54.         $this->numero $numero;
  55.         return $this;
  56.     }
  57.     public function getLibelle(): ?string
  58.     {
  59.         return $this->libelle;
  60.     }
  61.     public function setLibelle(string $libelle): static
  62.     {
  63.         $this->libelle $libelle;
  64.         return $this;
  65.     }
  66.     public function getClasse(): ?string
  67.     {
  68.         return $this->classe;
  69.     }
  70.     public function setClasse(string $classe): static
  71.     {
  72.         $this->classe $classe;
  73.         return $this;
  74.     }
  75.     public function getNature(): ?string
  76.     {
  77.         return $this->nature;
  78.     }
  79.     public function setNature(string $nature): static
  80.     {
  81.         $this->nature $nature;
  82.         return $this;
  83.     }
  84.     public function isEstActif(): ?bool
  85.     {
  86.         return $this->estActif;
  87.     }
  88.     public function setEstActif(bool $estActif): static
  89.     {
  90.         $this->estActif $estActif;
  91.         return $this;
  92.     }
  93.     public function getDescription(): ?string
  94.     {
  95.         return $this->description;
  96.     }
  97.     public function setDescription(?string $description): static
  98.     {
  99.         $this->description $description;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection<int, LigneEcriture>
  104.      */
  105.     public function getLignesDebit(): Collection
  106.     {
  107.         return $this->lignesDebit;
  108.     }
  109.     public function addLigneDebit(LigneEcriture $ligneDebit): static
  110.     {
  111.         if (!$this->lignesDebit->contains($ligneDebit)) {
  112.             $this->lignesDebit->add($ligneDebit);
  113.             $ligneDebit->setCompteDebit($this);
  114.         }
  115.         return $this;
  116.     }
  117.     public function removeLigneDebit(LigneEcriture $ligneDebit): static
  118.     {
  119.         if ($this->lignesDebit->removeElement($ligneDebit)) {
  120.             if ($ligneDebit->getCompteDebit() === $this) {
  121.                 $ligneDebit->setCompteDebit(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, LigneEcriture>
  128.      */
  129.     public function getLignesCredit(): Collection
  130.     {
  131.         return $this->lignesCredit;
  132.     }
  133.     public function addLigneCredit(LigneEcriture $ligneCredit): static
  134.     {
  135.         if (!$this->lignesCredit->contains($ligneCredit)) {
  136.             $this->lignesCredit->add($ligneCredit);
  137.             $ligneCredit->setCompteCredit($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeLigneCredit(LigneEcriture $ligneCredit): static
  142.     {
  143.         if ($this->lignesCredit->removeElement($ligneCredit)) {
  144.             if ($ligneCredit->getCompteCredit() === $this) {
  145.                 $ligneCredit->setCompteCredit(null);
  146.             }
  147.         }
  148.         return $this;
  149.     }
  150.     public function getCompteParent(): ?self
  151.     {
  152.         return $this->compteParent;
  153.     }
  154.     public function setCompteParent(?self $compteParent): static
  155.     {
  156.         $this->compteParent $compteParent;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, self>
  161.      */
  162.     public function getSousComptes(): Collection
  163.     {
  164.         return $this->sousComptes;
  165.     }
  166.     public function addSousCompte(self $sousCompte): static
  167.     {
  168.         if (!$this->sousComptes->contains($sousCompte)) {
  169.             $this->sousComptes->add($sousCompte);
  170.             $sousCompte->setCompteParent($this);
  171.         }
  172.         return $this;
  173.     }
  174.     public function removeSousCompte(self $sousCompte): static
  175.     {
  176.         if ($this->sousComptes->removeElement($sousCompte)) {
  177.             if ($sousCompte->getCompteParent() === $this) {
  178.                 $sousCompte->setCompteParent(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183.     public function getSoldeInitial(): ?float
  184.     {
  185.         return $this->soldeInitial;
  186.     }
  187.     public function setSoldeInitial(float $soldeInitial): static
  188.     {
  189.         $this->soldeInitial $soldeInitial;
  190.         return $this;
  191.     }
  192.     /**
  193.      * Calcule le solde du compte (Débit - Crédit)
  194.      */
  195.     public function calculerSolde(): float
  196.     {
  197.         $debit $this->soldeInitial;
  198.         $credit 0;
  199.         foreach ($this->lignesDebit as $ligne) {
  200.             if ($ligne->getEcritureComptable()->isEstValide()) {
  201.                 $debit += $ligne->getMontant();
  202.             }
  203.         }
  204.         foreach ($this->lignesCredit as $ligne) {
  205.             if ($ligne->getEcritureComptable()->isEstValide()) {
  206.                 $credit += $ligne->getMontant();
  207.             }
  208.         }
  209.         return $debit $credit;
  210.     }
  211.     public function __toString(): string
  212.     {
  213.         return $this->numero ' - ' $this->libelle;
  214.     }
  215. }