src/Entity/DetalleVenta.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\IdiomaEnum;
  4. use App\Enum\TipoGarantiaEnum;
  5. use DateInterval;
  6. use DateTimeInterface;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as JMS;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\DetalleVentaRepository")
  12.  * @ORM\Table(name="detalle_venta")
  13.  * @ORM\EntityListeners({
  14.  *     "App\EntityListener\DetalleVenta\CrearAccionEnviadoListener",
  15.  *     "App\EntityListener\DetalleVenta\ControlRelojesOperacionListener"
  16.  * })
  17.  */
  18. class DetalleVenta extends DetalleOperacion
  19. {
  20.     /**
  21.      * @ORM\Column(
  22.      *     type="float",
  23.      *     nullable=true,
  24.      *     precision=2,
  25.      *     name="precio_coste_total",
  26.      *     options={"default":"0.00","comment":"Coste del reloj + costes reparación, servicios u otros añadidos en PROMOCION"}
  27.      * )
  28.      */
  29.     protected $precioCosteTotal;
  30.     /**
  31.      * @ORM\Column(type="float", nullable=true, precision=2, name="precio_venta", options={"default":"0.00","unsigned":true})
  32.      */
  33.     protected $precioVenta;
  34.     /**
  35.      * @ORM\Column(type="float", nullable=true, precision=2, name="margen_beneficio", options={"default":"0.00","comment":"%"})
  36.      * @JMS\Groups({
  37.      *      "api_v1_operacion_show_serialize"
  38.      *  })
  39.      */
  40.     protected $margenBeneficio;
  41.     /**
  42.      *  Ajuste sobre el precio final del reloj.
  43.      *  Puede ser positivo para incrementar el precio o negativo para reducirlo.
  44.      *  Sustituye al concepto anterior de descuento.
  45.      *
  46.      * @ORM\Column(type="float", nullable=true, precision=2, options={
  47.      *     "default":"0.00",
  48.      *     "comment": "Ajuste sobre el precio final del reloj. Positivo aumenta el precio y negativo lo disminuye."
  49.      * })
  50.      * @JMS\Groups({
  51.      *      "api_v1_operacion_show_serialize"
  52.      *  })
  53.      */
  54.     protected $descuento;
  55.     /**
  56.      * @ORM\Column(
  57.      *     type="datetime",
  58.      *     nullable=true,
  59.      *     name="fecha_envio",
  60.      *     options={"comment":"Cada vez que se modifica la fecha envío se crea un nuevo estado envio en promoción."}
  61.      * )
  62.      * @JMS\Groups({
  63.      *      "api_v1_operacion_show_serialize"
  64.      *  })
  65.      */
  66.     protected $fechaEnvio;
  67.     /**
  68.      * @ORM\Column(type="float", nullable=true, precision=2)
  69.      * @JMS\Groups({
  70.      *      "api_v1_operacion_show_serialize"
  71.      *  })
  72.      */
  73.     protected $recompra;
  74.     /**
  75.      * @ORM\Column(type="string", nullable=true)
  76.      * @JMS\Groups({
  77.      *      "api_v1_operacion_show_serialize"
  78.      *  })
  79.      */
  80.     protected $garantia;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity=\App\Entity\Venta::class, inversedBy="detalleVentas")
  83.      * @ORM\JoinColumn(name="venta_id", referencedColumnName="id")
  84.      */
  85.     protected $venta;
  86.     /*
  87.      * @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
  88.      * @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="detalleVenta")
  89.      */
  90. //    private $reloj;
  91.     /**
  92.      * @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="detalleVenta")
  93.      * @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
  94.      * @JMS\Type(Reloj::class)
  95.      * @JMS\Groups({
  96.      *     "api_v1_operacion_show_serialize"
  97.      * })
  98.      */
  99.     protected $reloj;
  100.     /*public function __toString(): string
  101.     {
  102.         return $this->getVenta()->__toString() . ' - ' . $this->getReloj() ?? '---';
  103.     }*/
  104.     public function getVenta(): ?Venta
  105.     {
  106.         return $this->venta;
  107.     }
  108.     public function setVenta(?Venta $venta): self
  109.     {
  110.         $this->venta $venta;
  111.         return $this;
  112.     }
  113.     public function getPrecioCosteTotal(): ?float
  114.     {
  115.         return $this->precioCosteTotal;
  116.     }
  117.     public function setPrecioCosteTotal(?float $precioCosteTotal): self
  118.     {
  119.         $this->precioCosteTotal $precioCosteTotal;
  120.         return $this;
  121.     }
  122.     public function getPrecioVenta(): ?float
  123.     {
  124.         return $this->precioVenta;
  125.     }
  126.     public function setPrecioVenta(?float $precioVenta): self
  127.     {
  128.         $this->precioVenta $precioVenta;
  129.         return $this;
  130.     }
  131.     public function getMargenBeneficio(): ?float
  132.     {
  133.         return $this->margenBeneficio;
  134.     }
  135.     public function setMargenBeneficio(?float $margenBeneficio): self
  136.     {
  137.         $this->margenBeneficio $margenBeneficio;
  138.         return $this;
  139.     }
  140.     public function getDescuento(): ?float
  141.     {
  142.         return $this->descuento;
  143.     }
  144.     public function setDescuento(?float $descuento): self
  145.     {
  146.         $this->descuento $descuento;
  147.         return $this;
  148.     }
  149.     public function getReloj(): ?Reloj
  150.     {
  151.         return $this->reloj;
  152.     }
  153.     public function setReloj(?Reloj $reloj): static
  154.     {
  155.         $this->reloj $reloj;
  156.         return $this;
  157.     }
  158.     public function getFechaEnvio(): ?DateTimeInterface
  159.     {
  160.         return $this->fechaEnvio;
  161.     }
  162.     public function setFechaEnvio(?DateTimeInterface $fechaEnvio): static
  163.     {
  164.         $this->fechaEnvio $fechaEnvio;
  165.         return $this;
  166.     }
  167.     public function getRecompra(): ?float
  168.     {
  169.         return $this->recompra;
  170.     }
  171.     public function setRecompra(?float $recompra): static
  172.     {
  173.         $this->recompra $recompra;
  174.         return $this;
  175.     }
  176.     public function getGarantia(): ?string
  177.     {
  178.         return $this->garantia;
  179.     }
  180.     public function setGarantia(?string $garantia): static
  181.     {
  182.         $this->garantia $garantia;
  183.         return $this;
  184.     }
  185.     public function getGarantiaStr(): ?string
  186.     {
  187.         switch ($this->getVenta()->getOperacion()->getIdioma())
  188.         {
  189.             case IdiomaEnum::IDIOMA_ES:
  190.                 $garantia $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN null 'Sobre el calibre';
  191.                 break;
  192.             case IdiomaEnum::IDIOMA_EN:
  193.                 $garantia $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN null 'Over the movement';
  194.                 break;
  195.             default:
  196.                 $garantia null;
  197.                 break;
  198.         }
  199.         return $garantia;
  200.     }
  201.     public function getGarantiaFecha(): ?DateTimeInterface
  202.     {
  203.         switch ($this->getGarantia())
  204.         {
  205.             case TipoGarantiaEnum::GARANTIA_6:
  206.                 $fechaGarantia $this->getFechaEnvio()->add(new DateInterval('P6M'));
  207.                 break;
  208.             case TipoGarantiaEnum::GARANTIA_12:
  209.                 $fechaGarantia $this->getFechaEnvio()->add(new DateInterval('P12M'));
  210.                 break;
  211.             default:
  212.                 $fechaGarantia null;
  213.                 break;
  214.         }
  215.         return $fechaGarantia;
  216.     }
  217.     public function getRecompraStr(): ?string
  218.     {
  219.         if(!$this->getGarantiaStr() || !$this->getRecompraIndice()) return null;
  220.         switch ($this->getVenta()->getOperacion()->getIdioma())
  221.         {
  222.             case IdiomaEnum::IDIOMA_ES:
  223.                 $recompra 'Recompra:';
  224.                 break;
  225.             case IdiomaEnum::IDIOMA_EN:
  226.                 $recompra 'Buy-back:';
  227.                 break;
  228.             default:
  229.                 $recompra null;
  230.                 break;
  231.         }
  232.         return $recompra;
  233.     }
  234.     public function getRecompraIndice(): ?string
  235.     {
  236.         if(!$this->getRecompra() || $this->getRecompra() !== 0.0) return null;
  237.         $recompra number_format($this->getRecompra(), 2',');
  238.         switch ($this->getVenta()->getOperacion()->getIdioma())
  239.         {
  240.             case IdiomaEnum::IDIOMA_ES:
  241.                 $indice "Sí, $recompra%";
  242.                 break;
  243.             case IdiomaEnum::IDIOMA_EN:
  244.                 $indice "Yes, $recompra%";
  245.                 break;
  246.             default:
  247.                 $indice null;
  248.                 break;
  249.         }
  250.         return $indice;
  251.     }
  252.     public function getRecompraFechaStr(): ?string
  253.     {
  254.         if(!$this->getRecompraFecha() || !$this->getRecompraIndice()) return null;
  255.         switch ($this->getVenta()->getOperacion()->getIdioma())
  256.         {
  257.             case IdiomaEnum::IDIOMA_ES:
  258.                 $recompraFechaStr 'Activa hasta: ';
  259.                 break;
  260.             case IdiomaEnum::IDIOMA_EN:
  261.                 $recompraFechaStr 'Term: ';
  262.                 break;
  263.             default:
  264.                 $recompraFechaStr null;
  265.                 break;
  266.         }
  267.         return $recompraFechaStr;
  268.     }
  269.     public function getRecompraFecha(): ?DateTimeInterface
  270.     {
  271.         return $this->getRecompraIndice() ? $this->getGarantiaFecha() : null;
  272.     }
  273. }