src/Entity/Compra.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JMS\Serializer\Annotation as JMS;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. /**
  9.  * @ORM\Table(name="compra")
  10.  * @ORM\Entity(repositoryClass="App\Repository\CompraRepository")
  11.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  12.  */
  13. class Compra
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\Column(type="bigint", options={"unsigned":true})
  18.      * @ORM\GeneratedValue(strategy="AUTO")
  19.      */
  20.     protected $id;
  21.     /**
  22.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  23.      */
  24.     protected $deletedAt;
  25.     /**
  26.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  27.      * @Gedmo\Timestampable(on="update")
  28.      */
  29.     protected $updatedAt;
  30.     /**
  31.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  32.      * @Gedmo\Timestampable(on="create")
  33.      */
  34.     protected $createdAt;
  35.     /**
  36.      * @ORM\OneToOne(targetEntity="App\Entity\Operacion", mappedBy="compra")
  37.      */
  38.     protected $operacion;
  39.     /**
  40.      * @ORM\OneToMany(
  41.      *     targetEntity=\App\Entity\DetalleCompra::class,
  42.      *     mappedBy="compra",
  43.      *     orphanRemoval=true,
  44.      *     cascade={"persist","remove"}
  45.      * )
  46.      * @JMS\Type("ArrayCollection<App\Entity\DetalleCompra>")
  47.      * @JMS\Groups({
  48.      *      "api_v1_operacion_show_serialize",
  49.      *  })
  50.      */
  51.     private $detalle;
  52.     public function __construct()
  53.     {
  54.         $this->detalle = new ArrayCollection();
  55.     }
  56.     public function __toString(): string
  57.     {
  58.         return $this->getOperacion()?->getIDperseo() ?? '---';
  59.     }
  60.     public function getId(): ?string
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getDeletedAt(): ?\DateTimeInterface
  65.     {
  66.         return $this->deletedAt;
  67.     }
  68.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  69.     {
  70.         $this->deletedAt $deletedAt;
  71.         return $this;
  72.     }
  73.     public function getUpdatedAt(): ?\DateTimeInterface
  74.     {
  75.         return $this->updatedAt;
  76.     }
  77.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  78.     {
  79.         $this->updatedAt $updatedAt;
  80.         return $this;
  81.     }
  82.     public function getCreatedAt(): ?\DateTimeInterface
  83.     {
  84.         return $this->createdAt;
  85.     }
  86.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  87.     {
  88.         $this->createdAt $createdAt;
  89.         return $this;
  90.     }
  91.     public function getOperacion(): ?Operacion
  92.     {
  93.         return $this->operacion;
  94.     }
  95.     public function setOperacion(?Operacion $operacion): self
  96.     {
  97.         // unset the owning side of the relation if necessary
  98.         if ($operacion === null && $this->operacion !== null) {
  99.             $this->operacion->setCompra(null);
  100.         }
  101.         // set the owning side of the relation if necessary
  102.         if ($operacion !== null && $operacion->getCompra() !== $this) {
  103.             $operacion->setCompra($this);
  104.         }
  105.         $this->operacion $operacion;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @return Collection|DetalleCompra[]
  110.      */
  111.     public function getDetalle(): Collection
  112.     {
  113.         return $this->detalle;
  114.     }
  115.     public function addDetalle(DetalleCompra $detalle): self
  116.     {
  117.         if (!$this->detalle->contains($detalle)) {
  118.             $this->detalle[] = $detalle;
  119.             $detalle->setCompra($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeDetalle(DetalleCompra $detalle): self
  124.     {
  125.         if ($this->detalle->removeElement($detalle)) {
  126.             // set the owning side to null (unless already changed)
  127.             if ($detalle->getCompra() === $this) {
  128.                 $detalle->setCompra(null);
  129.             }
  130.         }
  131.         return $this;
  132.     }
  133. }