<?php
namespace App\Entity;
use App\Enum\IdiomaEnum;
use App\Enum\TipoGarantiaEnum;
use DateInterval;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\DetalleVentaRepository")
* @ORM\Table(name="detalle_venta", schema="perseo")
* @ORM\EntityListeners({
* "App\EntityListener\DetalleVenta\CrearAccionEnviadoListener",
* "App\EntityListener\DetalleVenta\ControlRelojesOperacionListener"
* })
*/
class DetalleVenta extends DetalleOperacion
{
/**
* @ORM\Column(
* type="float",
* nullable=true,
* precision=2,
* name="precio_coste_total",
* options={"default":"0.00","comment":"Coste del reloj + costes reparación, servicios u otros añadidos en PROMOCION"}
* )
*/
protected $precioCosteTotal;
/**
* @ORM\Column(type="float", nullable=true, precision=2, name="precio_venta", options={"default":"0.00","unsigned":true})
*/
protected $precioVenta;
/**
* @ORM\Column(type="float", nullable=true, precision=2, name="margen_beneficio", options={"default":"0.00","comment":"%"})
*/
protected $margenBeneficio;
/**
* @ORM\Column(type="float", nullable=true, precision=2, options={"default":"0.00"})
*/
protected $descuento;
/**
* @ORM\Column(
* type="datetime",
* nullable=true,
* name="fecha_envio",
* options={"comment":"Cada vez que se modifica la fecha envío se crea un nuevo estado envio en promoción."}
* )
*/
private $fechaEnvio;
/**
* @ORM\Column(type="float", nullable=true, precision=2)
*/
protected $recompra;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $garantia;
/**
* @ORM\ManyToOne(targetEntity=\App\Entity\Venta::class, inversedBy="detalleVentas")
* @ORM\JoinColumn(name="venta_id", referencedColumnName="id")
*/
protected $venta;
/*
* @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
* @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="detalleVenta")
*/
// private $reloj;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="detalleVenta")
* @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
*/
protected $reloj;
/*public function __toString(): string
{
return $this->getVenta()->__toString() . ' - ' . $this->getReloj() ?? '---';
}*/
public function getVenta(): ?Venta
{
return $this->venta;
}
public function setVenta(?Venta $venta): self
{
$this->venta = $venta;
return $this;
}
public function getPrecioCosteTotal(): ?float
{
return $this->precioCosteTotal;
}
public function setPrecioCosteTotal(?float $precioCosteTotal): self
{
$this->precioCosteTotal = $precioCosteTotal;
return $this;
}
public function getPrecioVenta(): ?float
{
return $this->precioVenta;
}
public function setPrecioVenta(?float $precioVenta): self
{
$this->precioVenta = $precioVenta;
return $this;
}
public function getMargenBeneficio(): ?float
{
return $this->margenBeneficio;
}
public function setMargenBeneficio(?float $margenBeneficio): self
{
$this->margenBeneficio = $margenBeneficio;
return $this;
}
public function getDescuento(): ?float
{
return $this->descuento;
}
public function setDescuento(?float $descuento): self
{
$this->descuento = $descuento;
return $this;
}
public function getReloj(): ?Reloj
{
return $this->reloj;
}
public function setReloj(?Reloj $reloj): static
{
$this->reloj = $reloj;
return $this;
}
public function getFechaEnvio(): ?DateTimeInterface
{
return $this->fechaEnvio;
}
public function setFechaEnvio(?DateTimeInterface $fechaEnvio): static
{
$this->fechaEnvio = $fechaEnvio;
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 getGarantiaStr(): ?string
{
switch ($this->getVenta()->getOperacion()->getIdioma())
{
case IdiomaEnum::IDIOMA_ES:
$garantia = $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN ? null : 'Sobre el calibre';
break;
case IdiomaEnum::IDIOMA_EN:
$garantia = $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN ? null : 'Over the movement';
break;
default:
$garantia = null;
break;
}
return $garantia;
}
public function getGarantiaFecha(): ?DateTimeInterface
{
switch ($this->getGarantia())
{
case TipoGarantiaEnum::GARANTIA_6:
$fechaGarantia = $this->getFechaEnvio()->add(new DateInterval('P' . 365*6/12 . 'D'));
break;
case TipoGarantiaEnum::GARANTIA_12:
$fechaGarantia = $this->getFechaEnvio()->add(new DateInterval('P' . 365*12/12 . 'D'));
break;
default:
$fechaGarantia = null;
break;
}
return $fechaGarantia;
}
public function getRecompraStr(): ?string
{
if(!$this->getGarantiaStr()) return null;
switch ($this->getVenta()->getOperacion()->getIdioma())
{
case IdiomaEnum::IDIOMA_ES:
$recompra = 'Recompra:';
break;
case IdiomaEnum::IDIOMA_EN:
$recompra = 'Buy-back:';
break;
default:
$recompra = null;
break;
}
return $recompra;
}
public function getRecompraIndice(): ?string
{
if(!$this->getRecompra()) return null;
$recompra = number_format($this->getRecompra(), 2, ',');
switch ($this->getVenta()->getOperacion()->getIdioma())
{
case IdiomaEnum::IDIOMA_ES:
$indice = "Sí, $recompra%";
break;
case IdiomaEnum::IDIOMA_EN:
$indice = "Yes, $recompra%";
break;
default:
$indice = null;
break;
}
return $indice;
}
public function getRecompraFechaStr(): ?string
{
if(!$this->getRecompraFecha()) return null;
switch ($this->getVenta()->getOperacion()->getIdioma())
{
case IdiomaEnum::IDIOMA_ES:
$recompraFechaStr = 'Activa hasta: ';
break;
case IdiomaEnum::IDIOMA_EN:
$recompraFechaStr = 'Term: ';
break;
default:
$recompraFechaStr = null;
break;
}
return $recompraFechaStr;
}
public function getRecompraFecha(): ?DateTimeInterface
{
return $this->getGarantiaFecha();
}
}