src/Entity/DetalleCompra.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\TipoOperacionEnum;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\DetalleCompraRepository")
  10.  * @ORM\Table(name="detalle_compra")
  11.  * @ORM\EntityListeners({
  12.  *     "App\EntityListener\DetalleCompra\ControlRelojesOperacionListener",
  13.  *     "App\EntityListener\DetalleCompra\CrearAccionEstadoGestionCanceladaListener"
  14.  * })
  15.  */
  16. class DetalleCompra extends DetalleOperacion
  17. {
  18.     /**
  19.      * @ORM\Column(type="float", nullable=true, name="precio_pagar", precision=2, options={"default":"0.0"})
  20.      */
  21.     protected $precioPagar;
  22.     /**
  23.      * @ORM\Column(type="float", nullable=true, name="coste_importacion_iva", precision=2)
  24.      */
  25.     private $costeImportacionIva;
  26.     /**
  27.      * @ORM\Column(type="float", nullable=true, name="coste_importacion_otros", precision=2)
  28.      */
  29.     private $costeImportacionOtros;
  30.     /**
  31.      * @ORM\Column(
  32.      *     type="datetime",
  33.      *     nullable=true,
  34.      *     name="fecha_verificacion",
  35.      *     options={"comment":"Será la fecha del estado de recepción en promoción, que se crea automáticamente cuando está en confirmada"}
  36.      * )
  37.      */
  38.     private $fechaVerificacion;
  39.     /**
  40.      * @ORM\Column(
  41.      *     type="datetime",
  42.      *     nullable=true,
  43.      *     name="fecha_cancelacion",
  44.      *     options={"comment":"Será la fecha del estado de cancelada en promoción, que se crea automáticamente cuando se cancela el reloj"}
  45.      * )
  46.      */
  47.     private $fechaCancelacion;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=\App\Entity\Compra::class, inversedBy="detalle")
  50.      * @ORM\JoinColumn(name="compra_id", referencedColumnName="id")
  51.      */
  52.     protected $compra;
  53.     /*
  54.      * @ORM\OneToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="detalleCompra")
  55.      * @ORM\JoinColumn(name="reloj_compra_id", referencedColumnName="id", unique=true)
  56.      */
  57.     /**
  58.      * @ORM\JoinColumn(name="reloj_compra_id", referencedColumnName="id")
  59.      * @ORM\ManyToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="detalleCompra")
  60.      */
  61.     private $reloj;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity=\App\Entity\Reloj::class, inversedBy="relojesDerivadosDetalleCompra")
  64.      * @ORM\JoinColumn(name="reloj_base_id", referencedColumnName="id")
  65.      */
  66.     private $relojBase;
  67.     /**
  68.      * @ORM\JoinColumn(name="valoracion_reloj_id", referencedColumnName="id", unique=true)
  69.      * @ORM\OneToOne(targetEntity=\App\Entity\ValoracionesRelojesSinStock::class, inversedBy="detalleCompra")
  70.      */
  71.     private $valoracionReloj;
  72.     /*public function __toString(): string
  73.     {
  74.         return $this->getCompra()->__toString() . ' - ' . $this->getRelojMarca() . ' - ' .  $this->getRelojModelo1() . ' - ' .  $this->getRelojRef1() ?? '---';
  75.     }*/
  76.     public function __clone(): void
  77.     {
  78.         $this->setCompra(null);
  79.         $this->setActividad(null);
  80.         $this->setFechaVerificacion(null);
  81.         $this->setCreatedAt(new DateTime());
  82.         $this->setUpdatedAt(new DateTime());
  83.     }
  84.     public function getCompra(): ?Compra
  85.     {
  86.         return $this->compra;
  87.     }
  88.     public function setCompra(?Compra $compra): self
  89.     {
  90.         $this->compra $compra;
  91.         return $this;
  92.     }
  93.     public function getFechaVerificacion(): ?DateTimeInterface
  94.     {
  95.         return $this->fechaVerificacion;
  96.     }
  97.     public function setFechaVerificacion(?DateTimeInterface $fechaVerificacion): static
  98.     {
  99.         $this->fechaVerificacion $fechaVerificacion;
  100.         return $this;
  101.     }
  102.     public function getFechaCancelacion(): ?\DateTimeInterface
  103.     {
  104.         return $this->fechaCancelacion;
  105.     }
  106.     public function setFechaCancelacion(?\DateTimeInterface $fechaCancelacion): static
  107.     {
  108.         $this->fechaCancelacion $fechaCancelacion;
  109.         return $this;
  110.     }
  111.     public function getReloj(): ?Reloj
  112.     {
  113.         return $this->reloj;
  114.     }
  115.     public function setReloj(?Reloj $reloj): static
  116.     {
  117.         $this->reloj $reloj;
  118.         return $this;
  119.     }
  120.     public function getPrecioPagar(): ?float
  121.     {
  122.         return $this->precioPagar;
  123.     }
  124.     public function setPrecioPagar(?float $precioPagar): static
  125.     {
  126.         $this->precioPagar $precioPagar;
  127.         return $this;
  128.     }
  129.     public function getValoracionReloj(): ?ValoracionesRelojesSinStock
  130.     {
  131.         return $this->valoracionReloj;
  132.     }
  133.     public function setValoracionReloj(?ValoracionesRelojesSinStock $valoracionReloj): static
  134.     {
  135.         $this->valoracionReloj $valoracionReloj;
  136.         return $this;
  137.     }
  138.     public function getRelojBase(): ?Reloj
  139.     {
  140.         return $this->relojBase;
  141.     }
  142.     public function setRelojBase(?Reloj $relojBase): static
  143.     {
  144.         $this->relojBase $relojBase;
  145.         return $this;
  146.     }
  147.     public function getRelojGestion(): ?Reloj
  148.     {
  149.         if (!$relojBase $this->getRelojBase()) return null;
  150.         if(!$operacionGestion $relojBase->getOperacionGestion()) return null;
  151.         $cancelRelojBase $operacionGestion
  152.             ->getCompra()
  153.             ->getDetalle()
  154.             ->findFirst(
  155.                 fn($key$detalle) => $detalle->getReloj()?->getId() === $relojBase->getId()
  156.             )
  157.             ?->getFechaCancelacion();
  158.         return (!$cancelRelojBase && !$relojBase->getFechaVenta() && !$relojBase->getFechaCompra()) ? $relojBase null;
  159.     }
  160.     public function getFechaVerificacionRelojGestion(): ?DateTimeInterface
  161.     {
  162.         if (!$relojBase $this->getRelojBase()) return null;
  163.         if(!$operacionGestion $relojBase->getOperacionGestion()) return null;
  164.         $detalleRelojBase $operacionGestion
  165.             ->getCompra()
  166.             ->getDetalle()
  167.             ->findFirst(
  168.                 fn($key$detalle) => $detalle->getReloj()?->getId() === $relojBase->getId()
  169.             )
  170.         ;
  171.         $cancelRelojBase $detalleRelojBase?->getFechaCancelacion();
  172.         return (!$cancelRelojBase && !$relojBase->getFechaVenta() && !$relojBase->getFechaCompra()) ? $detalleRelojBase->getFechaVerificacion() : null;
  173.     }
  174.     public function getCosteImportacionIva(): ?float
  175.     {
  176.         return $this->costeImportacionIva;
  177.     }
  178.     public function setCosteImportacionIva(?float $costeImportacionIva): static
  179.     {
  180.         $this->costeImportacionIva $costeImportacionIva;
  181.         return $this;
  182.     }
  183.     public function getCosteImportacionOtros(): ?float
  184.     {
  185.         return $this->costeImportacionOtros;
  186.     }
  187.     public function setCosteImportacionOtros(?float $costeImportacionOtros): static
  188.     {
  189.         $this->costeImportacionOtros $costeImportacionOtros;
  190.         return $this;
  191.     }
  192. }