<?php
namespace App\Entity\Gestiform\Formations\Devis;
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\Dossier\Dossier;
use App\Entity\Gestiform\Formations\Entreprise\Contact;
use App\Entity\Gestiform\Formations\Entreprise\Entreprise;
use App\Entity\Gestiform\Formations\Financement\Financement;
use App\Entity\Gestiform\Users\Employe;
use App\Repository\Gestiform\Formations\Devis\DevisRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass=DevisRepository::class)
*/
class Devis extends AbstractEntity
{
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $start = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $end = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $state = null;
/**
* @ORM\ManyToOne(targetEntity=Employe::class)
* @ORM\JoinColumn(nullable=true)
* @Serializer\Ignore()
*/
private ?Employe $referentCommercial = null;
/**
* @ORM\ManyToOne(targetEntity=Contact::class)
* @ORM\JoinColumn(nullable=true)
* @Serializer\Ignore()
*/
private ?Contact $contactEntreprise = null;
/**
* @ORM\ManyToOne(targetEntity=Societe::class)
* @ORM\JoinColumn(nullable=true)
*/
private ?Societe $societeSource = null;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private ?string $code = null;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private ?string $repas = null;
/**
* @ORM\OneToOne(targetEntity=Upload::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Upload $signatureFile = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $signature = null;
/**
* @ORM\ManyToOne(targetEntity=Dossier::class, inversedBy="deviss",cascade={"persist"})
* @Serializer\Ignore()
*/
private ?Dossier $dossier = null;
/**
* @ORM\ManyToMany(targetEntity=Dossier::class, mappedBy="devisEntreprises")
*/
private Collection $dossiers;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $calendrierPerso = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $devisApprenant = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $valide = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $devisEntreprise = null;
/**
* @ORM\ManyToOne(targetEntity=Entreprise::class, inversedBy="deviss")
*/
private ?Entreprise $entreprise = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $sourceAppli = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $sourceFront = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $devisInter = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $devisIntra = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $nbApprenants = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $sourceCalendrier = false;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $chezClient = null;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private ?bool $chezOf = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $debutFormation = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTime $finFormation = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $commentaire = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $montantHT = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $remisePourC = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $remise = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $montantPied = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $totalHT = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class)
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $codeTva = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $tauxTva = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $montantTva = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $montantTtc = null;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private ?float $totalValidation = null;
/**
* @ORM\OneToMany(targetEntity=DevisLigne::class, mappedBy="devis", orphanRemoval=true, cascade={"persist"})
* @Serializer\Ignore()
*/
private Collection $devisLignes;
/**
* @ORM\OneToMany(targetEntity=Financement::class, mappedBy="devis",cascade={"persist"})
*/
private Collection $financements;
public function __construct()
{
$this->dossiers = new ArrayCollection();
$this->devisLignes = new ArrayCollection();
$this->financements = new ArrayCollection();
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getRepas(): ?string
{
return $this->repas;
}
public function setRepas(?string $repas): self
{
$this->repas = $repas;
return $this;
}
public function getSignature(): ?string
{
return $this->signature;
}
public function setSignature(?string $signature): self
{
$this->signature = $signature;
return $this;
}
public function isCalendrierPerso(): ?bool
{
return $this->calendrierPerso;
}
public function setCalendrierPerso(?bool $calendrierPerso): self
{
$this->calendrierPerso = $calendrierPerso;
return $this;
}
public function isDevisApprenant(): ?bool
{
return $this->devisApprenant;
}
public function setDevisApprenant(?bool $devisApprenant): self
{
$this->devisApprenant = $devisApprenant;
return $this;
}
public function isValide(): ?bool
{
return $this->valide;
}
public function setValide(?bool $valide): self
{
$this->valide = $valide;
return $this;
}
public function isDevisEntreprise(): ?bool
{
return $this->devisEntreprise;
}
public function setDevisEntreprise(?bool $devisEntreprise): self
{
$this->devisEntreprise = $devisEntreprise;
return $this;
}
public function isSourceAppli(): ?bool
{
return $this->sourceAppli;
}
public function setSourceAppli(?bool $sourceAppli): self
{
$this->sourceAppli = $sourceAppli;
return $this;
}
public function isSourceFront(): ?bool
{
return $this->sourceFront;
}
public function setSourceFront(?bool $sourceFront): self
{
$this->sourceFront = $sourceFront;
return $this;
}
public function isDevisInter(): ?bool
{
return $this->devisInter;
}
public function setDevisInter(?bool $devisInter): self
{
$this->devisInter = $devisInter;
return $this;
}
public function isDevisIntra(): ?bool
{
return $this->devisIntra;
}
public function setDevisIntra(?bool $devisIntra): self
{
$this->devisIntra = $devisIntra;
return $this;
}
public function getNbApprenants(): ?int
{
return $this->nbApprenants;
}
public function setNbApprenants(?int $nbApprenants): self
{
$this->nbApprenants = $nbApprenants;
return $this;
}
public function isSourceCalendrier(): ?bool
{
return $this->sourceCalendrier;
}
public function setSourceCalendrier(?bool $sourceCalendrier): self
{
$this->sourceCalendrier = $sourceCalendrier;
return $this;
}
public function isChezClient(): ?bool
{
return $this->chezClient;
}
public function setChezClient(?bool $chezClient): self
{
$this->chezClient = $chezClient;
return $this;
}
public function isChezOf(): ?bool
{
return $this->chezOf;
}
public function setChezOf(?bool $chezOf): self
{
$this->chezOf = $chezOf;
return $this;
}
public function getDebutFormation(): ?\DateTimeInterface
{
return $this->debutFormation;
}
public function setDebutFormation(?\DateTimeInterface $debutFormation): self
{
$this->debutFormation = $debutFormation;
return $this;
}
public function getFinFormation(): ?\DateTimeInterface
{
return $this->finFormation;
}
public function setFinFormation(?\DateTimeInterface $finFormation): self
{
$this->finFormation = $finFormation;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
public function getMontantHT(): ?string
{
return $this->montantHT;
}
public function setMontantHT(string $montantHT): self
{
$this->montantHT = $montantHT;
return $this;
}
public function getRemisePourC(): ?string
{
return $this->remisePourC;
}
public function setRemisePourC(string $remisePourC): self
{
$this->remisePourC = $remisePourC;
return $this;
}
public function getRemise(): ?string
{
return $this->remise;
}
public function setRemise(string $remise): self
{
$this->remise = $remise;
return $this;
}
public function getMontantPied(): ?string
{
return $this->montantPied;
}
public function setMontantPied(string $montantPied): self
{
$this->montantPied = $montantPied;
return $this;
}
public function getTotalHT(): ?string
{
return $this->totalHT;
}
public function setTotalHT(string $totalHT): self
{
$this->totalHT = $totalHT;
return $this;
}
public function getCodeTva(): ?Masterlistelg
{
return $this->codeTva;
}
public function setCodeTva(?Masterlistelg $codeTva): self
{
$this->codeTva = $codeTva;
return $this;
}
public function getTauxTva(): ?string
{
return $this->tauxTva;
}
public function setTauxTva(?string $tauxTva): self
{
$this->tauxTva = $tauxTva;
return $this;
}
public function getMontantTva(): ?string
{
return $this->montantTva;
}
public function setMontantTva(?string $montantTva): self
{
$this->montantTva = $montantTva;
return $this;
}
public function getMontantTtc(): ?string
{
return $this->montantTtc;
}
public function setMontantTtc(?string $montantTtc): self
{
$this->montantTtc = $montantTtc;
return $this;
}
public function getTotalValidation(): ?string
{
return $this->totalValidation;
}
public function setTotalValidation(?string $totalValidation): self
{
$this->totalValidation = $totalValidation;
return $this;
}
public function getState(): ?Masterlistelg
{
return $this->state;
}
public function setState(?Masterlistelg $state): self
{
$this->state = $state;
return $this;
}
public function getReferentCommercial(): ?Employe
{
return $this->referentCommercial;
}
public function setReferentCommercial(?Employe $referentCommercial): self
{
$this->referentCommercial = $referentCommercial;
return $this;
}
public function getContactEntreprise(): ?Contact
{
return $this->contactEntreprise;
}
public function setContactEntreprise(?Contact $contactEntreprise): self
{
$this->contactEntreprise = $contactEntreprise;
return $this;
}
public function getSocieteSource(): ?Societe
{
return $this->societeSource;
}
public function setSocieteSource(?Societe $societeSource): self
{
$this->societeSource = $societeSource;
return $this;
}
public function getSignatureFile(): ?Upload
{
return $this->signatureFile;
}
public function setSignatureFile(?Upload $signatureFile): self
{
$this->signatureFile = $signatureFile;
return $this;
}
public function getDossier(): ?Dossier
{
return $this->dossier;
}
public function setDossier(?Dossier $dossier): self
{
$this->dossier = $dossier;
return $this;
}
/**
* @return Collection<int, Dossier>
*/
public function getDossiers(): Collection
{
return $this->dossiers;
}
public function addDossier(Dossier $dossier): self
{
if (!$this->dossiers->contains($dossier)) {
$this->dossiers->add($dossier);
$dossier->addDevisEntreprise($this);
}
return $this;
}
public function removeDossier(Dossier $dossier): self
{
if ($this->dossiers->removeElement($dossier)) {
$dossier->removeDevisEntreprise($this);
}
return $this;
}
public function getEntreprise(): ?Entreprise
{
return $this->entreprise;
}
public function setEntreprise(?Entreprise $entreprise): self
{
$this->entreprise = $entreprise;
return $this;
}
/**
* @return Collection<int, DevisLigne>
*/
public function getDevisLignes(): Collection
{
return $this->devisLignes;
}
public function addDevisLigne(DevisLigne $devisLigne): self
{
if (!$this->devisLignes->contains($devisLigne)) {
$this->devisLignes->add($devisLigne);
$devisLigne->setDevis($this);
}
return $this;
}
public function removeDevisLigne(DevisLigne $devisLigne): self
{
if ($this->devisLignes->removeElement($devisLigne)) {
// set the owning side to null (unless already changed)
if ($devisLigne->getDevis() === $this) {
$devisLigne->setDevis(null);
}
}
return $this;
}
public function isSessionsExiste(): bool
{
$sessionsExiste = false;
foreach ($this->devisLignes as $devisLigne) {
$sessionsExiste = true;
if (is_null($devisLigne->getSession()))
$sessionsExiste = false;
}
return $sessionsExiste;
}
public function calculerMoyenneCoutUnitaireHT(): float
{
$totalHT = 0;
$totalDuree = 0;
foreach ($this->getDevisLignes() as $ligne) {
$totalHT += $ligne->getMontantHT() ?? 0;
$totalDuree += $ligne->getDuree() ?? 0;
}
return $totalDuree > 0 ? $totalHT / $totalDuree : 0;
}
public function getDetailCoutUnitaireHT(): array
{
$details = [];
foreach ($this->getDevisLignes() as $ligne) {
$libelle = $ligne->getDesignation();
$montantHT = $ligne->getMontantHT() ?? 0;
$duree = $ligne->getDuree() ?? 0;
$moyenneCoutHoraire = $duree > 0 ? $montantHT / $duree : 0;
$details[] = [
'designation' => $libelle,
'moyParHeure' => round($moyenneCoutHoraire, 2)
];
}
return $details;
}
/**
* @return Collection<int, Financement>
*/
public function getFinancements(): Collection
{
return $this->financements;
}
public function addFinancement(Financement $financement): self
{
if (!$this->financements->contains($financement)) {
$this->financements->add($financement);
$financement->setDevis($this);
}
return $this;
}
public function removeFinancement(Financement $financement): self
{
// set the owning side to null (unless already changed)
if ($this->financements->removeElement($financement) && $financement->getDevis() === $this) {
$financement->setDevis(null);
}
return $this;
}
public function getStart(): ?\DateTime
{
return $this->start;
}
public function setStart(?\DateTime $start): self
{
$this->start = $start;
return $this;
}
public function getEnd(): ?\DateTime
{
return $this->end;
}
public function setEnd(?\DateTime $end): self
{
$this->end = $end;
return $this;
}
public function getAllFrais(): float
{
$resultat = 0;
foreach ($this->getDevisLignes() as $ligne) {
if (!$ligne->isChargeHT()) {
$resultat += $ligne->getMontantHT();
}
}
return $resultat;
}
public function getDetailFinancement(): array
{
$resultat = [];
$resultat['nbfinancements'] = 0;
$resultat['montantht'] = 0;
$resultat['montanttva'] = 0;
$resultat['montantttc'] = 0;
foreach ($this->getFinancements() as $ligne) {
$resultat['montantht'] += $ligne->getMontantHt();
$resultat['montanttva'] += $ligne->getMontantTva();
$resultat['montantttc'] += $ligne->getMontantTtc();
++$resultat['nbfinancements'];
}
return $resultat;
}
}