src/Entity/UserEnseignantFacture.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserEnseignantFactureRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserEnseignantFactureRepository::class)
  11.  */
  12. class UserEnseignantFacture
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="date")
  22.      */
  23.     private $periode_debut;
  24.     /**
  25.      * @ORM\Column(type="date")
  26.      */
  27.     private $periode_fin;
  28.     /**
  29.      * @ORM\Column(type="datetime_immutable")
  30.      * @Gedmo\Timestampable(on="create")
  31.      */
  32.     private $createdAt;
  33.     /**
  34.      * @ORM\Column(type="string", length=255, nullable=true)
  35.      */
  36.     private $export;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity=ActiviteDisponibiliteInscription::class, mappedBy="facture")
  39.      */
  40.     private $cours;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="factures")
  43.      * @ORM\JoinColumn(nullable=false)
  44.      */
  45.     private $enseignant;
  46.     /**
  47.      * @ORM\Column(type="integer")
  48.      */
  49.     private $heures;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $validation;
  54.     public function __construct()
  55.     {
  56.         $this->cours = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getPeriodeDebut(): ?\DateTimeInterface
  63.     {
  64.         return $this->periode_debut;
  65.     }
  66.     public function setPeriodeDebut(\DateTimeInterface $periode_debut): self
  67.     {
  68.         $this->periode_debut $periode_debut;
  69.         return $this;
  70.     }
  71.     public function getPeriodeFin(): ?\DateTimeInterface
  72.     {
  73.         return $this->periode_fin;
  74.     }
  75.     public function setPeriodeFin(\DateTimeInterface $periode_fin): self
  76.     {
  77.         $this->periode_fin $periode_fin;
  78.         return $this;
  79.     }
  80.     public function getCreatedAt(): ?\DateTimeImmutable
  81.     {
  82.         return $this->createdAt;
  83.     }
  84.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  85.     {
  86.         $this->createdAt $createdAt;
  87.         return $this;
  88.     }
  89.     public function getExport(): ?string
  90.     {
  91.         return $this->export;
  92.     }
  93.     public function setExport(?string $export): self
  94.     {
  95.         $this->export $export;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, ActiviteDisponibiliteInscription>
  100.      */
  101.     public function getCours(): Collection
  102.     {
  103.         return $this->cours;
  104.     }
  105.     public function addCour(ActiviteDisponibiliteInscription $cour): self
  106.     {
  107.         if (!$this->cours->contains($cour)) {
  108.             $this->cours[] = $cour;
  109.             $cour->setFacture($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeCour(ActiviteDisponibiliteInscription $cour): self
  114.     {
  115.         if ($this->cours->removeElement($cour)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($cour->getFacture() === $this) {
  118.                 $cour->setFacture(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.     public function getEnseignant(): ?User
  124.     {
  125.         return $this->enseignant;
  126.     }
  127.     public function setEnseignant(?User $enseignant): self
  128.     {
  129.         $this->enseignant $enseignant;
  130.         return $this;
  131.     }
  132.     public function getHeures(): ?int
  133.     {
  134.         return $this->heures;
  135.     }
  136.     public function setHeures(int $heures): self
  137.     {
  138.         $this->heures $heures;
  139.         return $this;
  140.     }
  141.     public function makeExport() : string
  142.     {
  143.         if ($this->isFacture()) {
  144.             return 'facture-'.$this->getNumero().'.pdf';
  145.         }
  146.         if ($this->isReleve()) {
  147.             return date('Y-m-d H:i:s');
  148.         }
  149.     }
  150.     public function getDir() : ?string
  151.     {
  152.         if(!$this->isFacture())return null;
  153.         return $this->getEnseignant()->getDir().'/'.'factures';
  154.     }
  155.     public function getRealPath() : ?string
  156.     {
  157.         if(!$this->isFacture())return null;
  158.         if(!$this->getExport())return null;
  159.         return $this->getDir().'/'.$this->getExport();
  160.     }
  161.     public function getPeriode()
  162.     {
  163.         return ['debut'=>$this->getPeriodeDebut(), 'fin'=>$this->getPeriodeFin()];
  164.     }
  165.     public function getNumero()
  166.     {
  167.         return $this->getId();
  168.     }
  169.     public function makeHeures(): self
  170.     {
  171.         $heures 0;
  172.         foreach ($this->cours as $cours) {
  173.             $heures += $cours->getDispo()->getHours();
  174.         }
  175.         $this->heures $heures;
  176.         return $this;
  177.     }
  178.     public function getTarif(?string $prestation=null): float
  179.     {
  180.         $montant 0;
  181.         if ($this->getEnseignant()->isIndependant()) {
  182.             if(!$prestation or $prestation == "conduite")
  183.             $montant += $this->getEnseignant()->getAccountDetail()->getSalaire();
  184.             if(!$prestation or $prestation == "location")
  185.             $montant += $this->getEnseignant()->getAccountDetail()->getLocation();
  186.         }
  187.         return $montant;
  188.     }
  189.     public function makeMontant(?string $prestation=null): float
  190.     {
  191.         $montant $this->getTarif($prestation);
  192.         $montant*= $this->getHeures();
  193.         return $montant;
  194.     }
  195.     public function makeTVA(?string $prestation=null): float
  196.     {
  197.         $montant $this->makeMontant($prestation);
  198.         $montant*= 0.2;
  199.         return $montant;
  200.     }
  201.     public function makeTTC(?string $prestation=null): float
  202.     {
  203.         $montant $this->makeMontant($prestation);
  204.         $montant*= 1.2;
  205.         $montant round($montant2);
  206.         return $montant;
  207.     }
  208.     public function getType(): ?string
  209.     {
  210.         if($this->isFacture())return "facture";
  211.         if($this->isReleve())return "releve";
  212.         return null;
  213.     }
  214.     public function isFacture(): bool
  215.     {
  216.         return $this->getEnseignant()->isIndependant();
  217.     }
  218.     public function isReleve(): bool
  219.     {
  220.         return $this->getEnseignant()->isSalarie();
  221.     }
  222.     public function getValidation(): ?string
  223.     {
  224.         return $this->validation;
  225.     }
  226.     public function setValidation(?string $validation): self
  227.     {
  228.         $this->validation $validation;
  229.         return $this;
  230.     }
  231.     
  232.     public function getFileExtensionValidation(): ?string
  233.     {
  234.         return $this->getValidation() ? pathinfo($this->getValidation(), PATHINFO_EXTENSION) : null;
  235.     }
  236.     
  237.     public function getFileNameValidation(): ?string
  238.     {
  239.         return $this->getValidation() ? pathinfo($this->getValidation(), PATHINFO_FILENAME) : null;
  240.     }
  241.     
  242.     public function getDateValidation(): ?DateTime
  243.     {
  244.         return $this->getValidation() ? new DateTime('@'.filemtime($this->getValidation())) : null;
  245.     }
  246. }