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