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.      * @ORM\Column(type="float", nullable=true, precision=2, options={"default":"0.00"})
  43.      * @JMS\Groups({
  44.      *      "api_v1_operacion_show_serialize"
  45.      *  })
  46.      */
  47.     protected $descuento;
  48.     /**
  49.      * @ORM\Column(
  50.      *     type="datetime",
  51.      *     nullable=true,
  52.      *     name="fecha_envio",
  53.      *     options={"comment":"Cada vez que se modifica la fecha envío se crea un nuevo estado envio en promoción."}
  54.      * )
  55.      * @JMS\Groups({
  56.      *      "api_v1_operacion_show_serialize"
  57.      *  })
  58.      */
  59.     protected $fechaEnvio;
  60.     /**
  61.      * @ORM\Column(type="float", nullable=true, precision=2)
  62.      * @JMS\Groups({
  63.      *      "api_v1_operacion_show_serialize"
  64.      *  })
  65.      */
  66.     protected $recompra;
  67.     /**
  68.      * @ORM\Column(type="string", nullable=true)
  69.      * @JMS\Groups({
  70.      *      "api_v1_operacion_show_serialize"
  71.      *  })
  72.      */
  73.     protected $garantia;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=\App\Entity\Venta::class, inversedBy="detalleVentas")
  76.      * @ORM\JoinColumn(name="venta_id", referencedColumnName="id")
  77.      */
  78.     protected $venta;
  79.     /*
  80.      * @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
  81.      * @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="detalleVenta")
  82.      */
  83. //    private $reloj;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="detalleVenta")
  86.      * @ORM\JoinColumn(name="reloj_venta_id", referencedColumnName="id")
  87.      * @JMS\Type(Reloj::class)
  88.      * @JMS\Groups({
  89.      *     "api_v1_operacion_show_serialize"
  90.      * })
  91.      */
  92.     protected $reloj;
  93.     /*public function __toString(): string
  94.     {
  95.         return $this->getVenta()->__toString() . ' - ' . $this->getReloj() ?? '---';
  96.     }*/
  97.     public function getVenta(): ?Venta
  98.     {
  99.         return $this->venta;
  100.     }
  101.     public function setVenta(?Venta $venta): self
  102.     {
  103.         $this->venta $venta;
  104.         return $this;
  105.     }
  106.     public function getPrecioCosteTotal(): ?float
  107.     {
  108.         return $this->precioCosteTotal;
  109.     }
  110.     public function setPrecioCosteTotal(?float $precioCosteTotal): self
  111.     {
  112.         $this->precioCosteTotal $precioCosteTotal;
  113.         return $this;
  114.     }
  115.     public function getPrecioVenta(): ?float
  116.     {
  117.         return $this->precioVenta;
  118.     }
  119.     public function setPrecioVenta(?float $precioVenta): self
  120.     {
  121.         $this->precioVenta $precioVenta;
  122.         return $this;
  123.     }
  124.     public function getMargenBeneficio(): ?float
  125.     {
  126.         return $this->margenBeneficio;
  127.     }
  128.     public function setMargenBeneficio(?float $margenBeneficio): self
  129.     {
  130.         $this->margenBeneficio $margenBeneficio;
  131.         return $this;
  132.     }
  133.     public function getDescuento(): ?float
  134.     {
  135.         return $this->descuento;
  136.     }
  137.     public function setDescuento(?float $descuento): self
  138.     {
  139.         $this->descuento $descuento;
  140.         return $this;
  141.     }
  142.     public function getReloj(): ?Reloj
  143.     {
  144.         return $this->reloj;
  145.     }
  146.     public function setReloj(?Reloj $reloj): static
  147.     {
  148.         $this->reloj $reloj;
  149.         return $this;
  150.     }
  151.     public function getFechaEnvio(): ?DateTimeInterface
  152.     {
  153.         return $this->fechaEnvio;
  154.     }
  155.     public function setFechaEnvio(?DateTimeInterface $fechaEnvio): static
  156.     {
  157.         $this->fechaEnvio $fechaEnvio;
  158.         return $this;
  159.     }
  160.     public function getRecompra(): ?float
  161.     {
  162.         return $this->recompra;
  163.     }
  164.     public function setRecompra(?float $recompra): static
  165.     {
  166.         $this->recompra $recompra;
  167.         return $this;
  168.     }
  169.     public function getGarantia(): ?string
  170.     {
  171.         return $this->garantia;
  172.     }
  173.     public function setGarantia(?string $garantia): static
  174.     {
  175.         $this->garantia $garantia;
  176.         return $this;
  177.     }
  178.     public function getGarantiaStr(): ?string
  179.     {
  180.         switch ($this->getVenta()->getOperacion()->getIdioma())
  181.         {
  182.             case IdiomaEnum::IDIOMA_ES:
  183.                 $garantia $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN null 'Sobre el calibre';
  184.                 break;
  185.             case IdiomaEnum::IDIOMA_EN:
  186.                 $garantia $this->getGarantia() === TipoGarantiaEnum::GARANTIA_SIN null 'Over the movement';
  187.                 break;
  188.             default:
  189.                 $garantia null;
  190.                 break;
  191.         }
  192.         return $garantia;
  193.     }
  194.     public function getGarantiaFecha(): ?DateTimeInterface
  195.     {
  196.         switch ($this->getGarantia())
  197.         {
  198.             case TipoGarantiaEnum::GARANTIA_6:
  199.                 $fechaGarantia $this->getFechaEnvio()->add(new DateInterval('P6M'));
  200.                 break;
  201.             case TipoGarantiaEnum::GARANTIA_12:
  202.                 $fechaGarantia $this->getFechaEnvio()->add(new DateInterval('P12M'));
  203.                 break;
  204.             default:
  205.                 $fechaGarantia null;
  206.                 break;
  207.         }
  208.         return $fechaGarantia;
  209.     }
  210.     public function getRecompraStr(): ?string
  211.     {
  212.         if(!$this->getGarantiaStr() || !$this->getRecompraIndice()) return null;
  213.         switch ($this->getVenta()->getOperacion()->getIdioma())
  214.         {
  215.             case IdiomaEnum::IDIOMA_ES:
  216.                 $recompra 'Recompra:';
  217.                 break;
  218.             case IdiomaEnum::IDIOMA_EN:
  219.                 $recompra 'Buy-back:';
  220.                 break;
  221.             default:
  222.                 $recompra null;
  223.                 break;
  224.         }
  225.         return $recompra;
  226.     }
  227.     public function getRecompraIndice(): ?string
  228.     {
  229.         if(!$this->getRecompra() || $this->getRecompra() !== 0.0) return null;
  230.         $recompra number_format($this->getRecompra(), 2',');
  231.         switch ($this->getVenta()->getOperacion()->getIdioma())
  232.         {
  233.             case IdiomaEnum::IDIOMA_ES:
  234.                 $indice "Sí, $recompra%";
  235.                 break;
  236.             case IdiomaEnum::IDIOMA_EN:
  237.                 $indice "Yes, $recompra%";
  238.                 break;
  239.             default:
  240.                 $indice null;
  241.                 break;
  242.         }
  243.         return $indice;
  244.     }
  245.     public function getRecompraFechaStr(): ?string
  246.     {
  247.         if(!$this->getRecompraFecha() || !$this->getRecompraIndice()) return null;
  248.         switch ($this->getVenta()->getOperacion()->getIdioma())
  249.         {
  250.             case IdiomaEnum::IDIOMA_ES:
  251.                 $recompraFechaStr 'Activa hasta: ';
  252.                 break;
  253.             case IdiomaEnum::IDIOMA_EN:
  254.                 $recompraFechaStr 'Term: ';
  255.                 break;
  256.             default:
  257.                 $recompraFechaStr null;
  258.                 break;
  259.         }
  260.         return $recompraFechaStr;
  261.     }
  262.     public function getRecompraFecha(): ?DateTimeInterface
  263.     {
  264.         return $this->getRecompraIndice() ? $this->getGarantiaFecha() : null;
  265.     }
  266. }