src/Entity/EcritureComptable.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EcritureComptableRepository;
  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(repositoryClassEcritureComptableRepository::class)]
  9. class EcritureComptable
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length50uniquetrue)]
  16.     private ?string $numeroEcriture null;
  17.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  18.     private ?\DateTimeInterface $dateEcriture null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $libelle null;
  21.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  22.     private ?string $notes null;
  23.     #[ORM\Column]
  24.     private ?bool $estValide false;
  25.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  26.     private ?\DateTimeInterface $dateValidation null;
  27.     #[ORM\ManyToOne(inversedBy'ecrituresComptables')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private ?JournalComptable $journal null;
  30.     #[ORM\ManyToOne(inversedBy'ecrituresComptables')]
  31.     #[ORM\JoinColumn(nullablefalse)]
  32.     private ?Exercice $exercice null;
  33.     #[ORM\OneToMany(mappedBy'ecritureComptable'targetEntityLigneEcriture::class, cascade: ['persist''remove'])]
  34.     private Collection $lignes;
  35.     #[ORM\ManyToOne]
  36.     private ?User $utilisateur null;
  37.     #[ORM\ManyToOne]
  38.     private ?User $validePar null;
  39.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  40.     private ?\DateTimeInterface $createdAt null;
  41.     #[ORM\Column(length50nullabletrue)]
  42.     private ?string $pieceReference null// Référence facture, vente, etc.
  43.     #[ORM\Column(length50nullabletrue)]
  44.     private ?string $typeOrigine null// VENTE, ACHAT, PAIEMENT, etc.
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?int $idOrigine null// ID de la vente, facture, etc.
  47.     #[ORM\ManyToOne(inversedBy'ecrituresComptables')]
  48.     private ?Boutique $boutique null;
  49.     public function __construct()
  50.     {
  51.         $this->lignes = new ArrayCollection();
  52.         $this->createdAt = new \DateTime();
  53.         $this->dateEcriture = new \DateTime();
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getNumeroEcriture(): ?string
  60.     {
  61.         return $this->numeroEcriture;
  62.     }
  63.     public function setNumeroEcriture(string $numeroEcriture): static
  64.     {
  65.         $this->numeroEcriture $numeroEcriture;
  66.         return $this;
  67.     }
  68.     public function getDateEcriture(): ?\DateTimeInterface
  69.     {
  70.         return $this->dateEcriture;
  71.     }
  72.     public function setDateEcriture(\DateTimeInterface $dateEcriture): static
  73.     {
  74.         $this->dateEcriture $dateEcriture;
  75.         return $this;
  76.     }
  77.     public function getLibelle(): ?string
  78.     {
  79.         return $this->libelle;
  80.     }
  81.     public function setLibelle(string $libelle): static
  82.     {
  83.         $this->libelle $libelle;
  84.         return $this;
  85.     }
  86.     public function getNotes(): ?string
  87.     {
  88.         return $this->notes;
  89.     }
  90.     public function setNotes(?string $notes): static
  91.     {
  92.         $this->notes $notes;
  93.         return $this;
  94.     }
  95.     public function isEstValide(): ?bool
  96.     {
  97.         return $this->estValide;
  98.     }
  99.     public function setEstValide(bool $estValide): static
  100.     {
  101.         $this->estValide $estValide;
  102.         return $this;
  103.     }
  104.     public function getDateValidation(): ?\DateTimeInterface
  105.     {
  106.         return $this->dateValidation;
  107.     }
  108.     public function setDateValidation(?\DateTimeInterface $dateValidation): static
  109.     {
  110.         $this->dateValidation $dateValidation;
  111.         return $this;
  112.     }
  113.     public function getJournal(): ?JournalComptable
  114.     {
  115.         return $this->journal;
  116.     }
  117.     public function setJournal(?JournalComptable $journal): static
  118.     {
  119.         $this->journal $journal;
  120.         return $this;
  121.     }
  122.     public function getExercice(): ?Exercice
  123.     {
  124.         return $this->exercice;
  125.     }
  126.     public function setExercice(?Exercice $exercice): static
  127.     {
  128.         $this->exercice $exercice;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection<int, LigneEcriture>
  133.      */
  134.     public function getLignes(): Collection
  135.     {
  136.         return $this->lignes;
  137.     }
  138.     public function addLigne(LigneEcriture $ligne): static
  139.     {
  140.         if (!$this->lignes->contains($ligne)) {
  141.             $this->lignes->add($ligne);
  142.             $ligne->setEcritureComptable($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeLigne(LigneEcriture $ligne): static
  147.     {
  148.         if ($this->lignes->removeElement($ligne)) {
  149.             if ($ligne->getEcritureComptable() === $this) {
  150.                 $ligne->setEcritureComptable(null);
  151.             }
  152.         }
  153.         return $this;
  154.     }
  155.     public function getUtilisateur(): ?User
  156.     {
  157.         return $this->utilisateur;
  158.     }
  159.     public function setUtilisateur(?User $utilisateur): static
  160.     {
  161.         $this->utilisateur $utilisateur;
  162.         return $this;
  163.     }
  164.     public function getValidePar(): ?User
  165.     {
  166.         return $this->validePar;
  167.     }
  168.     public function setValidePar(?User $validePar): static
  169.     {
  170.         $this->validePar $validePar;
  171.         return $this;
  172.     }
  173.     public function getCreatedAt(): ?\DateTimeInterface
  174.     {
  175.         return $this->createdAt;
  176.     }
  177.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  178.     {
  179.         $this->createdAt $createdAt;
  180.         return $this;
  181.     }
  182.     public function getPieceReference(): ?string
  183.     {
  184.         return $this->pieceReference;
  185.     }
  186.     public function setPieceReference(?string $pieceReference): static
  187.     {
  188.         $this->pieceReference $pieceReference;
  189.         return $this;
  190.     }
  191.     public function getTypeOrigine(): ?string
  192.     {
  193.         return $this->typeOrigine;
  194.     }
  195.     public function setTypeOrigine(?string $typeOrigine): static
  196.     {
  197.         $this->typeOrigine $typeOrigine;
  198.         return $this;
  199.     }
  200.     public function getIdOrigine(): ?int
  201.     {
  202.         return $this->idOrigine;
  203.     }
  204.     public function setIdOrigine(?int $idOrigine): static
  205.     {
  206.         $this->idOrigine $idOrigine;
  207.         return $this;
  208.     }
  209.     public function getBoutique(): ?Boutique
  210.     {
  211.         return $this->boutique;
  212.     }
  213.     public function setBoutique(?Boutique $boutique): static
  214.     {
  215.         $this->boutique $boutique;
  216.         return $this;
  217.     }
  218.     /**
  219.      * Calcule le total débit
  220.      */
  221.     public function getTotalDebit(): float
  222.     {
  223.         $total 0;
  224.         foreach ($this->lignes as $ligne) {
  225.             $total += $ligne->getDebit();
  226.         }
  227.         return $total;
  228.     }
  229.     /**
  230.      * Calcule le total crédit
  231.      */
  232.     public function getTotalCredit(): float
  233.     {
  234.         $total 0;
  235.         foreach ($this->lignes as $ligne) {
  236.             $total += $ligne->getCredit();
  237.         }
  238.         return $total;
  239.     }
  240.     /**
  241.      * Vérifie si l'écriture est équilibrée (Débit = Crédit)
  242.      */
  243.     public function estEquilibree(): bool
  244.     {
  245.         return abs($this->getTotalDebit() - $this->getTotalCredit()) < 0.01;
  246.     }
  247.     public function __toString(): string
  248.     {
  249.         return $this->numeroEcriture ' - ' $this->libelle;
  250.     }
  251. }