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