<?php
namespace App\Entity\Gestiform\Formations\Entreprise;
use App\Entity\Common\Convention;
use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
use App\Entity\Gestiform\Admin\Tiers;
use App\Entity\Gestiform\Formations\Devis\Devis;
use App\Entity\Gestiform\Formations\Dossier\Dossier;
use App\Entity\Gestiform\Formations\Financeur\Financeur;
use App\Entity\Gestiform\Formations\Financement\Financement;
use App\Repository\Gestiform\Formations\Entreprise\EntrepriseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=EntrepriseRepository::class)
*/
class Entreprise extends Tiers
{
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $delegataire = false;
/**
* @ORM\OneToMany(targetEntity=Financement::class, mappedBy="entreprise",cascade={"persist"})
*/
private Collection $financements;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $assuranceChomage = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $rna = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $effectif = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $cart = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $activitePrincipale = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $type = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $typeEmployeur = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $employeurSpecifique = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $naf = null;
/**
* @ORM\ManyToOne(targetEntity=Financeur::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Financeur $financeurEntreprise = null;
/**
* @ORM\ManyToOne(targetEntity=Masterlistelg::class,cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?Masterlistelg $adhesionRegimeChomagePublic = null;
/**
* @ORM\OneToMany(targetEntity=Convention::class, mappedBy="entreprise",cascade={"persist"})
*/
private Collection $conventions;
/**
* @ORM\OneToMany(targetEntity=Devis::class, mappedBy="entreprise",cascade={"all"})
*/
private Collection $deviss;
/**
* @ORM\OneToMany(targetEntity=Dossier::class, mappedBy="entreprise",cascade={"persist"})
*/
private Collection $dossiers;
/**
* @ORM\OneToMany(targetEntity=FormateurEntreprise::class, mappedBy="entreprise",cascade={"persist"})
*/
private Collection $formateurEntreprises;
/**
* @ORM\OneToMany(targetEntity=Contrat::class, mappedBy="entreprise",cascade={"all"})
*/
private Collection $contrats;
/**
* @ORM\Column( type="text", nullable=true)
*/
private ?string $missionProposee = null;
public function __construct()
{
parent::__construct();
$this->financements = new ArrayCollection();
$this->conventions = new ArrayCollection();
$this->contrats = new ArrayCollection();
$this->deviss = new ArrayCollection();
$this->dossiers = new ArrayCollection();
$this->formateurEntreprises = new ArrayCollection();
}
public function getEffectif(): ?string
{
return $this->effectif;
}
public function setEffectif(?string $effectif): self
{
$this->effectif = $effectif;
return $this;
}
public function getRna(): ?string
{
return $this->rna;
}
public function setRna(?string $rna): self
{
$this->rna = $rna;
return $this;
}
public function getType(): ?Masterlistelg
{
return $this->type;
}
public function setType(?Masterlistelg $type): self
{
$this->type = $type;
return $this;
}
public function getNaf(): ?Masterlistelg
{
return $this->naf;
}
public function setNaf(?Masterlistelg $naf): self
{
$this->naf = $naf;
return $this;
}
/**
* @return Collection<int, Convention>
*/
public function getConventions(): Collection
{
return $this->conventions;
}
public function addConvention(Convention $convention): self
{
if (!$this->conventions->contains($convention)) {
$this->conventions->add($convention);
$convention->setEntreprise($this);
}
return $this;
}
public function removeConvention(Convention $convention): self
{
if ($this->conventions->removeElement($convention)) {
// set the owning side to null (unless already changed)
if ($convention->getEntreprise() === $this) {
$convention->setEntreprise(null);
}
}
return $this;
}
/**
* @return Collection<int, Devis>
*/
public function getDeviss(): Collection
{
return $this->deviss;
}
public function addDeviss(Devis $deviss): self
{
if (!$this->deviss->contains($deviss)) {
$this->deviss->add($deviss);
$deviss->setEntreprise($this);
}
return $this;
}
public function removeDeviss(Devis $deviss): self
{
if ($this->deviss->removeElement($deviss)) {
// set the owning side to null (unless already changed)
if ($deviss->getEntreprise() === $this) {
$deviss->setEntreprise(null);
}
}
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->setEntreprise($this);
}
return $this;
}
public function removeDossier(Dossier $dossier): self
{
if ($this->dossiers->removeElement($dossier)) {
// set the owning side to null (unless already changed)
if ($dossier->getEntreprise() === $this) {
$dossier->setEntreprise(null);
}
}
return $this;
}
public function getContactPrincipal()
{
$contacts = $this->getContacts();
foreach ($contacts as $item) {
if ($item->isPrincipal())
return $item;
}
return null;
}
public function getDelegataire(): ?bool
{
return $this->delegataire;
}
public function setDelegataire(?bool $delegataire): self
{
$this->delegataire = $delegataire;
return $this;
}
public function isDelegataire(): ?bool
{
return $this->delegataire;
}
/**
* @return Collection<int, FormateurEntreprise>
*/
public function getFormateurEntreprises(): Collection
{
return $this->formateurEntreprises;
}
public function addFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
{
if (!$this->formateurEntreprises->contains($formateurEntreprise)) {
$this->formateurEntreprises->add($formateurEntreprise);
$formateurEntreprise->setEntreprise($this);
}
return $this;
}
public function removeFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
{
if ($this->formateurEntreprises->removeElement($formateurEntreprise)) {
// set the owning side to null (unless already changed)
if ($formateurEntreprise->getEntreprise() === $this) {
$formateurEntreprise->setEntreprise(null);
}
}
return $this;
}
/**
* @return Collection<int, Contrat>
*/
public function getContrats(): Collection
{
return $this->contrats;
}
public function addContrat(Contrat $contrat): self
{
if (!$this->contrats->contains($contrat)) {
$this->contrats->add($contrat);
$contrat->setEntreprise($this);
}
return $this;
}
public function removeContrat(Contrat $contrat): self
{
// set the owning side to null (unless already changed)
if ($this->contrats->removeElement($contrat) && $contrat->getEntreprise() === $this) {
$contrat->setEntreprise(null);
}
return $this;
}
/**
* @throws \JsonException
*/
public function setMissionProposee($missionProposee): self
{
if (is_array($missionProposee)) {
$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);
} elseif (is_string($missionProposee)) {
json_decode($missionProposee, false, 512, JSON_THROW_ON_ERROR);
if (json_last_error() === JSON_ERROR_NONE) {
$this->missionProposee = $missionProposee;
} else {
throw new \InvalidArgumentException('Invalid JSON string.');
}
} else {
throw new \InvalidArgumentException('Expected an array or a JSON string.');
}
return $this;
}
/**
* @throws \JsonException
*/
public function removeFormateurFromMission(string $missionId, string $formateurId): self
{
$missionsProposees = $this->getMissionProposee() ?? [];
foreach ($missionsProposees as &$mission) {
if ($mission['id'] === $missionId) {
if (isset($mission['formateurs'])) {
$mission['formateurs'] = array_filter($mission['formateurs'],
static function ($formateur) use ($formateurId) {
return $formateur['id'] !== $formateurId;
});
$mission['formateurs'] = array_values($mission['formateurs']);
}
}
}
$this->missionProposee = json_encode($missionsProposees, JSON_THROW_ON_ERROR);
return $this;
}
/**
* @throws \JsonException
*/
public function getMissionProposee()
{
if ($this->missionProposee === null || $this->missionProposee === "") {
return [];
}
return json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR);
}
/**
* @throws \JsonException
*/
public function addFormateurMissionProposee(string $id, string $idFormateur, string $nomFormateur): self
{
$missionProposee = $this->getMissionProposee() ?? [];
$modified = false;
foreach ($missionProposee as &$item) {
if ($item['id'] === $id) {
$item['formateurs'] = $item['formateurs'] ?? [];
// Check if formateur already exists
$formateurExists = false;
foreach ($item['formateurs'] as $formateur) {
if ($formateur['id'] === $idFormateur) {
$formateurExists = true;
break;
}
}
if (!$formateurExists) {
$item['formateurs'][] = [
'id' => $idFormateur,
'nom' => $nomFormateur
];
$item['state'] = true;
$modified = true;
}
}
}
if ($modified) {
$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);
}
return $this;
}
/**
* @throws \JsonException
*/
public function addMissionProposee(string $id, string $title, $state = null, $sevent = []): self
{
$missionProposee = $this->getMissionProposee() ?? [];
$exist = false;
foreach ($missionProposee as &$item) {
if ($item['id'] === $id) {
$item['title'] = $title;
$item['state'] = $state;
$item['week'] = $sevent['week'];
$item['start'] = $sevent['start'];
$item['end'] = $sevent['end'];
$exist = true;
}
}
if (!$exist) {
$missionProposee[] = [
'id' => $id,
'title' => $title,
'state' => $state,
'week' => $sevent['week'],
'start' => $sevent['start'],
'end' => $sevent['end']
];
}
$this->missionProposee = json_encode($missionProposee, JSON_THROW_ON_ERROR);
return $this;
}
/**
* @throws \JsonException
*/
public function getMissionProposeeById(string $id)
{
$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];
foreach ($missionProposee as $item) {
if ($item['id'] === $id) {
return $item;
}
}
return null;
}
/**
* @throws \JsonException
*/
public function removeMissionProposee(string $intitule): self
{
$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];
foreach ($missionProposee as $key => $item) {
if ($item['id'] === $intitule) {
unset($missionProposee[$key]);
}
}
$this->missionProposee = json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
return $this;
}
/**
* @throws \JsonException
*/
public function verifMissionProposee(string $id): bool
{
$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];
$exist = false;
foreach ($missionProposee as &$item) {
if ($item['id'] === $id) {
$exist = true;
}
}
return $exist;
}
/**
* @throws \JsonException
*/
public function verifStateMission(string $id): bool
{
$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];
$exist = false;
foreach ($missionProposee as &$item) {
if ($item['id'] === $id && $item['state']) {
$exist = true;
}
}
return $exist;
}
/**
* @throws \JsonException
*/
public function confirmerMission(string $id): self
{
$missionProposee = json_decode($this->missionProposee, true, 512, JSON_THROW_ON_ERROR) ?? [];
foreach ($missionProposee as &$item) {
if ($item['id'] === $id) {
$item['state'] = true;
break;
}
}
$this->missionProposee = json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
return $this;
}
public function getFinanceurEntreprise(): ?Financeur
{
return $this->financeurEntreprise;
}
public function setFinanceurEntreprise(?Financeur $financeurEntreprise): self
{
$this->financeurEntreprise = $financeurEntreprise;
return $this;
}
public function getTypeEmployeur(): ?Masterlistelg
{
return $this->typeEmployeur;
}
public function setTypeEmployeur(?Masterlistelg $typeEmployeur): self
{
$this->typeEmployeur = $typeEmployeur;
return $this;
}
public function getEmployeurSpecifique(): ?Masterlistelg
{
return $this->employeurSpecifique;
}
public function setEmployeurSpecifique(?Masterlistelg $employeurSpecifique): self
{
$this->employeurSpecifique = $employeurSpecifique;
return $this;
}
public function getActivitePrincipale(): ?string
{
return $this->activitePrincipale;
}
public function setActivitePrincipale(?string $activitePrincipale): self
{
$this->activitePrincipale = $activitePrincipale;
return $this;
}
public function getAdhesionRegimeChomagePublic(): ?Masterlistelg
{
return $this->adhesionRegimeChomagePublic;
}
public function setAdhesionRegimeChomagePublic(?Masterlistelg $adhesionRegimeChomagePublic): self
{
$this->adhesionRegimeChomagePublic = $adhesionRegimeChomagePublic;
return $this;
}
public function getCart()
{
if ($this->cart === null) {
return [];
}
return json_decode($this->cart, true);
}
/**
* @throws \JsonException
*/
public function addCart(string $idModule, string $intitule, string $duree): self
{
$exit = false;
$items = $this->getCart();
foreach ($items as $item) {
if ($item['id'] === $idModule) {
$exit = true;
}
}
if (!$exit) {
$items[] = [
'id' => $idModule,
'intitule' => $intitule,
'duree' => $duree,
];
}
$this->cart = json_encode($items, JSON_THROW_ON_ERROR);
return $this;
}
/**
* @throws \JsonException
*/
public function removeCart(int $idModule): self
{
$items = $this->getCart();
if (array_key_exists($idModule, $items) === true) {
unset($items[$idModule]);
}
$this->cart = json_encode($items, JSON_THROW_ON_ERROR);
return $this;
}
public function removeCarts(): self
{
$this->cart = NULL;
return $this;
}
public function getAssuranceChomage(): ?bool
{
return $this->assuranceChomage;
}
public function setAssuranceChomage(?bool $assuranceChomage): Entreprise
{
$this->assuranceChomage = $assuranceChomage;
return $this;
}
}