<?php
namespace App\Entity\Gestiform\Formations\Entreprise;
use App\Entity\AbstractEntity;
use App\Entity\Common\Upload;
use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
use App\Entity\Gestiform\Admin\Societe;
use App\Entity\Gestiform\Formations\Session\FormateurEvent;
use App\Entity\Gestiform\Formations\Session\Planning\Prestation;
use App\Entity\Gestiform\Users\Formateur;
use App\Repository\Gestiform\Formations\Entreprise\ContratRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ContratRepository::class)
*/
class Contrat extends AbstractEntity
{
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $reference = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $tarif = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $duree = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $tva = false;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTime $start;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTime $end = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
*/
private ?Masterlistelg $statut = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
*/
private ?Masterlistelg $type = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
*/
private ?Masterlistelg $objet = null;
/**
* @ORM\ManyToMany(targetEntity=Formateur::class, inversedBy="contrats",cascade={"persist"})
*/
private Collection $formateurs;
/**
* @ORM\ManyToOne(targetEntity=Societe::class)
*/
private ?Societe $societe = null;
/**
* @ORM\ManyToOne(targetEntity=Entreprise::class, inversedBy="contrats")
*/
private ?Entreprise $entreprise = null;
/**
* @ORM\OneToOne(targetEntity=Upload::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Upload $signatureFile = null;
/**
* @ORM\OneToMany(targetEntity=Prestation::class, mappedBy="contrat",cascade={"persist", "remove"})
*/
private Collection $prestations;
public function __construct()
{
$this->prestations = new ArrayCollection();
$this->formateurs = new ArrayCollection();
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getTarif(): ?string
{
return $this->tarif;
}
public function setTarif(?string $tarif): self
{
$this->tarif = $tarif;
return $this;
}
public function getDuree(): ?string
{
return $this->duree;
}
public function setDuree(?string $duree): self
{
$this->duree = $duree;
return $this;
}
public function isTva(): ?bool
{
return $this->tva;
}
public function setTva(?bool $tva): self
{
$this->tva = $tva;
return $this;
}
public function getStart(): ?\DateTimeInterface
{
return $this->start;
}
public function setStart(\DateTimeInterface $start): self
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTimeInterface
{
return $this->end;
}
public function setEnd(\DateTimeInterface $end): self
{
$this->end = $end;
return $this;
}
public function getStatut(): ?Masterlistelg
{
return $this->statut;
}
public function setStatut(?Masterlistelg $statut): self
{
$this->statut = $statut;
return $this;
}
public function getType(): ?Masterlistelg
{
return $this->type;
}
public function setType(?Masterlistelg $type): self
{
$this->type = $type;
return $this;
}
public function getObjet(): ?Masterlistelg
{
return $this->objet;
}
public function setObjet(?Masterlistelg $objet): self
{
$this->objet = $objet;
return $this;
}
public function getSociete(): ?Societe
{
return $this->societe;
}
public function setSociete(?Societe $societe): self
{
$this->societe = $societe;
return $this;
}
public function getEntreprise(): ?Entreprise
{
return $this->entreprise;
}
public function setEntreprise(?Entreprise $entreprise): self
{
$this->entreprise = $entreprise;
return $this;
}
public function getSignatureFile(): ?Upload
{
return $this->signatureFile;
}
public function setSignatureFile(?Upload $signatureFile): self
{
$this->signatureFile = $signatureFile;
return $this;
}
/**
* @return Collection<int, Formateur>
*/
public function getFormateurs(): Collection
{
return $this->formateurs;
}
public function addFormateur(Formateur $formateur): self
{
if (!$this->formateurs->contains($formateur)) {
$this->formateurs->add($formateur);
}
return $this;
}
public function removeFormateur(Formateur $formateur): self
{
$this->formateurs->removeElement($formateur);
return $this;
}
public function getResponsable()
{
if (!is_null($this->getType()) and
$this->getType()->getCode() == 'SOUS-TRAITANCE') {
return $this->getEntreprise()?->getPersonne();
} elseif (!empty($this->getFormateurs())) {
return $this->getFormateurs()->first();
}
return null;
}
/**
* @return Collection<int, Prestation>
*/
public function getPrestations(): Collection
{
return $this->prestations;
}
public function addPrestation(Prestation $prestation): self
{
if (!$this->prestations->contains($prestation)) {
$this->prestations->add($prestation);
$prestation->setContrat($this);
}
return $this;
}
public function removePrestation(Prestation $prestation): self
{
if ($this->prestations->removeElement($prestation)) {
// set the owning side to null (unless already changed)
if ($prestation->getContrat() === $this) {
$prestation->setContrat(null);
}
}
return $this;
}
}