src/Entity/SessionCaisse.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SessionCaisseRepository;
  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(repositoryClassSessionCaisseRepository::class)]
  9. class SessionCaisse
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'sessions')]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private ?Caisse $caisse null;
  18.     #[ORM\ManyToOne(targetEntityUser::class)]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?User $utilisateur null;
  21.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  22.     private ?\DateTimeInterface $dateOuverture null;
  23.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  24.     private ?\DateTimeInterface $dateFermeture null;
  25.     #[ORM\Column(typeTypes::DECIMALprecision15scale2)]
  26.     private ?string $fondsOuverture '0.00';
  27.     #[ORM\Column(typeTypes::DECIMALprecision15scale2nullabletrue)]
  28.     private ?string $fondsFermeture null;
  29.     #[ORM\Column(typeTypes::DECIMALprecision15scale2nullabletrue)]
  30.     private ?string $fondsTheoriqueFermeture null;
  31.     #[ORM\Column(typeTypes::DECIMALprecision15scale2nullabletrue)]
  32.     private ?string $ecart null;
  33.     #[ORM\Column(length50)]
  34.     private ?string $statut 'ouverte'// ouverte, fermee, validee
  35.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  36.     private ?string $noteOuverture null;
  37.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  38.     private ?string $noteFermeture null;
  39.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  40.     private ?string $justificationEcart null;
  41.     #[ORM\OneToMany(mappedBy'session'targetEntityMouvementCaisse::class)]
  42.     private Collection $mouvements;
  43.     #[ORM\Column]
  44.     private ?\DateTimeImmutable $createdAt null;
  45.     #[ORM\ManyToOne(targetEntityUser::class)]
  46.     private ?User $fermePar null;
  47.     #[ORM\ManyToOne(targetEntityUser::class)]
  48.     private ?User $validePar null;
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  50.     private ?\DateTimeInterface $dateValidation null;
  51.     public function __construct()
  52.     {
  53.         $this->mouvements = new ArrayCollection();
  54.         $this->createdAt = new \DateTimeImmutable();
  55.         $this->dateOuverture = new \DateTime();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getCaisse(): ?Caisse
  62.     {
  63.         return $this->caisse;
  64.     }
  65.     public function setCaisse(?Caisse $caisse): static
  66.     {
  67.         $this->caisse $caisse;
  68.         return $this;
  69.     }
  70.     public function getUtilisateur(): ?User
  71.     {
  72.         return $this->utilisateur;
  73.     }
  74.     public function setUtilisateur(?User $utilisateur): static
  75.     {
  76.         $this->utilisateur $utilisateur;
  77.         return $this;
  78.     }
  79.     public function getDateOuverture(): ?\DateTimeInterface
  80.     {
  81.         return $this->dateOuverture;
  82.     }
  83.     public function setDateOuverture(\DateTimeInterface $dateOuverture): static
  84.     {
  85.         $this->dateOuverture $dateOuverture;
  86.         return $this;
  87.     }
  88.     public function getDateFermeture(): ?\DateTimeInterface
  89.     {
  90.         return $this->dateFermeture;
  91.     }
  92.     public function setDateFermeture(?\DateTimeInterface $dateFermeture): static
  93.     {
  94.         $this->dateFermeture $dateFermeture;
  95.         return $this;
  96.     }
  97.     public function getFondsOuverture(): ?string
  98.     {
  99.         return $this->fondsOuverture;
  100.     }
  101.     public function setFondsOuverture(string $fondsOuverture): static
  102.     {
  103.         $this->fondsOuverture $fondsOuverture;
  104.         return $this;
  105.     }
  106.     public function getFondsFermeture(): ?string
  107.     {
  108.         return $this->fondsFermeture;
  109.     }
  110.     public function setFondsFermeture(?string $fondsFermeture): static
  111.     {
  112.         $this->fondsFermeture $fondsFermeture;
  113.         return $this;
  114.     }
  115.     public function getFondsTheoriqueFermeture(): ?string
  116.     {
  117.         return $this->fondsTheoriqueFermeture;
  118.     }
  119.     public function setFondsTheoriqueFermeture(?string $fondsTheoriqueFermeture): static
  120.     {
  121.         $this->fondsTheoriqueFermeture $fondsTheoriqueFermeture;
  122.         return $this;
  123.     }
  124.     public function getEcart(): ?string
  125.     {
  126.         return $this->ecart;
  127.     }
  128.     public function setEcart(?string $ecart): static
  129.     {
  130.         $this->ecart $ecart;
  131.         return $this;
  132.     }
  133.     public function getStatut(): ?string
  134.     {
  135.         return $this->statut;
  136.     }
  137.     public function setStatut(string $statut): static
  138.     {
  139.         $this->statut $statut;
  140.         return $this;
  141.     }
  142.     public function getNoteOuverture(): ?string
  143.     {
  144.         return $this->noteOuverture;
  145.     }
  146.     public function setNoteOuverture(?string $noteOuverture): static
  147.     {
  148.         $this->noteOuverture $noteOuverture;
  149.         return $this;
  150.     }
  151.     public function getNoteFermeture(): ?string
  152.     {
  153.         return $this->noteFermeture;
  154.     }
  155.     public function setNoteFermeture(?string $noteFermeture): static
  156.     {
  157.         $this->noteFermeture $noteFermeture;
  158.         return $this;
  159.     }
  160.     public function getJustificationEcart(): ?string
  161.     {
  162.         return $this->justificationEcart;
  163.     }
  164.     public function setJustificationEcart(?string $justificationEcart): static
  165.     {
  166.         $this->justificationEcart $justificationEcart;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, MouvementCaisse>
  171.      */
  172.     public function getMouvements(): Collection
  173.     {
  174.         return $this->mouvements;
  175.     }
  176.     public function addMouvement(MouvementCaisse $mouvement): static
  177.     {
  178.         if (!$this->mouvements->contains($mouvement)) {
  179.             $this->mouvements->add($mouvement);
  180.             $mouvement->setSession($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeMouvement(MouvementCaisse $mouvement): static
  185.     {
  186.         if ($this->mouvements->removeElement($mouvement)) {
  187.             if ($mouvement->getSession() === $this) {
  188.                 $mouvement->setSession(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     public function getCreatedAt(): ?\DateTimeImmutable
  194.     {
  195.         return $this->createdAt;
  196.     }
  197.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  198.     {
  199.         $this->createdAt $createdAt;
  200.         return $this;
  201.     }
  202.     public function getFermePar(): ?User
  203.     {
  204.         return $this->fermePar;
  205.     }
  206.     public function setFermePar(?User $fermePar): static
  207.     {
  208.         $this->fermePar $fermePar;
  209.         return $this;
  210.     }
  211.     public function getValidePar(): ?User
  212.     {
  213.         return $this->validePar;
  214.     }
  215.     public function setValidePar(?User $validePar): static
  216.     {
  217.         $this->validePar $validePar;
  218.         return $this;
  219.     }
  220.     public function getDateValidation(): ?\DateTimeInterface
  221.     {
  222.         return $this->dateValidation;
  223.     }
  224.     public function setDateValidation(?\DateTimeInterface $dateValidation): static
  225.     {
  226.         $this->dateValidation $dateValidation;
  227.         return $this;
  228.     }
  229.     public function calculerFondsTheorique(): void
  230.     {
  231.         $totalEntrees 0;
  232.         $totalSorties 0;
  233.         foreach ($this->mouvements as $mouvement) {
  234.             if ($mouvement->getTypeMouvement() === 'entree') {
  235.                 $totalEntrees += floatval($mouvement->getMontant());
  236.             } else {
  237.                 $totalSorties += floatval($mouvement->getMontant());
  238.             }
  239.         }
  240.         $fondsTheorique floatval($this->fondsOuverture) + $totalEntrees $totalSorties;
  241.         $this->fondsTheoriqueFermeture number_format($fondsTheorique2'.''');
  242.     }
  243.     public function calculerEcart(): void
  244.     {
  245.         if ($this->fondsFermeture !== null && $this->fondsTheoriqueFermeture !== null) {
  246.             $ecart floatval($this->fondsFermeture) - floatval($this->fondsTheoriqueFermeture);
  247.             $this->ecart number_format($ecart2'.''');
  248.         }
  249.     }
  250.     public function getDuree(): ?int
  251.     {
  252.         if (!$this->dateOuverture) {
  253.             return null;
  254.         }
  255.         
  256.         $dateFin $this->dateFermeture ?? new \DateTime();
  257.         return $this->dateOuverture->diff($dateFin)->h;
  258.     }
  259.     public function getTotalEntrees(): float
  260.     {
  261.         $total 0;
  262.         foreach ($this->mouvements as $mouvement) {
  263.             if ($mouvement->getTypeMouvement() === 'entree') {
  264.                 $total += floatval($mouvement->getMontant());
  265.             }
  266.         }
  267.         return $total;
  268.     }
  269.     public function getTotalSorties(): float
  270.     {
  271.         $total 0;
  272.         foreach ($this->mouvements as $mouvement) {
  273.             if ($mouvement->getTypeMouvement() === 'sortie') {
  274.                 $total += floatval($mouvement->getMontant());
  275.             }
  276.         }
  277.         return $total;
  278.     }
  279.     public function __toString(): string
  280.     {
  281.         return 'Session ' . ($this->dateOuverture $this->dateOuverture->format('d/m/Y H:i') : '');
  282.     }
  283. }