src/Domain/Entity/Empresa.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use App\Domain\Interfaces\IntervinienteInterface;
  4. use App\Shared\Domain\ApplicationCore\Interfaces\EntityInterface;
  5. use App\Shared\Domain\Utils;
  6. use App\Shared\Domain\Validator as CRLAssert;
  7. use App\Shared\Infrastructure\Utils\ClassUtils;
  8. use DateTime;
  9. use DateTimeInterface;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\PersistentCollection;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Uid\Uuid;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @UniqueEntity(fields={"entidad", "cif"})
  18.  */
  19. class Empresa extends Interviniente implements EntityInterfaceIntervinienteInterface
  20. {
  21.     /**
  22.      * @var string|null
  23.      * @Assert\Length( max=9, maxMessage="max_length {{ limit }}")
  24.      * @CRLAssert\ConstraintCIF()
  25.      * @Assert\NotBlank(message="not_blank")
  26.      */
  27.     private ?string $cif;
  28.     /**
  29.      * @var Collection|ArrayCollection
  30.      * @Assert\Valid()
  31.      */
  32.     private Collection $centrosTrabajo;
  33.     /**
  34.      * @var string|null
  35.      * @Assert\NotBlank(message="not_blank")
  36.      */
  37.     private ?string $razonSocial;
  38.     /**
  39.      * @var int|null
  40.      * @Assert\NotBlank(message="not_blank")
  41.      */
  42.     private ?int $hombres;
  43.     /**
  44.      * @var int|null
  45.      * @Assert\NotBlank(message="not_blank")
  46.      */
  47.     private ?int $mujeres;
  48.     /**
  49.      * @var int|null
  50.      * @Assert\NotBlank(message="not_blank")
  51.      */
  52.     private ?int $trabajadores;
  53.     /**
  54.      * @var string|null
  55.      */
  56.     private ?string $cp;
  57.     private ?string $changedObservaciones;
  58.     private ?DateTimeInterface $changedAt;
  59.     /**
  60.      * @var Ccaa|null
  61.      */
  62.     private ?Ccaa $ccaa;
  63.     /**
  64.      * @var Cnae|null
  65.      * @Assert\NotBlank(message="not_blank")
  66.      */
  67.     private ?Cnae $cnae;
  68.     /**
  69.      * @var Provincia|null
  70.      */
  71.     private ?Provincia $provincia;
  72.     /**
  73.      * @var Municipio|null
  74.      */
  75.     private ?Municipio $municipio;
  76.     private ?Empresa $padre;
  77.     private ?Empresa $padrehijo;
  78.     private ?Empresa $hijo;
  79.     private ?Empresa $hijopadre;
  80.     private Collection $organosRepresentacion;
  81.     private Collection $personasContacto;
  82.     public function __construct()
  83.     {
  84.         parent::__construct();
  85.         $this->hijo null;
  86.         $this->padre null;
  87.         $this->cif null;
  88.         $this->razonSocial null;
  89.         $this->centrosTrabajo = new ArrayCollection();
  90.         $this->organosRepresentacion = new ArrayCollection();
  91.         $this->personasContacto = new ArrayCollection();
  92.     }
  93.     public function __clone(): void
  94.     {
  95.         $centrosTrabajo $this->getCentrosTrabajo();
  96.         foreach ($centrosTrabajo??[] as $centroTrabajo)
  97.         {
  98.             $centroTrabajoClone = clone ($centroTrabajo);
  99.             $this->addCentrosTrabajo($centroTrabajoClone);
  100.             $this->removeCentrosTrabajo($centroTrabajo);
  101.         }
  102.         $organosRepresentacion $this->getOrganosRepresentacion();
  103.         foreach ($organosRepresentacion??[] as $organoRepresentacion)
  104.         {
  105.             $organoRepresentacionClone = clone ($organoRepresentacion);
  106.             $this->addOrganosRepresentacion($organoRepresentacionClone);
  107.             $this->removeOrganosRepresentacion($organoRepresentacion);
  108.         }
  109.         parent::setCreatedAt(new DateTime('now'));
  110.         parent::setUpdatedAt(new DateTime('now'));
  111.     }
  112.     public function __toString(): string
  113.     {
  114.         return $this->getRazonSocial()??'Empresa Sin Definir';
  115.     }
  116.     public function getCif(): ?string
  117.     {
  118.         return $this->cif;
  119.     }
  120.     public function setCif(?string $cif): static
  121.     {
  122.         $this->cif $cif;
  123.         return $this;
  124.     }
  125.     public function getRazonSocial(): ?string
  126.     {
  127.         return $this->razonSocial;
  128.     }
  129.     public function setRazonSocial(?string $razonSocial): static
  130.     {
  131.         $this->razonSocial $razonSocial;
  132.         return $this;
  133.     }
  134.     public function getHombres(): ?int
  135.     {
  136.         return $this->hombres;
  137.     }
  138.     public function setHombres(?int $hombres): static
  139.     {
  140.         $this->hombres $hombres;
  141.         return $this;
  142.     }
  143.     public function getMujeres(): ?int
  144.     {
  145.         return $this->mujeres;
  146.     }
  147.     public function setMujeres(?int $mujeres): static
  148.     {
  149.         $this->mujeres $mujeres;
  150.         return $this;
  151.     }
  152.     public function getTrabajadores(): ?int
  153.     {
  154.         return $this->trabajadores;
  155.     }
  156.     public function setTrabajadores(?int $trabajadores): static
  157.     {
  158.         $this->trabajadores $trabajadores;
  159.         return $this;
  160.     }
  161.     public function getCp(): ?string
  162.     {
  163.         return $this->cp;
  164.     }
  165.     public function setCp(?string $cp): static
  166.     {
  167.         $this->cp $cp;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return Collection<int, CentroTrabajo>
  172.      */
  173.     public function getCentrosTrabajo(): Collection
  174.     {
  175.         return $this->centrosTrabajo;
  176.     }
  177.     public function setCentrosTrabajo(PersistentCollection $centrosTrabajo): static
  178.     {
  179.         $this->centrosTrabajo $centrosTrabajo;
  180.         return $this;
  181.     }
  182.     public function addCentrosTrabajo(CentroTrabajo $centrosTrabajo): static
  183.     {
  184.         if (!$this->centrosTrabajo->contains($centrosTrabajo)) {
  185.             $this->centrosTrabajo->add($centrosTrabajo);
  186.             $centrosTrabajo->setEmpresa($this);
  187.         }
  188.         return $this;
  189.     }
  190.     public function removeCentrosTrabajo(CentroTrabajo $centrosTrabajo): static
  191.     {
  192.         if ($this->centrosTrabajo->removeElement($centrosTrabajo)) {
  193.             // set the owning side to null (unless already changed)
  194.             if ($centrosTrabajo->getEmpresa() === $this) {
  195.                 $centrosTrabajo->setEmpresa(null);
  196.             }
  197.         }
  198.         return $this;
  199.     }
  200.     public function getCcaa(): ?Ccaa
  201.     {
  202.         return $this->ccaa;
  203.     }
  204.     public function setCcaa(?Ccaa $ccaa): static
  205.     {
  206.         $this->ccaa $ccaa;
  207.         return $this;
  208.     }
  209.     public function getCnae(): ?Cnae
  210.     {
  211.         return $this->cnae;
  212.     }
  213.     public function setCnae(?Cnae $cnae): static
  214.     {
  215.         $this->cnae $cnae;
  216.         return $this;
  217.     }
  218.     public function getProvincia(): ?Provincia
  219.     {
  220.         return $this->provincia;
  221.     }
  222.     public function setProvincia(?Provincia $provincia): static
  223.     {
  224.         $this->provincia $provincia;
  225.         return $this;
  226.     }
  227.     public function getMunicipio(): ?Municipio
  228.     {
  229.         return $this->municipio;
  230.     }
  231.     public function setMunicipio(?Municipio $municipio): static
  232.     {
  233.         $this->municipio $municipio;
  234.         return $this;
  235.     }
  236.     public function getHistorico(): Collection
  237.     {
  238.         $historico = new ArrayCollection();
  239.         $current $this;
  240.         while ($current $current->getPadre())
  241.         {
  242.             $historico->add($current);
  243.         }
  244.         return $historico;
  245.     }
  246.     public function getChangedAt(): ?DateTimeInterface
  247.     {
  248.         return $this->changedAt;
  249.     }
  250.     public function setChangedAt(?DateTimeInterface $changedAt): static
  251.     {
  252.         $this->changedAt $changedAt;
  253.         return $this;
  254.     }
  255.     public function getPadre(): ?self
  256.     {
  257.         return $this->padre;
  258.     }
  259.     public function setPadre(?self $padre): static
  260.     {
  261.         $this->padre $padre;
  262.         return $this;
  263.     }
  264.     public function getHijo(): ?self
  265.     {
  266.         return $this->hijo;
  267.     }
  268.     public function setHijo(?self $hijo): static
  269.     {
  270.         // unset the owning side of the relation if necessary
  271.         if ($hijo === null && $this->hijo !== null) {
  272.             $this->hijo->setPadre(null);
  273.         }
  274.         // set the owning side of the relation if necessary
  275.         if ($hijo !== null && $hijo->getPadre() !== $this) {
  276.             $hijo->setPadre($this);
  277.         }
  278.         $this->hijo $hijo;
  279.         return $this;
  280.     }
  281.     public function getChangedObservaciones(): ?string
  282.     {
  283.         return $this->changedObservaciones;
  284.     }
  285.     public function setChangedObservaciones(?string $changedObservaciones): static
  286.     {
  287.         $this->changedObservaciones $changedObservaciones;
  288.         return $this;
  289.     }
  290.     public function getPadrehijo(): ?self
  291.     {
  292.         return $this->padrehijo;
  293.     }
  294.     public function setPadrehijo(?self $padrehijo): static
  295.     {
  296.         // unset the owning side of the relation if necessary
  297.         if ($padrehijo === null && $this->padrehijo !== null) {
  298.             $this->padrehijo->setPadre(null);
  299.         }
  300.         // set the owning side of the relation if necessary
  301.         if ($padrehijo !== null && $padrehijo->getPadre() !== $this) {
  302.             $padrehijo->setPadre($this);
  303.         }
  304.         $this->padrehijo $padrehijo;
  305.         return $this;
  306.     }
  307.     public function getHijopadre(): ?self
  308.     {
  309.         return $this->hijopadre;
  310.     }
  311.     public function setHijopadre(?self $hijopadre): static
  312.     {
  313.         // unset the owning side of the relation if necessary
  314.         if ($hijopadre === null && $this->hijopadre !== null) {
  315.             $this->hijopadre->setHijo(null);
  316.         }
  317.         // set the owning side of the relation if necessary
  318.         if ($hijopadre !== null && $hijopadre->getHijo() !== $this) {
  319.             $hijopadre->setHijo($this);
  320.         }
  321.         $this->hijopadre $hijopadre;
  322.         return $this;
  323.     }
  324.     /**
  325.      * @return Collection<int, OrganoRepresentacion>
  326.      */
  327.     public function getOrganosRepresentacion(): Collection
  328.     {
  329.         return $this->organosRepresentacion;
  330.     }
  331.     public function addOrganosRepresentacion(OrganoRepresentacion $organosRepresentacion): static
  332.     {
  333.         if (!$this->organosRepresentacion->contains($organosRepresentacion)) {
  334.             $this->organosRepresentacion->add($organosRepresentacion);
  335.             $organosRepresentacion->setEmpresa($this);
  336.         }
  337.         return $this;
  338.     }
  339.     public function removeOrganosRepresentacion(OrganoRepresentacion $organosRepresentacion): static
  340.     {
  341.         if ($this->organosRepresentacion->removeElement($organosRepresentacion)) {
  342.             // set the owning side to null (unless already changed)
  343.             if ($organosRepresentacion->getEmpresa() === $this) {
  344.                 $organosRepresentacion->setEmpresa(null);
  345.             }
  346.         }
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection<int, Persona>
  351.      */
  352.     public function getPersonasContacto(): Collection
  353.     {
  354.         return $this->personasContacto;
  355.     }
  356.     public function addPersonasContacto(Persona $personasContacto): static
  357.     {
  358.         if (!$this->personasContacto->contains($personasContacto)) {
  359.             $this->personasContacto->add($personasContacto);
  360.         }
  361.         return $this;
  362.     }
  363.     public function removePersonasContacto(Persona $personasContacto): static
  364.     {
  365.         $this->personasContacto->removeElement($personasContacto);
  366.         return $this;
  367.     }
  368.     public function getContactos(): Collection
  369.     {
  370.         return $this->getPersonasContacto();
  371.     }
  372. }//class