src/Entity/Gestiform/Formations/Entreprise/Entreprise.php line 20

  1. <?php
  2. namespace App\Entity\Gestiform\Formations\Entreprise;
  3. use App\Entity\Common\Convention;
  4. use App\Entity\Common\Document;
  5. use App\Entity\Common\Upload;
  6. use App\Entity\Gestiform\Admin\MasterListe\Masterlistelg;
  7. use App\Entity\Gestiform\Admin\Tiers;
  8. use App\Entity\Gestiform\Formations\Devis\Devis;
  9. use App\Entity\Gestiform\Formations\Dossier\Dossier;
  10. use App\Entity\Gestiform\Formations\Financement\Financement;
  11. use App\Entity\Gestiform\Formations\Financeur\Financeur;
  12. use App\Repository\Gestiform\Formations\Entreprise\EntrepriseRepository;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use InvalidArgumentException;
  17. use JsonException;
  18. #[ORM\Entity(repositoryClassEntrepriseRepository::class)]
  19. #[ORM\HasLifecycleCallbacks]
  20. class Entreprise extends Tiers
  21. {
  22.     #[ORM\Column(type'boolean'nullabletrue)]
  23.     private ?bool $delegataire false;
  24.     #[ORM\Column(type'boolean'nullabletrue)]
  25.     private ?bool $assuranceChomage false;
  26.     #[ORM\Column(type'string'length255nullabletrue)]
  27.     private ?string $rna null;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private ?string $effectif null;
  30.     #[ORM\Column(type'text'nullabletrue)]
  31.     private ?string $cart null;
  32.     #[ORM\Column(type'string'length255nullabletrue)]
  33.     private ?string $activitePrincipale null;
  34.     #[ORM\Column(type'text'nullabletrue)]
  35.     private ?string $missionProposee null;
  36.     #[ORM\JoinColumn(nullabletrue)]
  37.     #[ORM\ManyToOne(targetEntityMasterlistelg::class, cascade: ['persist'])]
  38.     private ?Masterlistelg $type null;
  39.     #[ORM\JoinColumn(nullabletrue)]
  40.     #[ORM\ManyToOne(targetEntityMasterlistelg::class, cascade: ['persist'])]
  41.     private ?Masterlistelg $typeEmployeur null;
  42.     #[ORM\JoinColumn(nullabletrue)]
  43.     #[ORM\ManyToOne(targetEntityMasterlistelg::class, cascade: ['persist'])]
  44.     private ?Masterlistelg $employeurSpecifique null;
  45.     #[ORM\JoinColumn(nullabletrue)]
  46.     #[ORM\ManyToOne(targetEntityMasterlistelg::class, cascade: ['persist'])]
  47.     private ?Masterlistelg $naf null;
  48.     #[ORM\JoinColumn(nullabletrue)]
  49.     #[ORM\ManyToOne(targetEntityFinanceur::class, cascade: ['persist'])]
  50.     private ?Financeur $financeurEntreprise null;
  51.     #[ORM\JoinColumn(nullabletrue)]
  52.     #[ORM\ManyToOne(targetEntityMasterlistelg::class, cascade: ['persist'])]
  53.     private ?Masterlistelg $adhesionRegimeChomagePublic null;
  54.     #[ORM\OneToMany(targetEntityConvention::class, mappedBy'entreprise'cascade: ['persist''remove'], orphanRemovaltrue)]
  55.     private Collection $conventions;
  56.     #[ORM\OneToMany(targetEntityDevis::class, mappedBy'entreprise'cascade: ['persist''remove'], orphanRemovaltrue)]
  57.     private Collection $deviss;
  58.     #[ORM\OneToMany(targetEntityDossier::class, mappedBy'entreprise')]
  59.     private Collection $dossiers;
  60.     #[ORM\OneToMany(targetEntityFormateurEntreprise::class, mappedBy'entreprise'cascade: ['persist'])]
  61.     private Collection $formateurEntreprises;
  62.     #[ORM\OneToMany(targetEntityContrat::class, mappedBy'entreprise')]
  63.     private Collection $contrats;
  64.     #[ORM\OneToMany(targetEntityDocument::class, mappedBy'entreprise'cascade: ['persist'])]
  65.     private Collection $documents;
  66.     #[ORM\OneToMany(targetEntityFinancement::class, mappedBy'entreprise'cascade: ['persist'])]
  67.     private Collection $financements;
  68.     #[ORM\JoinColumn(nullabletrue)]
  69.     #[ORM\OneToOne(targetEntityUpload::class, cascade: ['persist''remove'])]
  70.     private ?Upload $cachet null;
  71.     public function __construct()
  72.     {
  73.         parent::__construct();
  74.         $this->financements = new ArrayCollection();
  75.         $this->conventions = new ArrayCollection();
  76.         $this->contrats = new ArrayCollection();
  77.         $this->deviss = new ArrayCollection();
  78.         $this->dossiers = new ArrayCollection();
  79.         $this->formateurEntreprises = new ArrayCollection();
  80.         $this->documents = new ArrayCollection();
  81.     }
  82.     public function getEffectif(): ?string
  83.     {
  84.         return $this->effectif;
  85.     }
  86.     public function setEffectif(?string $effectif): self
  87.     {
  88.         $this->effectif $effectif;
  89.         return $this;
  90.     }
  91.     public function getRna(): ?string
  92.     {
  93.         return $this->rna;
  94.     }
  95.     public function setRna(?string $rna): self
  96.     {
  97.         $this->rna $rna;
  98.         return $this;
  99.     }
  100.     public function getType(): ?Masterlistelg
  101.     {
  102.         return $this->type;
  103.     }
  104.     public function setType(?Masterlistelg $type): self
  105.     {
  106.         $this->type $type;
  107.         return $this;
  108.     }
  109.     public function getNaf(): ?Masterlistelg
  110.     {
  111.         return $this->naf;
  112.     }
  113.     public function setNaf(?Masterlistelg $naf): self
  114.     {
  115.         $this->naf $naf;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, Convention>
  120.      */
  121.     public function getConventions(): Collection
  122.     {
  123.         return $this->conventions;
  124.     }
  125.     public function addConvention(Convention $convention): self
  126.     {
  127.         if (!$this->conventions->contains($convention)) {
  128.             $this->conventions->add($convention);
  129.             $convention->setEntreprise($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeConvention(Convention $convention): self
  134.     {
  135.         // set the owning side to null (unless already changed)
  136.         if ($this->conventions->removeElement($convention) && $convention->getEntreprise() === $this) {
  137.             $convention->setEntreprise(null);
  138.         }
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return Collection<int, Devis>
  143.      */
  144.     public function getDeviss(): Collection
  145.     {
  146.         return $this->deviss;
  147.     }
  148.     public function addDeviss(Devis $deviss): self
  149.     {
  150.         if (!$this->deviss->contains($deviss)) {
  151.             $this->deviss->add($deviss);
  152.             $deviss->setEntreprise($this);
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeDeviss(Devis $deviss): self
  157.     {
  158.         // set the owning side to null (unless already changed)
  159.         if ($this->deviss->removeElement($deviss) && $deviss->getEntreprise() === $this) {
  160.             $deviss->setEntreprise(null);
  161.         }
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, Dossier>
  166.      */
  167.     public function getDossiers(): Collection
  168.     {
  169.         return $this->dossiers;
  170.     }
  171.     public function addDossier(Dossier $dossier): self
  172.     {
  173.         if (!$this->dossiers->contains($dossier)) {
  174.             $this->dossiers->add($dossier);
  175.             $dossier->setEntreprise($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeDossier(Dossier $dossier): self
  180.     {
  181.         // set the owning side to null (unless already changed)
  182.         if ($this->dossiers->removeElement($dossier) && $dossier->getEntreprise() === $this) {
  183.             $dossier->setEntreprise(null);
  184.         }
  185.         return $this;
  186.     }
  187.     public function getContactPrincipal()
  188.     {
  189.         $contacts $this->getContacts();
  190.         foreach ($contacts as $item) {
  191.             if ($item->isPrincipal()) {
  192.                 return $item;
  193.             }
  194.         }
  195.         return null;
  196.     }
  197.     public function getDelegataire(): ?bool
  198.     {
  199.         return $this->delegataire;
  200.     }
  201.     public function setDelegataire(?bool $delegataire): self
  202.     {
  203.         $this->delegataire $delegataire;
  204.         return $this;
  205.     }
  206.     public function isDelegataire(): ?bool
  207.     {
  208.         return $this->delegataire;
  209.     }
  210.     /**
  211.      * @return Collection<int, FormateurEntreprise>
  212.      */
  213.     public function getFormateurEntreprises(): Collection
  214.     {
  215.         return $this->formateurEntreprises;
  216.     }
  217.     public function addFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  218.     {
  219.         if (!$this->formateurEntreprises->contains($formateurEntreprise)) {
  220.             $this->formateurEntreprises->add($formateurEntreprise);
  221.             $formateurEntreprise->setEntreprise($this);
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeFormateurEntreprise(FormateurEntreprise $formateurEntreprise): self
  226.     {
  227.         // set the owning side to null (unless already changed)
  228.         if ($this->formateurEntreprises->removeElement($formateurEntreprise) && $formateurEntreprise->getEntreprise() === $this) {
  229.             $formateurEntreprise->setEntreprise(null);
  230.         }
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection<int, Contrat>
  235.      */
  236.     public function getContrats(): Collection
  237.     {
  238.         return $this->contrats;
  239.     }
  240.     public function addContrat(Contrat $contrat): self
  241.     {
  242.         if (!$this->contrats->contains($contrat)) {
  243.             $this->contrats->add($contrat);
  244.             $contrat->setEntreprise($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeContrat(Contrat $contrat): self
  249.     {
  250.         // set the owning side to null (unless already changed)
  251.         if ($this->contrats->removeElement($contrat) && $contrat->getEntreprise() === $this) {
  252.             $contrat->setEntreprise(null);
  253.         }
  254.         return $this;
  255.     }
  256.     /**
  257.      * @throws JsonException
  258.      */
  259.     public function setMissionProposee($missionProposee): self
  260.     {
  261.         if (is_array($missionProposee)) {
  262.             $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  263.         } elseif (is_string($missionProposee)) {
  264.             json_decode($missionProposeefalse512JSON_THROW_ON_ERROR);
  265.             if (json_last_error() === JSON_ERROR_NONE) {
  266.                 $this->missionProposee $missionProposee;
  267.             } else {
  268.                 throw new InvalidArgumentException('Invalid JSON string.');
  269.             }
  270.         } else {
  271.             throw new InvalidArgumentException('Expected an array or a JSON string.');
  272.         }
  273.         return $this;
  274.     }
  275.     /**
  276.      * @throws JsonException
  277.      */
  278.     public function removeFormateurFromMission(string $missionIdstring $formateurId): self
  279.     {
  280.         $missionsProposees $this->getMissionProposee() ?? [];
  281.         foreach ($missionsProposees as &$mission) {
  282.             if ($mission['id'] === $missionId && isset($mission['formateurs'])) {
  283.                 $mission['formateurs'] = array_filter($mission['formateurs'],
  284.                     static function ($formateur) use ($formateurId) {
  285.                         return $formateur['id'] !== $formateurId;
  286.                     });
  287.                 $mission['formateurs'] = array_values($mission['formateurs']);
  288.             }
  289.         }
  290.         $this->missionProposee json_encode($missionsProposeesJSON_THROW_ON_ERROR);
  291.         return $this;
  292.     }
  293.     /**
  294.      * @throws JsonException
  295.      */
  296.     public function getMissionProposee()
  297.     {
  298.         if ($this->missionProposee === null || $this->missionProposee === "") {
  299.             return [];
  300.         }
  301.         return json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR);
  302.     }
  303.     /**
  304.      * @throws JsonException
  305.      */
  306.     public function addFormateurMissionProposee(string $idstring $idFormateurstring $nomFormateur): self
  307.     {
  308.         $missionProposee $this->getMissionProposee() ?? [];
  309.         $modified false;
  310.         foreach ($missionProposee as &$item) {
  311.             if ($item['id'] === $id) {
  312.                 $item['formateurs'] = $item['formateurs'] ?? [];
  313.                 // Check if formateur already exists
  314.                 $formateurExists false;
  315.                 foreach ($item['formateurs'] as $formateur) {
  316.                     if ($formateur['id'] === $idFormateur) {
  317.                         $formateurExists true;
  318.                         break;
  319.                     }
  320.                 }
  321.                 if (!$formateurExists) {
  322.                     $item['formateurs'][] = [
  323.                         'id' => $idFormateur,
  324.                         'nom' => $nomFormateur
  325.                     ];
  326.                     $item['state'] = true;
  327.                     $modified true;
  328.                 }
  329.             }
  330.         }
  331.         if ($modified) {
  332.             $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @throws JsonException
  338.      */
  339.     public function addMissionProposee(string $idstring $title$state null$sevent = []): self
  340.     {
  341.         $missionProposee $this->getMissionProposee() ?? [];
  342.         $exist false;
  343.         foreach ($missionProposee as &$item) {
  344.             if ($item['id'] === $id) {
  345.                 $item['title'] = $title;
  346.                 $item['state'] = $state;
  347.                 $item['week'] = $sevent['week'];
  348.                 $item['start'] = $sevent['start'];
  349.                 $item['end'] = $sevent['end'];
  350.                 $exist true;
  351.             }
  352.         }
  353.         if (!$exist) {
  354.             $missionProposee[] = [
  355.                 'id' => $id,
  356.                 'title' => $title,
  357.                 'state' => $state,
  358.                 'week' => $sevent['week'],
  359.                 'start' => $sevent['start'],
  360.                 'end' => $sevent['end']
  361.             ];
  362.         }
  363.         $this->missionProposee json_encode($missionProposeeJSON_THROW_ON_ERROR);
  364.         return $this;
  365.     }
  366.     /**
  367.      * @throws JsonException
  368.      */
  369.     public function getMissionProposeeById(string $id)
  370.     {
  371.         $missionProposee json_decode($this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  372.         foreach ($missionProposee as $item) {
  373.             if ($item['id'] === $id) {
  374.                 return $item;
  375.             }
  376.         }
  377.         return null;
  378.     }
  379.     /**
  380.      * @throws JsonException
  381.      */
  382.     public function removeMissionProposee(string $id): self
  383.     {
  384.         $missionProposee = [];
  385.         if (!empty($this->missionProposee)) {
  386.             $cleanJson preg_replace('/[\x00-\x1F\x7F]/u'''$this->missionProposee);
  387.             try {
  388.                 $missionProposee json_decode($cleanJsontrue512JSON_THROW_ON_ERROR);
  389.             } catch (\JsonException $e) {
  390.                 dump($e->getMessage());
  391.                 $missionProposee = [];
  392.             }
  393.         }
  394.         foreach ($missionProposee as $key => $item) {
  395.             if (($item['id'] ?? null) === $id) {
  396.                 unset($missionProposee[$key]);
  397.             }
  398.         }
  399.         $this->missionProposee json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
  400.         return $this;
  401.     }
  402.     /**
  403.      * @throws JsonException
  404.      */
  405.     public function verifMissionProposee(string $id): bool
  406.     {
  407.         $json $this->missionProposee ?? '[]';
  408.          $missionProposee json_decode($jsontrue512JSON_THROW_ON_ERROR) ?? [];
  409.         $exist false;
  410.          foreach ($missionProposee as &$item) {
  411.              if ($item['id'] === $id) {
  412.                  $exist true;
  413.              }
  414.          }
  415.          return $exist;
  416.      }
  417.      /**
  418.       * @throws JsonException
  419.       */
  420.     public function verifStateMission(string $id): bool
  421.     {
  422.         $missionProposee json_decode((string) $this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  423.         $exist false;
  424.         foreach ($missionProposee as &$item) {
  425.             if ($item['id'] === $id && $item['state']) {
  426.                 $exist true;
  427.             }
  428.         }
  429.         return $exist;
  430.     }
  431.     /**
  432.      * @throws JsonException
  433.      */
  434.     public function confirmerMission(string $id): self
  435.     {
  436.         $missionProposee json_decode((string) $this->missionProposeetrue512JSON_THROW_ON_ERROR) ?? [];
  437.         foreach ($missionProposee as &$item) {
  438.             if ($item['id'] === $id) {
  439.                 $item['state'] = true;
  440.                 break;
  441.             }
  442.         }
  443.         $this->missionProposee json_encode(array_values($missionProposee), JSON_THROW_ON_ERROR);
  444.         return $this;
  445.     }
  446.     public function getFinanceurEntreprise(): ?Financeur
  447.     {
  448.         return $this->financeurEntreprise;
  449.     }
  450.     public function setFinanceurEntreprise(?Financeur $financeurEntreprise): self
  451.     {
  452.         $this->financeurEntreprise $financeurEntreprise;
  453.         return $this;
  454.     }
  455.     public function getTypeEmployeur(): ?Masterlistelg
  456.     {
  457.         return $this->typeEmployeur;
  458.     }
  459.     public function setTypeEmployeur(?Masterlistelg $typeEmployeur): self
  460.     {
  461.         $this->typeEmployeur $typeEmployeur;
  462.         return $this;
  463.     }
  464.     public function getEmployeurSpecifique(): ?Masterlistelg
  465.     {
  466.         return $this->employeurSpecifique;
  467.     }
  468.     public function setEmployeurSpecifique(?Masterlistelg $employeurSpecifique): self
  469.     {
  470.         $this->employeurSpecifique $employeurSpecifique;
  471.         return $this;
  472.     }
  473.     public function getActivitePrincipale(): ?string
  474.     {
  475.         return $this->activitePrincipale;
  476.     }
  477.     public function setActivitePrincipale(?string $activitePrincipale): self
  478.     {
  479.         $this->activitePrincipale $activitePrincipale;
  480.         return $this;
  481.     }
  482.     public function getAdhesionRegimeChomagePublic(): ?Masterlistelg
  483.     {
  484.         return $this->adhesionRegimeChomagePublic;
  485.     }
  486.     public function setAdhesionRegimeChomagePublic(?Masterlistelg $adhesionRegimeChomagePublic): self
  487.     {
  488.         $this->adhesionRegimeChomagePublic $adhesionRegimeChomagePublic;
  489.         return $this;
  490.     }
  491.     public function getCart()
  492.     {
  493.         if ($this->cart === null) {
  494.             return [];
  495.         }
  496.         return json_decode($this->carttrue);
  497.     }
  498.     /**
  499.      * @throws JsonException
  500.      */
  501.     public function addCart(string $idModulestring $intitulestring $duree): self
  502.     {
  503.         $exit false;
  504.         $items $this->getCart();
  505.         foreach ($items as $item) {
  506.             if ($item['id'] === $idModule) {
  507.                 $exit true;
  508.             }
  509.         }
  510.         if (!$exit) {
  511.             $items[] = [
  512.                 'id' => $idModule,
  513.                 'intitule' => $intitule,
  514.                 'duree' => $duree,
  515.             ];
  516.         }
  517.         $this->cart json_encode($itemsJSON_THROW_ON_ERROR);
  518.         return $this;
  519.     }
  520.     /**
  521.      * @throws JsonException
  522.      */
  523.     public function removeCart(int $idModule): self
  524.     {
  525.         $items $this->getCart();
  526.         if (array_key_exists($idModule$items)) {
  527.             unset($items[$idModule]);
  528.         }
  529.         $this->cart json_encode($itemsJSON_THROW_ON_ERROR);
  530.         return $this;
  531.     }
  532.     public function removeCarts(): self
  533.     {
  534.         $this->cart NULL;
  535.         return $this;
  536.     }
  537.     public function getAssuranceChomage(): ?bool
  538.     {
  539.         return $this->assuranceChomage;
  540.     }
  541.     public function setAssuranceChomage(?bool $assuranceChomage): Entreprise
  542.     {
  543.         $this->assuranceChomage $assuranceChomage;
  544.         return $this;
  545.     }
  546.     public function isAssuranceChomage(): ?bool
  547.     {
  548.         return $this->assuranceChomage;
  549.     }
  550.     public function setCart(?string $cart): self
  551.     {
  552.         $this->cart $cart;
  553.         return $this;
  554.     }
  555.     /**
  556.      * @return Collection<int, Financement>
  557.      */
  558.     public function getFinancements(): Collection
  559.     {
  560.         return $this->financements;
  561.     }
  562.     public function addFinancement(Financement $financement): self
  563.     {
  564.         if (!$this->financements->contains($financement)) {
  565.             $this->financements->add($financement);
  566.             $financement->setEntreprise($this);
  567.         }
  568.         return $this;
  569.     }
  570.     public function removeFinancement(Financement $financement): self
  571.     {
  572.         if ($this->financements->removeElement($financement)) {
  573.             // set the owning side to null (unless already changed)
  574.             if ($financement->getEntreprise() === $this) {
  575.                 $financement->setEntreprise(null);
  576.             }
  577.         }
  578.         return $this;
  579.     }
  580.     /**
  581.      * @return Collection<int, Document>
  582.      */
  583.     public function getDocuments(): Collection
  584.     {
  585.         return $this->documents;
  586.     }
  587.     public function addDocument(Document $document): self
  588.     {
  589.         if (!$this->documents->contains($document)) {
  590.             $this->documents->add($document);
  591.             $document->setEntreprise($this);
  592.         }
  593.         return $this;
  594.     }
  595.     public function removeDocument(Document $document): self
  596.     {
  597.         if ($this->documents->removeElement($document)) {
  598.             // set the owning side to null (unless already changed)
  599.             if ($document->getEntreprise() === $this) {
  600.                 $document->setEntreprise(null);
  601.             }
  602.         }
  603.         return $this;
  604.     }
  605.     public function getCachet(): ?Upload
  606.     {
  607.         return $this->cachet;
  608.     }
  609.     public function setCachet(?Upload $cachet): self
  610.     {
  611.         $this->cachet $cachet;
  612.         return $this;
  613.     }
  614. }