src/Entity/Promocion.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\EstadoRelojEnum;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use JMS\Serializer\Annotation as JMS;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. /**
  16.  * @ORM\Entity(repositoryClass="App\Repository\PromocionRepository")
  17.  * @ORM\Table(name="promocion")
  18.  * @ORM\EntityListeners({"App\EntityListener\Promocion\CalcularIDPerseoListener"})
  19.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  20.  * @Vich\Uploadable
  21.  */
  22. class Promocion
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\Column(type="bigint", options={"unsigned":true})
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      * @JMS\Groups({
  29.      *     "api_v1_promocion_serialize"
  30.      * })
  31.      */
  32.     protected $id;
  33.     /**
  34.      * @ORM\Column(type="string", nullable=true)
  35.      */
  36.     protected $IDperseo;
  37.     /**
  38.      * @ORM\Column(
  39.      *     type="string",
  40.      *     nullable=false,
  41.      *     options={"default":"COMPRA","comment":"valores a tomar (Compra, Gestión)"}
  42.      * )
  43.      * @JMS\Groups({
  44.      *      "api_v1_promocion_serialize"
  45.      *  })
  46.      */
  47.     protected $tipo;
  48.     /**
  49.      * @ORM\Column(type="datetime", nullable=true, name="fecha_listo", options={"comment":"La más antigua"})
  50.      */
  51.     protected $fechaListo;
  52.     /**
  53.      * @ORM\Column(type="datetime", nullable=true, name="fecha_promocion", options={"comment":"Fecha de la promoción vigente"})
  54.      * @JMS\Groups({
  55.      *      "api_v1_promocion_serialize"
  56.      *  })
  57.      */
  58.     protected $fechaPromocion;
  59.     /**
  60.      * @ORM\Column(
  61.      *     type="datetime",
  62.      *     nullable=true,
  63.      *     name="fecha_anuncio",
  64.      *     options={"comment":"La fecha del primer anuncio"}
  65.      * )
  66.      */
  67.     private $fechaAnuncio;
  68.     /**
  69.      * @deprecated 30-01-2026
  70.      * Este campo queda obsoleto porque la fecha de venta ya se obtiene directamente
  71.      * de la información propia del reloj, evitando duplicidad y posibles inconsistencias.
  72.      *
  73.      * @ORM\Column(type="datetime", nullable=true, name="fecha_venta")
  74.      */
  75.     protected $fechaVenta;
  76.     /**
  77.      * @ORM\Column(type="float", nullable=true, precision=2, options={"comment":"Precio de la promoción vigente"})
  78.      * @JMS\Groups({
  79.      *      "api_v1_promocion_serialize"
  80.      *  })
  81.      */
  82.     protected $precio;
  83.     /**
  84.      * @ORM\Column(type="float", nullable=true, precision=2)
  85.      */
  86.     protected $precioChrono24;
  87.     /**
  88.      * @ORM\Column(type="float", nullable=true, precision=2)
  89.      */
  90.     protected $margenBrutoEsperado;
  91.     /**
  92.      * @ORM\Column(type="float", nullable=true, precision=2)
  93.      */
  94.     protected $margenNetoEsperado;
  95.     /**
  96.      * @ORM\Column(type="float", nullable=true, precision=2, options={"comment":"% tiempo desde la compra"})
  97.      */
  98.     protected $tiempo;
  99.     /**
  100.      * @ORM\Column(type="text", length=16834, nullable=true, options={"comment":"formato html"})
  101.      */
  102.     protected $comentarioPublico;
  103.     /**
  104.      * @ORM\Column(type="text", length=256, nullable=true)
  105.      */
  106.     protected $comentarioPrivado;
  107.     /**
  108.      * @ORM\Column(type="text", nullable=true)
  109.      */
  110.     protected $descripcion;
  111.     /**
  112.      * @ORM\Column(type="string", nullable=true, name="ubicacion_actual", options={"comment":"Ubicación actual"})
  113.      * @JMS\Groups({
  114.      *      "api_v1_promocion_serialize"
  115.      *  })
  116.      */
  117.     protected $ubicacionActual;
  118.     /**
  119.      * @ORM\Column(type="datetime", nullable=true, name="fecha_ubicacion_actual")
  120.      */
  121.     protected $fechaUbicacionActual;
  122.     /**
  123.      * @ORM\Column(type="string", nullable=true, name="estado_actual")
  124.      * @JMS\Groups({
  125.      *      "api_v1_promocion_serialize"
  126.      *  })
  127.      */
  128.     protected $estadoActual;
  129.     /**
  130.      * @ORM\Column(type="datetime", nullable=true, name="fecha_estado_actual")
  131.      * @JMS\Groups({
  132.      *      "api_v1_promocion_serialize"
  133.      *  })
  134.      */
  135.     private $fechaEstadoActual;
  136.     /**
  137.      * @ORM\Column(type="json", nullable=true, options={"comment":"Servicio y Mejoras"})
  138.      */
  139.     protected $costes;
  140.     /**
  141.      * @ORM\Column(type="string", nullable=true, name="reloj_foto")
  142.      */
  143.     protected $relojFoto;
  144.     /**
  145.      * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto")
  146.      * @var \Symfony\Component\HttpFoundation\File\File
  147.      */
  148.     protected $relojFotoFile;
  149.     /**
  150.      * @ORM\Column(type="string", nullable=true, name="reloj_foto_valoracion")
  151.      */
  152.     private $relojFotoValoracion;
  153.     /**
  154.      * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_valoracion")
  155.      * @var File
  156.      */
  157.     protected $relojFotoValoracionFile;
  158.     /**
  159.      * @ORM\Column(type="string", nullable=true, name="reloj_foto_set")
  160.      */
  161.     private $relojFotoSet;
  162.     /**
  163.      * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_set")
  164.      * @var File
  165.      */
  166.     protected $relojFotoSetFile;
  167.     /**
  168.      * @ORM\Column(type="string", nullable=true, name="reloj_foto_crono", options={"comment":"foto del cronocomparador"})
  169.      */
  170.     private $relojFotoCrono;
  171.     /**
  172.      * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_crono")
  173.      * @var File
  174.      */
  175.     protected $relojFotoCronoFile;
  176.     /**
  177.      * @ORM\Column(type="string", nullable=true, name="reloj_video")
  178.      */
  179.     private $relojVideo;
  180.     /**
  181.      * @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_video")
  182.      * @var File
  183.      */
  184.     protected $relojVideoFile;
  185.     /**
  186.      * @ORM\Column(type="float", nullable=true, precision=2)
  187.      */
  188.     private $recompra;
  189.     /**
  190.      * @ORM\Column(type="string", nullable=true)
  191.      */
  192.     private $garantia;
  193.     /**
  194.      * @ORM\Column(
  195.      *     type="boolean",
  196.      *     nullable=true,
  197.      *     options={
  198.      *         "default":1,
  199.      *         "comment":"Utilizado cuando ya existe promoción y has deshecho parte de operación y hay que desactivar
  200.      *     promoción hasta que operación este en estado aceptada."
  201.      *     }
  202.      * )
  203.      * @JMS\Groups({
  204.      *      "api_v1_promocion_serialize"
  205.      *  })
  206.      */
  207.     protected $active;
  208.     /**
  209.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  210.      * @JMS\Groups({
  211.      *      "api_v1_promocion_serialize"
  212.      *  })
  213.      */
  214.     protected $deletedAt;
  215.     /**
  216.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  217.      * @Gedmo\Timestampable(on="update")
  218.      */
  219.     protected $updatedAt;
  220.     /**
  221.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  222.      * @Gedmo\Timestampable(on="create")
  223.      */
  224.     protected $createdAt;
  225.     /**
  226.      * @ORM\JoinColumn(name="reloj_id", referencedColumnName="id", unique=true)
  227.      * @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="promociones")
  228.      * @JMS\Type(Reloj::class)
  229.      * @JMS\Groups({
  230.      *      "api_v1_promocion_serialize"
  231.      *  })
  232.      */
  233.     protected $reloj;
  234.     /**
  235.      * @ORM\OneToMany(targetEntity="App\Entity\AccionAbstract", mappedBy="promocion")
  236.      */
  237.     protected $acciones;
  238.     public function __construct()
  239.     {
  240.         $this->acciones = new ArrayCollection();
  241.     }
  242.     public function __toString(): string
  243.     {
  244.         return $this->getIDperseo().'';
  245.     }
  246.     public function getId(): ?string
  247.     {
  248.         return $this->id;
  249.     }
  250.     public function getFechaInicio(): ?DateTimeInterface
  251.     {
  252.         return $this->fechaInicio;
  253.     }
  254.     public function setFechaInicio(?DateTimeInterface $fechaInicio): self
  255.     {
  256.         $this->fechaInicio $fechaInicio;
  257.         return $this;
  258.     }
  259.     public function getFechaFin(): ?DateTimeInterface
  260.     {
  261.         return $this->fechaFin;
  262.     }
  263.     public function setFechaFin(?DateTimeInterface $fechaFin): self
  264.     {
  265.         $this->fechaFin $fechaFin;
  266.         return $this;
  267.     }
  268.     public function getPrecio(): ?float
  269.     {
  270.         return $this->precio;
  271.     }
  272.     public function setPrecio(?float $precio): self
  273.     {
  274.         $this->precio $precio;
  275.         return $this;
  276.     }
  277.     public function getDeletedAt(): ?DateTimeInterface
  278.     {
  279.         return $this->deletedAt;
  280.     }
  281.     public function setDeletedAt(?DateTimeInterface $deletedAt): self
  282.     {
  283.         $this->deletedAt $deletedAt;
  284.         return $this;
  285.     }
  286.     public function getUpdatedAt(): ?DateTimeInterface
  287.     {
  288.         return $this->updatedAt;
  289.     }
  290.     public function setUpdatedAt(DateTimeInterface $updatedAt): self
  291.     {
  292.         $this->updatedAt $updatedAt;
  293.         return $this;
  294.     }
  295.     public function getCreatedAt(): ?DateTimeInterface
  296.     {
  297.         return $this->createdAt;
  298.     }
  299.     public function setCreatedAt(DateTimeInterface $createdAt): self
  300.     {
  301.         $this->createdAt $createdAt;
  302.         return $this;
  303.     }
  304.     public function getCanal(): ?Canal
  305.     {
  306.         return $this->canal;
  307.     }
  308.     public function setCanal(?Canal $canal): self
  309.     {
  310.         $this->canal $canal;
  311.         return $this;
  312.     }
  313.     public function getFechaPromocion(): ?DateTimeInterface
  314.     {
  315.         return $this->fechaPromocion;
  316.     }
  317.     public function setFechaPromocion(?DateTimeInterface $fechaPromocion): self
  318.     {
  319.         $this->fechaPromocion $fechaPromocion;
  320.         return $this;
  321.     }
  322.     public function getMargenBrutoEsperado(): ?float
  323.     {
  324.         return $this->margenBrutoEsperado;
  325.     }
  326.     public function setMargenBrutoEsperado(?float $margenBrutoEsperado): self
  327.     {
  328.         $this->margenBrutoEsperado $margenBrutoEsperado;
  329.         return $this;
  330.     }
  331.     public function getMargenNetoEsperado(): ?float
  332.     {
  333.         return $this->margenNetoEsperado;
  334.     }
  335.     public function setMargenNetoEsperado(?float $margenNetoEsperado): self
  336.     {
  337.         $this->margenNetoEsperado $margenNetoEsperado;
  338.         return $this;
  339.     }
  340.     public function getTiempo(): ?float
  341.     {
  342.         return $this->tiempo;
  343.     }
  344.     public function setTiempo(?float $tiempo): self
  345.     {
  346.         $this->tiempo $tiempo;
  347.         return $this;
  348.     }
  349.     public function getComentarioPublico(): ?string
  350.     {
  351.         return $this->comentarioPublico;
  352.     }
  353.     public function setComentarioPublico(?string $comentarioPublico): self
  354.     {
  355.         $this->comentarioPublico $comentarioPublico;
  356.         return $this;
  357.     }
  358.     public function getComentarioPrivado(): ?string
  359.     {
  360.         return $this->comentarioPrivado;
  361.     }
  362.     public function setComentarioPrivado(?string $comentarioPrivado): self
  363.     {
  364.         $this->comentarioPrivado $comentarioPrivado;
  365.         return $this;
  366.     }
  367.     /**
  368.      * @return Collection<int, AccionAbstract>
  369.      */
  370.     public function getAcciones(): Collection
  371.     {
  372.         return $this->acciones;
  373.     }
  374.     public function addAccione(AccionAbstract $accione): self
  375.     {
  376.         if (!$this->acciones->contains($accione)) {
  377.             $this->acciones->add($accione);
  378.             $accione->setPromocion($this);
  379.         }
  380.         return $this;
  381.     }
  382.     public function removeAccione(AccionAbstract $accione): self
  383.     {
  384.         if ($this->acciones->removeElement($accione)) {
  385.             // set the owning side to null (unless already changed)
  386.             if ($accione->getPromocion() === $this) {
  387.                 $accione->setPromocion(null);
  388.             }
  389.         }
  390.         return $this;
  391.     }
  392.     public function getReloj(): ?Reloj
  393.     {
  394.         return $this->reloj;
  395.     }
  396.     public function setReloj(?Reloj $reloj): static
  397.     {
  398.         $this->reloj $reloj;
  399.         return $this;
  400.     }
  401.     public function getIDperseo(): ?string
  402.     {
  403.         return $this->IDperseo;
  404.     }
  405.     public function setIDperseo(?string $IDperseo): static
  406.     {
  407.         $this->IDperseo $IDperseo;
  408.         return $this;
  409.     }
  410.     public function getPrecioChrono24(): ?float
  411.     {
  412.         return $this->precioChrono24;
  413.     }
  414.     public function setPrecioChrono24(?float $precioChrono24): static
  415.     {
  416.         $this->precioChrono24 $precioChrono24;
  417.         return $this;
  418.     }
  419.     public function getDescripcion(): ?string
  420.     {
  421.         return $this->descripcion;
  422.     }
  423.     public function setDescripcion(?string $descripcion): static
  424.     {
  425.         $this->descripcion $descripcion;
  426.         return $this;
  427.     }
  428.     public function getUbicacionActual(): ?string
  429.     {
  430.         return $this->ubicacionActual;
  431.     }
  432.     public function setUbicacionActual(?string $ubicacionActual): static
  433.     {
  434.         $this->ubicacionActual $ubicacionActual;
  435.         return $this;
  436.     }
  437.     public function getEstadoActual(): ?string
  438.     {
  439.         $sort = new Criteria(null, ['fecha' => Criteria::DESC'createdAt' => Criteria::DESC]);
  440.         $acciones $this->getAcciones()->matching($sort);
  441.         foreach ($acciones as $accion)
  442.         {
  443.             if(!$accion instanceof AccionServicio && !$accion instanceof AccionMejora && !$accion instanceof AccionCompetencia) break;
  444.         }
  445.         $checked = @$accion instanceof AccionCheck && $accion->getEstado() !== null;
  446.         return $checked '---' $this->estadoActual;
  447.     }
  448.     public function setEstadoActual(?string $estadoActual): static
  449.     {
  450.         $this->estadoActual $estadoActual;
  451.         return $this;
  452.     }
  453.     public function getCostes(): ?array
  454.     {
  455.         return $this->costes;
  456.     }
  457.     public function setCostes(?array $costes): static
  458.     {
  459.         $this->costes $costes;
  460.         return $this;
  461.     }
  462.     public function getUbicacion(): string
  463.     {
  464.         return '---';
  465.     }
  466.     public function getTipo(): ?string
  467.     {
  468.         return $this->tipo;
  469.     }
  470.     public function setTipo(string $tipo): static
  471.     {
  472.         $this->tipo $tipo;
  473.         return $this;
  474.     }
  475.     public function getFechaListo(): ?DateTimeInterface
  476.     {
  477.         return $this->fechaListo;
  478.     }
  479.     public function setFechaListo(?DateTimeInterface $fechaListo): static
  480.     {
  481.         $this->fechaListo $fechaListo;
  482.         return $this;
  483.     }
  484.     public function getFechaVenta(): ?DateTimeInterface
  485.     {
  486.         return $this->fechaVenta;
  487.     }
  488.     public function setFechaVenta(?DateTimeInterface $fechaVenta): static
  489.     {
  490.         $this->fechaVenta $fechaVenta;
  491.         return $this;
  492.     }
  493.     public function getRelojFoto(): ?string
  494.     {
  495.         return $this->relojFoto;
  496.     }
  497.     public function setRelojFoto(?string $relojFoto): static
  498.     {
  499.         $this->relojFoto $relojFoto;
  500.         return $this;
  501.     }
  502.     public function getRelojFotoFile(): ?File
  503.     {
  504.         return $this->relojFotoFile;
  505.     }
  506.     public function setRelojFotoFile(?File $relojFotoFile): static
  507.     {
  508.         $this->relojFotoFile $relojFotoFile;
  509.         if($relojFotoFile)
  510.         {
  511.             $this->setUpdatedAt(new DateTime('now'));
  512.         }
  513.         return $this;
  514.     }
  515.     public function getRelojFotoValoracion(): ?string
  516.     {
  517.         return $this->relojFotoValoracion;
  518.     }
  519.     public function setRelojFotoValoracion(?string $relojFotoValoracion): static
  520.     {
  521.         $this->relojFotoValoracion $relojFotoValoracion;
  522.         return $this;
  523.     }
  524.     public function getRelojFotoValoracionFile(): ?File
  525.     {
  526.         return $this->relojFotoValoracionFile;
  527.     }
  528.     public function setRelojFotoValoracionFile(?File $relojFotoValoracionFile): static
  529.     {
  530.         $this->relojFotoValoracionFile $relojFotoValoracionFile;
  531.         if($relojFotoValoracionFile)
  532.         {
  533.             $this->setUpdatedAt(new DateTime('now'));
  534.         }
  535.         return $this;
  536.     }
  537.     public function getRelojFotoSet(): ?string
  538.     {
  539.         return $this->relojFotoSet;
  540.     }
  541.     public function setRelojFotoSet(?string $relojFotoSet): static
  542.     {
  543.         $this->relojFotoSet $relojFotoSet;
  544.         return $this;
  545.     }
  546.     public function getRelojFotoSetFile(): ?File
  547.     {
  548.         return $this->relojFotoSetFile;
  549.     }
  550.     public function setRelojFotoSetFile(?File $relojFotoSetFile): static
  551.     {
  552.         $this->relojFotoSetFile $relojFotoSetFile;
  553.         if($relojFotoSetFile)
  554.         {
  555.             $this->setUpdatedAt(new DateTime('now'));
  556.         }
  557.         return $this;
  558.     }
  559.     public function getRelojFotoCrono(): ?string
  560.     {
  561.         return $this->relojFotoCrono;
  562.     }
  563.     public function setRelojFotoCrono(?string $relojFotoCrono): static
  564.     {
  565.         $this->relojFotoCrono $relojFotoCrono;
  566.         return $this;
  567.     }
  568.     public function getRelojFotoCronoFile(): ?File
  569.     {
  570.         return $this->relojFotoCronoFile;
  571.     }
  572.     public function setRelojFotoCronoFile(?File $relojFotoCronoFile): static
  573.     {
  574.         $this->relojFotoCronoFile $relojFotoCronoFile;
  575.         if($relojFotoCronoFile)
  576.         {
  577.             $this->setUpdatedAt(new DateTime('now'));
  578.         }
  579.         return $this;
  580.     }
  581.     public function getRelojVideo(): ?string
  582.     {
  583.         return $this->relojVideo;
  584.     }
  585.     public function setRelojVideo(?string $relojVideo): static
  586.     {
  587.         $this->relojVideo $relojVideo;
  588.         return $this;
  589.     }
  590.     public function getRelojVideoFile(): ?File
  591.     {
  592.         return $this->relojVideoFile;
  593.     }
  594.     public function setRelojVideoFile(?File $relojVideoFile): static
  595.     {
  596.         $this->relojVideoFile $relojVideoFile;
  597.         if($relojVideoFile)
  598.         {
  599.             $this->setUpdatedAt(new DateTime('now'));
  600.         }
  601.         return $this;
  602.     }
  603.     public function isActive(): ?bool
  604.     {
  605.         return $this->active;
  606.     }
  607.     public function setActive(?bool $active): static
  608.     {
  609.         $this->active $active;
  610.         return $this;
  611.     }
  612.     public function getRecompra(): ?float
  613.     {
  614.         return $this->recompra;
  615.     }
  616.     public function setRecompra(?float $recompra): static
  617.     {
  618.         $this->recompra $recompra;
  619.         return $this;
  620.     }
  621.     public function getGarantia(): ?string
  622.     {
  623.         return $this->garantia;
  624.     }
  625.     public function setGarantia(?string $garantia): static
  626.     {
  627.         $this->garantia $garantia;
  628.         return $this;
  629.     }
  630.     public function getExportFechaPromocion(): ?string
  631.     {
  632.         return $this->getFechaPromocion()?->format('d/m/Y');
  633.     }
  634.     public function fechaEstadoCompraStr(): ?string
  635.     {
  636.         return $this->fechaEstadoCompra()?->format('d/m/Y');
  637.     }
  638.     /**
  639.      * Obtiene la fecha en la que la entidad pasó al estado de compra.
  640.      *
  641.      * El valor se obtiene a partir de las acciones asociadas a la entidad.
  642.      * Se expone como propiedad virtual para aquellos mecanismos que necesiten
  643.      * serializar o consultar este valor.
  644.      *
  645.      * @JMS\VirtualProperty()
  646.      * @JMS\SerializedName("fecha_estado_compra")
  647.      * @JMS\Groups({
  648.      *     "api_v1_promocion_serialize"
  649.      * })
  650.      * @return DateTimeInterface|null
  651.      */
  652.     public function fechaEstadoCompra(): ?DateTimeInterface
  653.     {
  654.         $estado $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_COMPRA )->first();
  655.         return $estado $estado->getFecha() : null;
  656.     }
  657.     public function fechaEstadoRecepcionStr(): ?string
  658.     {
  659.         return $this->fechaEstadoRecepcion()?->format('d/m/Y');
  660.     }
  661.     public function fechaEstadoRecepcion(): ?DateTimeInterface
  662.     {
  663.         $estado $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_RECEPCION )->first();
  664.         return $estado $estado->getFecha() : null;
  665.     }
  666.     public function getFechaUbicacionActual(): ?DateTimeInterface
  667.     {
  668.         return $this->fechaUbicacionActual;
  669.     }
  670.     public function setFechaUbicacionActual(?DateTimeInterface $fechaUbicacionActual): static
  671.     {
  672.         $this->fechaUbicacionActual $fechaUbicacionActual;
  673.         return $this;
  674.     }
  675.     public function getFechaAnuncio(): ?DateTimeInterface
  676.     {
  677.         return $this->fechaAnuncio;
  678.     }
  679.     public function setFechaAnuncio(?DateTimeInterface $fechaAnuncio): static
  680.     {
  681.         $this->fechaAnuncio $fechaAnuncio;
  682.         return $this;
  683.     }
  684.     public function getFechaEstadoActual(): ?DateTimeInterface
  685.     {
  686.         return $this->fechaEstadoActual;
  687.     }
  688.     public function setFechaEstadoActual(?DateTimeInterface $fechaEstadoActual): static
  689.     {
  690.         $this->fechaEstadoActual $fechaEstadoActual;
  691.         return $this;
  692.     }
  693.     public function calculateUbicacion()
  694.     {
  695.         $ubicacionMasReciente $this->getAcciones()
  696.             ->filter(fn($accion) => $accion instanceof AccionUbicacion)
  697.             ->reduce(
  698.                 function (?AccionUbicacion $masRecienteAccionUbicacion $actual) {
  699.                     if ($masReciente === null || $actual->getFecha() > $masReciente->getFecha()) {
  700.                         return $actual;
  701.                     }
  702.                     return $masReciente;
  703.                 },
  704.                 null
  705.             );
  706.         $this->setUbicacionActual($ubicacionMasReciente);
  707.         $this->setFechaUbicacionActual($ubicacionMasReciente?->getFecha());
  708.         return $ubicacionMasReciente;
  709.     }
  710.     public function calculateFirstAnuncio(): ?AccionEstado
  711.     {
  712.         $anuncioFirst $this->getAccionesAnuncio()
  713.             ->reduce(
  714.                 function (?AccionEstado $primeroAccionEstado $actual): ?AccionEstado {
  715.                     return $primero === null || $actual->getFecha() < $primero->getFecha()
  716.                         ? $actual
  717.                         $primero;
  718.                 },
  719.                 null
  720.             );
  721.         $this->setfechaAnuncio($anuncioFirst?->getFecha());
  722.         return $anuncioFirst;
  723.     }
  724.     public function calculateLastAnuncio(): ?AccionEstado
  725.     {
  726.         $anuncioLast $this->getAccionesAnuncio()
  727.             ->reduce(
  728.                 function (?AccionEstado $ultimoAccionEstado $actual): ?AccionEstado {
  729.                     return $ultimo === null || $actual->getFecha() > $ultimo->getFecha()
  730.                         ? $actual
  731.                         $ultimo;
  732.                 },
  733.                 null
  734.             );
  735.         $this->setPrecio($anuncioLast?->getPrecio());
  736.         $this->setfechaPromocion($anuncioLast?->getFecha());
  737.         return $anuncioLast;
  738.     }
  739.     private function getAccionesAnuncio(): Collection
  740.     {
  741.         return $this->getAcciones()->filter(
  742.             fn($accion) =>
  743.                 $accion instanceof AccionEstado
  744.                 && $accion->getEstado()->getKey() === EstadoRelojEnum::ESTADO_ANUNCIO
  745.         );
  746.     }
  747. }