<?php
namespace App\Entity;
use App\Repository\UserEnseignantFactureRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=UserEnseignantFactureRepository::class)
*/
class UserEnseignantFacture
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="date")
*/
private $periode_debut;
/**
* @ORM\Column(type="date")
*/
private $periode_fin;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $export;
/**
* @ORM\OneToMany(targetEntity=ActiviteDisponibiliteInscription::class, mappedBy="facture")
*/
private $cours;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="factures")
* @ORM\JoinColumn(nullable=false)
*/
private $enseignant;
/**
* @ORM\Column(type="integer")
*/
private $heures;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $validation;
public function __construct()
{
$this->cours = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPeriodeDebut(): ?\DateTimeInterface
{
return $this->periode_debut;
}
public function setPeriodeDebut(\DateTimeInterface $periode_debut): self
{
$this->periode_debut = $periode_debut;
return $this;
}
public function getPeriodeFin(): ?\DateTimeInterface
{
return $this->periode_fin;
}
public function setPeriodeFin(\DateTimeInterface $periode_fin): self
{
$this->periode_fin = $periode_fin;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getExport(): ?string
{
return $this->export;
}
public function setExport(?string $export): self
{
$this->export = $export;
return $this;
}
/**
* @return Collection<int, ActiviteDisponibiliteInscription>
*/
public function getCours(): Collection
{
return $this->cours;
}
public function addCour(ActiviteDisponibiliteInscription $cour): self
{
if (!$this->cours->contains($cour)) {
$this->cours[] = $cour;
$cour->setFacture($this);
}
return $this;
}
public function removeCour(ActiviteDisponibiliteInscription $cour): self
{
if ($this->cours->removeElement($cour)) {
// set the owning side to null (unless already changed)
if ($cour->getFacture() === $this) {
$cour->setFacture(null);
}
}
return $this;
}
public function getEnseignant(): ?User
{
return $this->enseignant;
}
public function setEnseignant(?User $enseignant): self
{
$this->enseignant = $enseignant;
return $this;
}
public function getHeures(): ?int
{
return $this->heures;
}
public function setHeures(int $heures): self
{
$this->heures = $heures;
return $this;
}
public function makeExport() : string
{
if ($this->isFacture()) {
return 'facture-'.$this->getNumero().'.pdf';
}
if ($this->isReleve()) {
return date('Y-m-d H:i:s');
}
}
public function getDir() : ?string
{
if(!$this->isFacture())return null;
return $this->getEnseignant()->getDir().'/'.'factures';
}
public function getRealPath() : ?string
{
if(!$this->isFacture())return null;
if(!$this->getExport())return null;
return $this->getDir().'/'.$this->getExport();
}
public function getPeriode()
{
return ['debut'=>$this->getPeriodeDebut(), 'fin'=>$this->getPeriodeFin()];
}
public function getNumero()
{
return $this->getId();
}
public function makeHeures(): self
{
$heures = 0;
foreach ($this->cours as $cours) {
$heures += $cours->getDispo()->getHours();
}
$this->heures = $heures;
return $this;
}
public function getTarif(?string $prestation=null): float
{
$montant = 0;
if ($this->getEnseignant()->isIndependant()) {
if(!$prestation or $prestation == "conduite")
$montant += $this->getEnseignant()->getAccountDetail()->getSalaire();
if(!$prestation or $prestation == "location")
$montant += $this->getEnseignant()->getAccountDetail()->getLocation();
}
return $montant;
}
public function makeMontant(?string $prestation=null): float
{
$montant = $this->getTarif($prestation);
$montant*= $this->getHeures();
return $montant;
}
public function makeTVA(?string $prestation=null): float
{
$montant = $this->makeMontant($prestation);
$montant*= 0.2;
return $montant;
}
public function makeTTC(?string $prestation=null): float
{
$montant = $this->makeMontant($prestation);
$montant*= 1.2;
$montant = round($montant, 2);
return $montant;
}
public function getType(): ?string
{
if($this->isFacture())return "facture";
if($this->isReleve())return "releve";
return null;
}
public function isFacture(): bool
{
return $this->getEnseignant()->isIndependant();
}
public function isReleve(): bool
{
return $this->getEnseignant()->isSalarie();
}
public function getValidation(): ?string
{
return $this->validation;
}
public function setValidation(?string $validation): self
{
$this->validation = $validation;
return $this;
}
public function getFileExtensionValidation(): ?string
{
return $this->getValidation() ? pathinfo($this->getValidation(), PATHINFO_EXTENSION) : null;
}
public function getFileNameValidation(): ?string
{
return $this->getValidation() ? pathinfo($this->getValidation(), PATHINFO_FILENAME) : null;
}
public function getDateValidation(): ?DateTime
{
return $this->getValidation() ? new DateTime('@'.filemtime($this->getValidation())) : null;
}
}