<?php
namespace App\Entity;
use App\Enum\EstadoRelojEnum;
use DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\PromocionRepository")
* @ORM\Table(name="promocion", schema="perseo")
* @ORM\EntityListeners({"App\EntityListener\Promocion\CalcularIDPerseoListener"})
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
* @Vich\Uploadable
*/
class Promocion
{
/**
* @ORM\Id
* @ORM\Column(type="bigint", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $IDperseo;
/**
* @ORM\Column(
* type="string",
* nullable=false,
* options={"default":"COMPRA","comment":"valores a tomar (Compra, Gestión)"}
* )
*/
protected $tipo;
/**
* @ORM\Column(type="datetime", nullable=true, name="fecha_promocion", options={"comment":"La más antigua"})
*/
protected $fechaPromocion;
/**
* @ORM\Column(type="datetime", nullable=true, name="fecha_listo", options={"comment":"La más antigua"})
*/
protected $fechaListo;
/**
* @ORM\Column(type="datetime", nullable=true, name="fecha_venta")
*/
protected $fechaVenta;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
protected $precio;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
protected $precioChrono24;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
protected $margenBrutoEsperado;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
protected $margenNetoEsperado;
/**
* @ORM\Column(type="float", nullable=true, precision=2, options={"comment":"% tiempo desde la compra"})
*/
protected $tiempo;
/**
* @ORM\Column(type="text", length=16834, nullable=true, options={"comment":"formato html"})
*/
protected $comentarioPublico;
/**
* @ORM\Column(type="text", length=256, nullable=true)
*/
protected $comentarioPrivado;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $descripcion;
/**
* @ORM\Column(type="string", nullable=true, name="ubicacion_actual", options={"comment":"Ubicación actual"})
*/
protected $ubicacionActual;
/**
* @ORM\Column(type="datetime", nullable=true, name="fecha_ubicacion_actual")
*/
protected $fechaUbicacionActual;
/**
* @ORM\Column(
* type="datetime",
* nullable=true,
* name="fecha_anuncio",
* options={"comment":"La fecha del primer anuncio"}
* )
*/
private $fechaAnuncio;
/**
* @ORM\Column(type="string", nullable=true, name="estado_actual")
*/
protected $estadoActual;
/**
* @ORM\Column(type="datetime", nullable=true, name="fecha_estado_actual")
*/
private $fechaEstadoActual;
/**
* @ORM\Column(type="json", nullable=true, options={"comment":"Servicio y Mejoras"})
*/
protected $costes;
/**
* @ORM\Column(type="string", nullable=true, name="reloj_foto")
*/
protected $relojFoto;
/**
* @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto")
* @var \Symfony\Component\HttpFoundation\File\File
*/
protected $relojFotoFile;
/**
* @ORM\Column(type="string", nullable=true, name="reloj_foto_valoracion")
*/
private $relojFotoValoracion;
/**
* @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_valoracion")
* @var File
*/
protected $relojFotoValoracionFile;
/**
* @ORM\Column(type="string", nullable=true, name="reloj_foto_set")
*/
private $relojFotoSet;
/**
* @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_set")
* @var File
*/
protected $relojFotoSetFile;
/**
* @ORM\Column(type="string", nullable=true, name="reloj_foto_crono", options={"comment":"foto del cronocomparador"})
*/
private $relojFotoCrono;
/**
* @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_foto_crono")
* @var File
*/
protected $relojFotoCronoFile;
/**
* @ORM\Column(type="string", nullable=true, name="reloj_video")
*/
private $relojVideo;
/**
* @Vich\UploadableField(mapping="reloj", fileNameProperty="reloj_video")
* @var File
*/
protected $relojVideoFile;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
private $recompra;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $garantia;
/**
* @ORM\Column(
* type="boolean",
* nullable=true,
* options={
* "default":1,
* "comment":"Utilizado cuando ya existe promoción y has deshecho parte de operación y hay que desactivar
* promoción hasta que operación este en estado aceptada."
* }
* )
*/
protected $active;
/**
* @ORM\Column(type="datetime", nullable=true, name="deleted_at")
*/
protected $deletedAt;
/**
* @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
* @Gedmo\Timestampable(on="update")
*/
protected $updatedAt;
/**
* @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
* @Gedmo\Timestampable(on="create")
*/
protected $createdAt;
/**
* @ORM\JoinColumn(name="reloj_id", referencedColumnName="id", unique=true)
* @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="promociones")
*/
protected $reloj;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AccionAbstract", mappedBy="promocion")
*/
protected $acciones;
public function __construct()
{
$this->acciones = new ArrayCollection();
}
public function __toString(): string
{
return $this->getIDperseo().'';
}
public function getId(): ?string
{
return $this->id;
}
public function getFechaInicio(): ?DateTimeInterface
{
return $this->fechaInicio;
}
public function setFechaInicio(?DateTimeInterface $fechaInicio): self
{
$this->fechaInicio = $fechaInicio;
return $this;
}
public function getFechaFin(): ?DateTimeInterface
{
return $this->fechaFin;
}
public function setFechaFin(?DateTimeInterface $fechaFin): self
{
$this->fechaFin = $fechaFin;
return $this;
}
public function getPrecio(): ?float
{
return $this->precio;
}
public function setPrecio(?float $precio): self
{
$this->precio = $precio;
return $this;
}
public function getDeletedAt(): ?DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getCreatedAt(): ?DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCanal(): ?Canal
{
return $this->canal;
}
public function setCanal(?Canal $canal): self
{
$this->canal = $canal;
return $this;
}
public function getFechaPromocion(): ?DateTimeInterface
{
return $this->fechaPromocion;
}
public function setFechaPromocion(?DateTimeInterface $fechaPromocion): self
{
$this->fechaPromocion = $fechaPromocion;
return $this;
}
public function getMargenBrutoEsperado(): ?float
{
return $this->margenBrutoEsperado;
}
public function setMargenBrutoEsperado(?float $margenBrutoEsperado): self
{
$this->margenBrutoEsperado = $margenBrutoEsperado;
return $this;
}
public function getMargenNetoEsperado(): ?float
{
return $this->margenNetoEsperado;
}
public function setMargenNetoEsperado(?float $margenNetoEsperado): self
{
$this->margenNetoEsperado = $margenNetoEsperado;
return $this;
}
public function getTiempo(): ?float
{
return $this->tiempo;
}
public function setTiempo(?float $tiempo): self
{
$this->tiempo = $tiempo;
return $this;
}
public function getComentarioPublico(): ?string
{
return $this->comentarioPublico;
}
public function setComentarioPublico(?string $comentarioPublico): self
{
$this->comentarioPublico = $comentarioPublico;
return $this;
}
public function getComentarioPrivado(): ?string
{
return $this->comentarioPrivado;
}
public function setComentarioPrivado(?string $comentarioPrivado): self
{
$this->comentarioPrivado = $comentarioPrivado;
return $this;
}
/**
* @return Collection<int, AccionAbstract>
*/
public function getAcciones(): Collection
{
return $this->acciones;
}
public function addAccione(AccionAbstract $accione): self
{
if (!$this->acciones->contains($accione)) {
$this->acciones->add($accione);
$accione->setPromocion($this);
}
return $this;
}
public function removeAccione(AccionAbstract $accione): self
{
if ($this->acciones->removeElement($accione)) {
// set the owning side to null (unless already changed)
if ($accione->getPromocion() === $this) {
$accione->setPromocion(null);
}
}
return $this;
}
public function getReloj(): ?Reloj
{
return $this->reloj;
}
public function setReloj(?Reloj $reloj): static
{
$this->reloj = $reloj;
return $this;
}
public function getIDperseo(): ?string
{
return $this->IDperseo;
}
public function setIDperseo(?string $IDperseo): static
{
$this->IDperseo = $IDperseo;
return $this;
}
public function getPrecioChrono24(): ?float
{
return $this->precioChrono24;
}
public function setPrecioChrono24(?float $precioChrono24): static
{
$this->precioChrono24 = $precioChrono24;
return $this;
}
public function getDescripcion(): ?string
{
return $this->descripcion;
}
public function setDescripcion(?string $descripcion): static
{
$this->descripcion = $descripcion;
return $this;
}
public function getUbicacionActual(): ?string
{
return $this->ubicacionActual;
}
public function setUbicacionActual(?string $ubicacionActual): static
{
$this->ubicacionActual = $ubicacionActual;
return $this;
}
public function getEstadoActual(): ?string
{
$sort = new Criteria(null, ['fecha' => Criteria::DESC, 'createdAt' => Criteria::DESC]);
$acciones = $this->getAcciones()->matching($sort);
foreach ($acciones as $accion)
{
if(!$accion instanceof AccionServicio && !$accion instanceof AccionMejora && !$accion instanceof AccionCompetencia) break;
}
$checked = @$accion instanceof AccionCheck && $accion->getEstado() !== null;
return $checked ? '---' : $this->estadoActual;
}
public function setEstadoActual(?string $estadoActual): static
{
$this->estadoActual = $estadoActual;
return $this;
}
public function getCostes(): ?array
{
return $this->costes;
}
public function setCostes(?array $costes): static
{
$this->costes = $costes;
return $this;
}
public function getUbicacion(): string
{
return '---';
}
public function getTipo(): ?string
{
return $this->tipo;
}
public function setTipo(string $tipo): static
{
$this->tipo = $tipo;
return $this;
}
public function getFechaListo(): ?DateTimeInterface
{
return $this->fechaListo;
}
public function setFechaListo(?DateTimeInterface $fechaListo): static
{
$this->fechaListo = $fechaListo;
return $this;
}
public function getFechaVenta(): ?DateTimeInterface
{
return $this->fechaVenta;
}
public function setFechaVenta(?DateTimeInterface $fechaVenta): static
{
$this->fechaVenta = $fechaVenta;
return $this;
}
public function getRelojFoto(): ?string
{
return $this->relojFoto;
}
public function setRelojFoto(?string $relojFoto): static
{
$this->relojFoto = $relojFoto;
return $this;
}
public function getRelojFotoFile(): ?File
{
return $this->relojFotoFile;
}
public function setRelojFotoFile(?File $relojFotoFile): static
{
$this->relojFotoFile = $relojFotoFile;
if($relojFotoFile)
{
$this->setUpdatedAt(new DateTime('now'));
}
return $this;
}
public function getRelojFotoValoracion(): ?string
{
return $this->relojFotoValoracion;
}
public function setRelojFotoValoracion(?string $relojFotoValoracion): static
{
$this->relojFotoValoracion = $relojFotoValoracion;
return $this;
}
public function getRelojFotoValoracionFile(): ?File
{
return $this->relojFotoValoracionFile;
}
public function setRelojFotoValoracionFile(?File $relojFotoValoracionFile): static
{
$this->relojFotoValoracionFile = $relojFotoValoracionFile;
if($relojFotoValoracionFile)
{
$this->setUpdatedAt(new DateTime('now'));
}
return $this;
}
public function getRelojFotoSet(): ?string
{
return $this->relojFotoSet;
}
public function setRelojFotoSet(?string $relojFotoSet): static
{
$this->relojFotoSet = $relojFotoSet;
return $this;
}
public function getRelojFotoSetFile(): ?File
{
return $this->relojFotoSetFile;
}
public function setRelojFotoSetFile(?File $relojFotoSetFile): static
{
$this->relojFotoSetFile = $relojFotoSetFile;
if($relojFotoSetFile)
{
$this->setUpdatedAt(new DateTime('now'));
}
return $this;
}
public function getRelojFotoCrono(): ?string
{
return $this->relojFotoCrono;
}
public function setRelojFotoCrono(?string $relojFotoCrono): static
{
$this->relojFotoCrono = $relojFotoCrono;
return $this;
}
public function getRelojFotoCronoFile(): ?File
{
return $this->relojFotoCronoFile;
}
public function setRelojFotoCronoFile(?File $relojFotoCronoFile): static
{
$this->relojFotoCronoFile = $relojFotoCronoFile;
if($relojFotoCronoFile)
{
$this->setUpdatedAt(new DateTime('now'));
}
return $this;
}
public function getRelojVideo(): ?string
{
return $this->relojVideo;
}
public function setRelojVideo(?string $relojVideo): static
{
$this->relojVideo = $relojVideo;
return $this;
}
public function getRelojVideoFile(): ?File
{
return $this->relojVideoFile;
}
public function setRelojVideoFile(?File $relojVideoFile): static
{
$this->relojVideoFile = $relojVideoFile;
if($relojVideoFile)
{
$this->setUpdatedAt(new DateTime('now'));
}
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): static
{
$this->active = $active;
return $this;
}
public function getRecompra(): ?float
{
return $this->recompra;
}
public function setRecompra(?float $recompra): static
{
$this->recompra = $recompra;
return $this;
}
public function getGarantia(): ?string
{
return $this->garantia;
}
public function setGarantia(?string $garantia): static
{
$this->garantia = $garantia;
return $this;
}
public function getExportFechaPromocion(): ?string
{
return $this->getFechaPromocion()?->format('d/m/Y');
}
public function diasEnVenta(): ?string
{
$now = new DateTime();
return $this->getFechaPromocion() ? ($this->getFechaVenta() ? $this->getFechaPromocion()->diff($this->getFechaVenta())->format('%a') : $this->getFechaPromocion()->diff($now)->format('%a')) : null;
}
public function fechaEstadoCompraStr(): ?string
{
return $this->fechaEstadoCompra()?->format('d/m/Y');
}
public function fechaEstadoCompra(): ?DateTimeInterface
{
$estado = $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_COMPRA )->first();
return $estado ? $estado->getFecha() : null;
}
public function fechaEstadoRecepcionStr(): ?string
{
return $this->fechaEstadoRecepcion()?->format('d/m/Y');
}
public function fechaEstadoRecepcion(): ?DateTimeInterface
{
$estado = $this->getAcciones()->filter(fn($accion) => $accion instanceof AccionEstado && $accion->getEstado()?->getKey() === EstadoRelojEnum::ESTADO_RECEPCION )->first();
return $estado ? $estado->getFecha() : null;
}
public function getFechaUbicacionActual(): ?DateTimeInterface
{
return $this->fechaUbicacionActual;
}
public function setFechaUbicacionActual(?DateTimeInterface $fechaUbicacionActual): static
{
$this->fechaUbicacionActual = $fechaUbicacionActual;
return $this;
}
public function getFechaAnuncio(): ?\DateTimeInterface
{
return $this->fechaAnuncio;
}
public function setFechaAnuncio(?\DateTimeInterface $fechaAnuncio): static
{
$this->fechaAnuncio = $fechaAnuncio;
return $this;
}
public function getFechaEstadoActual(): ?\DateTimeInterface
{
return $this->fechaEstadoActual;
}
public function setFechaEstadoActual(?\DateTimeInterface $fechaEstadoActual): static
{
$this->fechaEstadoActual = $fechaEstadoActual;
return $this;
}
}