src/Domain/Entity/Expediente.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use App\Domain\Enum\TipoProcedimientoTramiteEnum;
  4. use App\Shared\Domain\ApplicationCore\Interfaces\EntityInterface;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Uid\Uuid;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. class Expediente implements EntityInterface
  13. {
  14.     private ?Uuid $id null;
  15.     private ?string $key null;
  16.     private ?string $nombre null;
  17.     /**
  18.      * @var string|null
  19.      * @Assert\NotBlank(message="not_blank", groups={"explicit_check"})
  20.      *
  21.      * FIX-260518-101: el constraint queda en el grupo "explicit_check"
  22.      * en lugar de Default, para que el flujo Sonata create no lo dispare
  23.      * antes del flush. postPersist (GenerateNumExpCommandHandler) genera
  24.      * el numero despues del persist. Quien necesite exigir el numero
  25.      * (API, console, batch) debe validar pasando explicitamente
  26.      * ['explicit_check'] al ValidatorInterface.
  27.      */
  28.     private ?string $numeroExpediente null;
  29.     private ?string $descripcion null;
  30.     private ?DateTimeInterface $createdAt null;
  31.     private ?DateTimeInterface $updatedAt null;
  32.     private ?DateTimeInterface $deletedAt null;
  33.     private ?EstadoExpediente $estadoExpediente null;
  34.     private ?ExpedienteCabecera $cabecera null;
  35.     /**
  36.      * @var MetadataExpediente|null
  37.      * @Assert\NotBlank(message="not_blank")
  38.      */
  39.     private ?MetadataExpediente $metadata null;
  40.     private ?SonataUserUser $creador null;
  41.     private ?Entidad $entidad null;
  42.     private ?DocumentacionRegistro $solicitud null;
  43.     private Collection $tramites;
  44.     private Collection $minutas;
  45.     private Collection $responsables;
  46.     private Collection $registros;
  47.     private Collection $representacions;
  48.     public function __construct()
  49.     {
  50.         $this->tramites = new ArrayCollection();
  51.         $this->minutas = new ArrayCollection();
  52.         $this->responsables = new ArrayCollection();
  53.         $this->registros = new ArrayCollection();
  54.         $this->representacions = new ArrayCollection();
  55.     }
  56.     public function __toString(): string
  57.     {
  58.         return $this->getNumeroExpediente()??'X/0000/2024';
  59.     }
  60.     public function getKey(): ?string
  61.     {
  62.         return $this->key;
  63.     }
  64.     public function setKey(?string $key): static
  65.     {
  66.         $this->key $key;
  67.         return $this;
  68.     }
  69.     public function getNumeroExpediente(): ?string
  70.     {
  71.         return $this->numeroExpediente;
  72.     }
  73.     public function setNumeroExpediente(?string $numeroExpediente): static
  74.     {
  75.         $this->numeroExpediente $numeroExpediente;
  76.         return $this;
  77.     }
  78.     public function getNombre(): ?string
  79.     {
  80.         return $this->nombre;
  81.     }
  82.     public function setNombre(?string $nombre): static
  83.     {
  84.         $this->nombre $nombre;
  85.         return $this;
  86.     }
  87.     public function getDescripcion(): ?string
  88.     {
  89.         return $this->descripcion;
  90.     }
  91.     public function setDescripcion(?string $descripcion): static
  92.     {
  93.         $this->descripcion $descripcion;
  94.         return $this;
  95.     }
  96.     public function getCreatedAt(): ?\DateTimeInterface
  97.     {
  98.         return $this->createdAt;
  99.     }
  100.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  101.     {
  102.         $this->createdAt $createdAt;
  103.         return $this;
  104.     }
  105.     public function getUpdatedAt(): ?\DateTimeInterface
  106.     {
  107.         return $this->updatedAt;
  108.     }
  109.     public function setUpdatedAt(\DateTimeInterface $updatedAt): static
  110.     {
  111.         $this->updatedAt $updatedAt;
  112.         return $this;
  113.     }
  114.     public function getDeletedAt(): ?\DateTimeInterface
  115.     {
  116.         return $this->deletedAt;
  117.     }
  118.     public function setDeletedAt(?\DateTimeInterface $deletedAt): static
  119.     {
  120.         $this->deletedAt $deletedAt;
  121.         return $this;
  122.     }
  123.     public function getId(): ?Uuid
  124.     {
  125.         return $this->id;
  126.     }
  127.     /**
  128.      * @return Collection<int, Tramite>
  129.      */
  130.     public function getTramites(): Collection
  131.     {
  132.         return $this->tramites;
  133.     }
  134.     public function addTramite(Tramite $tramite): static
  135.     {
  136.         if (!$this->tramites->contains($tramite)) {
  137.             $this->tramites->add($tramite);
  138.             $tramite->setExpediente($this);
  139.         }
  140.         return $this;
  141.     }
  142.     public function removeTramite(Tramite $tramite): static
  143.     {
  144.         if ($this->tramites->removeElement($tramite)) {
  145.             // set the owning side to null (unless already changed)
  146.             if ($tramite->getExpediente() === $this) {
  147.                 $tramite->setExpediente(null);
  148.             }
  149.         }
  150.         return $this;
  151.     }
  152.     /**
  153.      * @return Collection<int, Minuta>
  154.      */
  155.     public function getMinutas(): Collection
  156.     {
  157.         return $this->minutas;
  158.     }
  159.     public function addMinuta(Minuta $minuta): static
  160.     {
  161.         if (!$this->minutas->contains($minuta)) {
  162.             $this->minutas->add($minuta);
  163.             $minuta->setExpediente($this);
  164.         }
  165.         return $this;
  166.     }
  167.     public function removeMinuta(Minuta $minuta): static
  168.     {
  169.         if ($this->minutas->removeElement($minuta)) {
  170.             // set the owning side to null (unless already changed)
  171.             if ($minuta->getExpediente() === $this) {
  172.                 $minuta->setExpediente(null);
  173.             }
  174.         }
  175.         return $this;
  176.     }
  177.     public function getEstadoExpediente(): ?EstadoExpediente
  178.     {
  179.         return $this->estadoExpediente;
  180.     }
  181.     public function setEstadoExpediente(?EstadoExpediente $estadoExpediente): static
  182.     {
  183.         $this->estadoExpediente $estadoExpediente;
  184.         return $this;
  185.     }
  186.     public function getMetadata(): ?MetadataExpediente
  187.     {
  188.         return $this->metadata;
  189.     }
  190.     public function setMetadata(?MetadataExpediente $metadata): static
  191.     {
  192.         $this->metadata $metadata;
  193.         return $this;
  194.     }
  195.     public function getCreador(): ?SonataUserUser
  196.     {
  197.         return $this->creador;
  198.     }
  199.     public function setCreador(?SonataUserUser $creador): static
  200.     {
  201.         $this->creador $creador;
  202.         return $this;
  203.     }
  204.     public function getEntidad(): ?Entidad
  205.     {
  206.         return $this->entidad;
  207.     }
  208.     public function setEntidad(?Entidad $entidad): static
  209.     {
  210.         $this->entidad $entidad;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection<int, SonataUserUser>
  215.      */
  216.     public function getResponsables(): Collection
  217.     {
  218.         return $this->responsables;
  219.     }
  220.     public function addResponsable(SonataUserUser $responsable): static
  221.     {
  222.         if (!$this->responsables->contains($responsable)) {
  223.             $this->responsables->add($responsable);
  224.         }
  225.         return $this;
  226.     }
  227.     public function removeResponsable(SonataUserUser $responsable): static
  228.     {
  229.         $this->responsables->removeElement($responsable);
  230.         return $this;
  231.     }
  232.     public function getCabecera(): ?ExpedienteCabecera
  233.     {
  234.         return $this->cabecera;
  235.     }
  236.     public function setCabecera(?ExpedienteCabecera $cabecera): static
  237.     {
  238.         $this->cabecera $cabecera;
  239.         return $this;
  240.     }
  241.     public function getTipo(): ?string
  242.     {
  243.         switch ($this->getTramites()?->last()->getProcedimiento())
  244.         {
  245.             case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_EC:
  246.                  $return 'EC';
  247.                 break;
  248.             case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_M:
  249.                 $return 'M';
  250.                 break;
  251.             case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_C:
  252.                 $return 'C';
  253.                 break;
  254.             case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_A:
  255.                 $return 'A';
  256.                 break;
  257.             default:
  258.                 $return null;
  259.                 break;
  260.         }
  261.         return $return;
  262.     }
  263.     public function getEmpresa(): ?string
  264.     {
  265.         $data json_decode($this->getCustom(), true);
  266.         switch ($data['entidad'])
  267.         {
  268.             case 'EMPRESA':
  269.             case '0':
  270.                 $tipo 'E';
  271.                 break;
  272.             case 'SECTOR':
  273.             case '1':
  274.                 $tipo 'S';
  275.                 break;
  276.             default:
  277.                 $tipo '---';
  278.                 break;
  279.         }
  280.         return $tipo;
  281.     }
  282.     public function getEmpresaNombre(): ?string
  283.     {
  284.         $data json_decode($this->getCustom(), true);
  285.         switch ($data['entidad'])
  286.         {
  287.             case 'EMPRESA':
  288.             case '0':
  289.                 $id $data['empresa'];
  290.                 break;
  291.             case 'SECTOR':
  292.             case '1':
  293.                 $id $data['sector'];
  294.                 break;
  295.             default:
  296.                 $id null;
  297.                 break;
  298.         }
  299.         return $id;
  300.     }
  301.     /**
  302.      * @return Collection<int, DocumentacionRegistro>
  303.      */
  304.     public function getRegistros(): Collection
  305.     {
  306.         return $this->registros;
  307.     }
  308.     public function addRegistro(DocumentacionRegistro $registro): static
  309.     {
  310.         if (!$this->registros->contains($registro)) {
  311.             $this->registros->add($registro);
  312.             $registro->setExpediente($this);
  313.         }
  314.         return $this;
  315.     }
  316.     public function removeRegistro(DocumentacionRegistro $registro): static
  317.     {
  318.         if ($this->registros->removeElement($registro)) {
  319.             // set the owning side to null (unless already changed)
  320.             if ($registro->getExpediente() === $this) {
  321.                 $registro->setExpediente(null);
  322.             }
  323.         }
  324.         return $this;
  325.     }
  326.     public function getFase():?string
  327.     {
  328.         return $this->getEstadoExpediente()?->getSubestado();
  329.     }
  330.     public function getSubFase():?string
  331.     {
  332.         return $this->getTramites()?->last()->getNombre();
  333.     }
  334.     public function getSolicitud(): ?DocumentacionRegistro
  335.     {
  336.         return $this->solicitud;
  337.     }
  338.     public function setSolicitud(?DocumentacionRegistro $solicitud): static
  339.     {
  340.         $this->solicitud $solicitud;
  341.         return $this;
  342.     }
  343.     public function getCustom():?string
  344.     {
  345.         return $this->getSolicitud()?->getCustom()->getForm();
  346.     }
  347.     /**
  348.      * @return Collection<int, Representacion>
  349.      */
  350.     public function getRepresentacions(): Collection
  351.     {
  352.         return $this->representacions;
  353.     }
  354.     public function addRepresentacion(Representacion $representacion): static
  355.     {
  356.         if (!$this->representacions->contains($representacion)) {
  357.             $this->representacions->add($representacion);
  358.             $representacion->setExpediente($this);
  359.         }
  360.         return $this;
  361.     }
  362.     public function removeRepresentacion(Representacion $representacion): static
  363.     {
  364.         if ($this->representacions->removeElement($representacion)) {
  365.             // set the owning side to null (unless already changed)
  366.             if ($representacion->getExpediente() === $this) {
  367.                 $representacion->setExpediente(null);
  368.             }
  369.         }
  370.         return $this;
  371.     }
  372. }