src/Entity/ValoracionesRelojes.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as JMS;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\ValoracionesRelojesRepository")
  11.  * @ORM\Table(name="valoraciones_relojes",
  12.  *     indexes={
  13.  *         @ORM\Index(name="idx_vrelojes_type_deleted", columns={"type", "deleted_at", "valoracion_id"})
  14.  *     }
  15.  * )
  16.  * @ORM\InheritanceType("SINGLE_TABLE")
  17.  * @ORM\DiscriminatorColumn(name="type", type="string")
  18.  * @ORM\DiscriminatorMap({"stock":"App\Entity\ValoracionesRelojesStock","sinstock":"App\Entity\ValoracionesRelojesSinStock"})
  19.  * @ORM\EntityListeners({"App\EntityListener\ValoracionesRelojes\CalcularIDPerseoListener"})
  20.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  21.  * @JMS\Discriminator(
  22.  *      field = "type",
  23.  *      map = {
  24.  *          "stock" = "App\Entity\ValoracionesRelojesStock",
  25.  *          "sinstock" = "App\Entity\ValoracionesRelojesSinStock"
  26.  *      }
  27.  *  )
  28.  */
  29. Abstract class ValoracionesRelojes
  30. {
  31.     /**
  32.      * @ORM\Id
  33.      * @ORM\Column(type="bigint")
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      * @JMS\Groups({
  36.      *     "api_v1_valoracion_serialize", "api_v1_valoracion_deserialize",
  37.      *     "api_v1_valoracionrelojcompra_deserialize",
  38.      *     "api_v1_valoracionrelojventa_deserialize"
  39.      * })
  40.      */
  41.     protected $id;
  42.     /**
  43.      * @ORM\Column(
  44.      *     type="string",
  45.      *     unique=true,
  46.      *     nullable=true,
  47.      *     name="id_perseo",
  48.      *     options={"comment":"Identificador de perseo único generado aleatoriamente combinación letras y números"}
  49.      * )
  50.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  51.      */
  52.     protected $IDperseo;
  53.     /**
  54.      * @ORM\Column(type="text", nullable=true, name="info_valoracion_compra", options={"default":NULL})
  55.      * @JMS\Groups({
  56.      *      "api_v1_valoracion_serialize",
  57.      *      "api_v1_valoracionrelojcompra_deserialize"
  58.      *  })
  59.      */
  60.     protected $infoValoracion;
  61.     /**
  62.      * @ORM\Column(type="boolean", nullable=true, name="is_precio_chrono24", options={"default":0})
  63.      */
  64.     protected $isPrecioChrono24;
  65.     /**
  66.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  67.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  68.      */
  69.     protected $deletedAt;
  70.     /**
  71.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  72.      * @Gedmo\Timestampable(on="update")
  73.      */
  74.     protected $updatedAt;
  75.     /**
  76.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  77.      * @Gedmo\Timestampable(on="create")
  78.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  79.      */
  80.     protected $createdAt;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=\App\Entity\ValoracionesRelojes::class, mappedBy="clone")
  83.      */
  84.     protected $clones;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity="App\Entity\Valoracion", inversedBy="valoracionesRelojes", cascade={"persist"})
  87.      * @ORM\JoinColumn(name="valoracion_id", referencedColumnName="id")
  88.      */
  89.     protected $valoracion;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="valoracionesRelojes", cascade={"persist"})
  92.      * @ORM\JoinColumn(name="reloj_id", referencedColumnName="id")
  93.      * @JMS\Type(Reloj::class)
  94.      * @JMS\Groups({
  95.      *      "api_v1_valoracion_serialize",
  96.      *      "api_v1_valoracionrelojventa_deserialize"
  97.      *  })
  98.      */
  99.     protected $reloj;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity=\App\Entity\ValoracionesRelojes::class, inversedBy="clones")
  102.      * @ORM\JoinColumn(name="clone_id", referencedColumnName="id")
  103.      */
  104.     protected $clone;
  105.     public function __construct()
  106.     {
  107.         $this->clones = new ArrayCollection();
  108.     }
  109.     public function __clone(): void
  110.     {
  111.         $this->setCreatedAt(new DateTime('now'));
  112.         $this->setUpdatedAt(new DateTime('now'));
  113.         if($this instanceof ValoracionesRelojesSinStock) {
  114.             $this->setRelojInventario(null);
  115.             $costes $this->getCostes();
  116.             foreach ($costes as $coste) {
  117.                 $costeClone = clone $coste;
  118.                 $this->addCoste($costeClone);
  119.             }
  120.             $referencias $this->getReferencias();
  121.             foreach ($referencias as $referencia) {
  122.                 $referenciaClone = clone $referencia;
  123.                 $this->addReferencia($referenciaClone);
  124.             }
  125.         }
  126.     }
  127.     public function __toString(): string
  128.     {
  129.         return $this->getId()??'---';
  130.     }
  131.     public function getId(): ?int
  132.     {
  133.         return $this->id;
  134.     }
  135.     public function getDeletedAt(): ?\DateTimeInterface
  136.     {
  137.         return $this->deletedAt;
  138.     }
  139.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  140.     {
  141.         $this->deletedAt $deletedAt;
  142.         return $this;
  143.     }
  144.     public function getUpdatedAt(): ?\DateTimeInterface
  145.     {
  146.         return $this->updatedAt;
  147.     }
  148.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  149.     {
  150.         $this->updatedAt $updatedAt;
  151.         return $this;
  152.     }
  153.     public function getCreatedAt(): ?\DateTimeInterface
  154.     {
  155.         return $this->createdAt;
  156.     }
  157.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  158.     {
  159.         $this->createdAt $createdAt;
  160.         return $this;
  161.     }
  162.     public function getValoracion(): ?Valoracion
  163.     {
  164.         return $this->valoracion;
  165.     }
  166.     public function setValoracion(?Valoracion $valoracion): self
  167.     {
  168.         $this->valoracion $valoracion;
  169.         return $this;
  170.     }
  171.     public function getReloj(): ?Reloj
  172.     {
  173.         return $this->reloj;
  174.     }
  175.     public function setReloj(?Reloj $reloj): self
  176.     {
  177.         $this->reloj $reloj;
  178.         return $this;
  179.     }
  180.     public function getInfoValoracion(): ?string
  181.     {
  182.         return $this->infoValoracion;
  183.     }
  184.     public function setInfoValoracion(?string $infoValoracion): self
  185.     {
  186.         $this->infoValoracion $infoValoracion;
  187.         return $this;
  188.     }
  189.     public function getIDperseo(): ?string
  190.     {
  191.         return $this->IDperseo;
  192.     }
  193.     public function setIDperseo(string $IDperseo): self
  194.     {
  195.         $this->IDperseo $IDperseo;
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return Collection|Valoracion[]
  200.      */
  201.     public function getClones(): Collection
  202.     {
  203.         return $this->clones;
  204.     }
  205.     public function addClone(Valoracion $clone): self
  206.     {
  207.         if (!$this->clones->contains($clone)) {
  208.             $this->clones[] = $clone;
  209.             $clone->setClone($this);
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeClone(Valoracion $clone): self
  214.     {
  215.         if ($this->clones->removeElement($clone)) {
  216.             // set the owning side to null (unless already changed)
  217.             if ($clone->getClone() === $this) {
  218.                 $clone->setClone(null);
  219.             }
  220.         }
  221.         return $this;
  222.     }
  223.     public function getClone(): ?self
  224.     {
  225.         return $this->clone;
  226.     }
  227.     public function setClone(?self $clone): self
  228.     {
  229.         $this->clone $clone;
  230.         return $this;
  231.     }
  232.     public function getRelojMarca(): ?Marca
  233.     {
  234.         if ($this instanceof ValoracionesRelojesSinStock) {
  235.             return $this->getRelojMarca();
  236.         }
  237.         if ($this instanceof ValoracionesRelojesStock) {
  238.             return $this->getReloj()?->getMarca();
  239.         }
  240.         return null;
  241.     }
  242.     public function getRelojModelo1(): ?string
  243.     {
  244.         if ($this instanceof ValoracionesRelojesSinStock) {
  245.             return $this->getRelojModelo1();
  246.         }
  247.         if ($this instanceof ValoracionesRelojesStock) {
  248.             return $this->getReloj()?->getModelo1();
  249.         }
  250.         return null;
  251.     }
  252.     public function getRelojRef1(): ?string
  253.     {
  254.         if ($this instanceof ValoracionesRelojesSinStock) {
  255.             return $this->getRelojRef1();
  256.         }
  257.         if ($this instanceof ValoracionesRelojesStock) {
  258.             return $this->getReloj()?->getRef1();
  259.         }
  260.         return null;
  261.     }
  262.     public function getMargenDeseado(): ?float
  263.     {
  264.         if ($this instanceof ValoracionesRelojesSinStock) {
  265.             return $this->getMargenDeseado();
  266.         }
  267.         if ($this instanceof ValoracionesRelojesStock) {
  268.             return $this->getReloj()?->getMargenDeseado();
  269.         }
  270.         return null;
  271.     }
  272.     public function getPrecioPagar(): ?float
  273.     {
  274.         if ($this instanceof ValoracionesRelojesSinStock) {
  275.             return $this->getprecioPagar();
  276.         }
  277.         if ($this instanceof ValoracionesRelojesStock) {
  278.             return $this->getReloj()?->getPrecioPagar();
  279.         }
  280.         return null;
  281.     }
  282. }