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