src/Entity/Caisse.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CaisseRepository;
  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(repositoryClassCaisseRepository::class)]
  9. class Caisse
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length100)]
  16.     private ?string $nom null;
  17.     #[ORM\Column(length255nullabletrue)]
  18.     private ?string $description null;
  19.     #[ORM\ManyToOne(inversedBy'caisses')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?Boutique $boutique null;
  22.     #[ORM\Column(typeTypes::DECIMALprecision15scale2)]
  23.     private ?string $fondsDepart '0.00';
  24.     #[ORM\Column(typeTypes::DECIMALprecision15scale2)]
  25.     private ?string $soldeActuel '0.00';
  26.     #[ORM\Column(length50)]
  27.     private ?string $statut 'fermee'// fermee, ouverte
  28.     #[ORM\ManyToOne(targetEntityUser::class)]
  29.     private ?User $responsable null;
  30.     #[ORM\Column]
  31.     private ?bool $estActive true;
  32.     #[ORM\Column]
  33.     private ?\DateTimeImmutable $createdAt null;
  34.     #[ORM\OneToMany(mappedBy'caisse'targetEntitySessionCaisse::class, orphanRemovaltrue)]
  35.     private Collection $sessions;
  36.     #[ORM\OneToMany(mappedBy'caisse'targetEntityMouvementCaisse::class, orphanRemovaltrue)]
  37.     private Collection $mouvements;
  38.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  39.     private ?\DateTimeInterface $derniereOuverture null;
  40.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  41.     private ?\DateTimeInterface $derniereFermeture null;
  42.     public function __construct()
  43.     {
  44.         $this->sessions = new ArrayCollection();
  45.         $this->mouvements = new ArrayCollection();
  46.         $this->createdAt = new \DateTimeImmutable();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getNom(): ?string
  53.     {
  54.         return $this->nom;
  55.     }
  56.     public function setNom(string $nom): static
  57.     {
  58.         $this->nom $nom;
  59.         return $this;
  60.     }
  61.     public function getDescription(): ?string
  62.     {
  63.         return $this->description;
  64.     }
  65.     public function setDescription(?string $description): static
  66.     {
  67.         $this->description $description;
  68.         return $this;
  69.     }
  70.     public function getBoutique(): ?Boutique
  71.     {
  72.         return $this->boutique;
  73.     }
  74.     public function setBoutique(?Boutique $boutique): static
  75.     {
  76.         $this->boutique $boutique;
  77.         return $this;
  78.     }
  79.     public function getFondsDepart(): ?string
  80.     {
  81.         return $this->fondsDepart;
  82.     }
  83.     public function setFondsDepart(string $fondsDepart): static
  84.     {
  85.         $this->fondsDepart $fondsDepart;
  86.         return $this;
  87.     }
  88.     public function getSoldeActuel(): ?string
  89.     {
  90.         return $this->soldeActuel;
  91.     }
  92.     public function setSoldeActuel(string $soldeActuel): static
  93.     {
  94.         $this->soldeActuel $soldeActuel;
  95.         return $this;
  96.     }
  97.     public function getStatut(): ?string
  98.     {
  99.         return $this->statut;
  100.     }
  101.     public function setStatut(string $statut): static
  102.     {
  103.         $this->statut $statut;
  104.         return $this;
  105.     }
  106.     public function getResponsable(): ?User
  107.     {
  108.         return $this->responsable;
  109.     }
  110.     public function setResponsable(?User $responsable): static
  111.     {
  112.         $this->responsable $responsable;
  113.         return $this;
  114.     }
  115.     public function isEstActive(): ?bool
  116.     {
  117.         return $this->estActive;
  118.     }
  119.     public function setEstActive(bool $estActive): static
  120.     {
  121.         $this->estActive $estActive;
  122.         return $this;
  123.     }
  124.     public function getCreatedAt(): ?\DateTimeImmutable
  125.     {
  126.         return $this->createdAt;
  127.     }
  128.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  129.     {
  130.         $this->createdAt $createdAt;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, SessionCaisse>
  135.      */
  136.     public function getSessions(): Collection
  137.     {
  138.         return $this->sessions;
  139.     }
  140.     public function addSession(SessionCaisse $session): static
  141.     {
  142.         if (!$this->sessions->contains($session)) {
  143.             $this->sessions->add($session);
  144.             $session->setCaisse($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeSession(SessionCaisse $session): static
  149.     {
  150.         if ($this->sessions->removeElement($session)) {
  151.             if ($session->getCaisse() === $this) {
  152.                 $session->setCaisse(null);
  153.             }
  154.         }
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, MouvementCaisse>
  159.      */
  160.     public function getMouvements(): Collection
  161.     {
  162.         return $this->mouvements;
  163.     }
  164.     public function addMouvement(MouvementCaisse $mouvement): static
  165.     {
  166.         if (!$this->mouvements->contains($mouvement)) {
  167.             $this->mouvements->add($mouvement);
  168.             $mouvement->setCaisse($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeMouvement(MouvementCaisse $mouvement): static
  173.     {
  174.         if ($this->mouvements->removeElement($mouvement)) {
  175.             if ($mouvement->getCaisse() === $this) {
  176.                 $mouvement->setCaisse(null);
  177.             }
  178.         }
  179.         return $this;
  180.     }
  181.     public function getDerniereOuverture(): ?\DateTimeInterface
  182.     {
  183.         return $this->derniereOuverture;
  184.     }
  185.     public function setDerniereOuverture(?\DateTimeInterface $derniereOuverture): static
  186.     {
  187.         $this->derniereOuverture $derniereOuverture;
  188.         return $this;
  189.     }
  190.     public function getDerniereFermeture(): ?\DateTimeInterface
  191.     {
  192.         return $this->derniereFermeture;
  193.     }
  194.     public function setDerniereFermeture(?\DateTimeInterface $derniereFermeture): static
  195.     {
  196.         $this->derniereFermeture $derniereFermeture;
  197.         return $this;
  198.     }
  199.     public function getSessionOuverte(): ?SessionCaisse
  200.     {
  201.         foreach ($this->sessions as $session) {
  202.             if ($session->getStatut() === 'ouverte') {
  203.                 return $session;
  204.             }
  205.         }
  206.         return null;
  207.     }
  208.     public function isOuverte(): bool
  209.     {
  210.         return $this->statut === 'ouverte' && $this->getSessionOuverte() !== null;
  211.     }
  212.     public function ajouterMontant(float $montant): void
  213.     {
  214.         $soldeActuel floatval($this->soldeActuel);
  215.         $this->soldeActuel number_format($soldeActuel $montant2'.''');
  216.     }
  217.     public function retirerMontant(float $montant): void
  218.     {
  219.         $soldeActuel floatval($this->soldeActuel);
  220.         $this->soldeActuel number_format($soldeActuel $montant2'.''');
  221.     }
  222.     public function __toString(): string
  223.     {
  224.         return $this->nom ?? '';
  225.     }
  226. }