src/Entity/Promocion.php line 24

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