src/Entity/Orden.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrdenRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=OrdenRepository::class)
  9. */
  10. class Orden
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="datetime", nullable=true)
  20. */
  21. private $createdAt;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="ordenes")
  24. */
  25. private $user;
  26. /**
  27. * @ORM\OneToMany(targetEntity=OrdenItem::class, mappedBy="orden", cascade={"persist"})
  28. */
  29. private $ordenItems;
  30. /**
  31. * @ORM\Column(type="boolean", options={"default": 0})
  32. */
  33. private $isCompleted;
  34. /**
  35. * @ORM\Column(type="float", nullable=true)
  36. */
  37. private $subTotal;
  38. /**
  39. * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="orden", cascade={"persist"})
  40. */
  41. private $transactions;
  42. /**
  43. * @ORM\Column(type="float", nullable=true)
  44. */
  45. private $taxes;
  46. /**
  47. * @ORM\Column(type="float", options={"default": 0})
  48. */
  49. private $ordenTotal;
  50. public function __toString()
  51. {
  52. return $this->getId() . ': ' . $this->getUser();
  53. }
  54. /**
  55. * @ORM\Column(type="float", options={"default": 0})
  56. */
  57. private $balance;
  58. /**
  59. * @ORM\Column(type="boolean", options={"default": 0})
  60. */
  61. private $hasSubsCreated;
  62. /**
  63. * @ORM\ManyToOne(targetEntity=PromoCode::class,cascade={"persist"})
  64. */
  65. private $promoCode;
  66. /**
  67. * @ORM\ManyToOne(targetEntity=OrdenOrigen::class,cascade={"persist"})
  68. */
  69. private $ordenOrigen;
  70. /**
  71. * @ORM\Column(type="string", length=255, nullable=true)
  72. */
  73. private $paymentIntent;
  74. /**
  75. * @ORM\Column(type="string", length=500, nullable=true)
  76. */
  77. private $receiptUrl;
  78. /**
  79. * @ORM\Column(type="string", length=255, nullable=true)
  80. */
  81. private $currentPlace;
  82. public function __construct()
  83. {
  84. $this->ordenItems = new ArrayCollection();
  85. if(!$this->currentPlace) $this->setCurrentPlace('Abierta');
  86. if(!$this->createdAt) $this->createdAt = new \DateTime();
  87. $this->transactions = new ArrayCollection();
  88. if(!$this->balance) $this->balance = 0;
  89. if(!$this->hasSubsCreated) $this->hasSubsCreated = 0;
  90. if(!$this->isCompleted) $this->isCompleted = 0;
  91. }
  92. public function getId(): ?int
  93. {
  94. return $this->id;
  95. }
  96. public function getCreatedAt(): ?\DateTimeInterface
  97. {
  98. return $this->createdAt;
  99. }
  100. public function setCreatedAt(?\DateTimeInterface $createdAt): self
  101. {
  102. $this->createdAt = $createdAt;
  103. return $this;
  104. }
  105. public function getUser(): ?User
  106. {
  107. return $this->user;
  108. }
  109. public function setUser(?User $user): self
  110. {
  111. $this->user = $user;
  112. return $this;
  113. }
  114. /**
  115. * @return Collection<int, OrdenItem>
  116. */
  117. public function getOrdenItems(): Collection
  118. {
  119. return $this->ordenItems;
  120. }
  121. public function addOrdenItem(OrdenItem $ordenItem): self
  122. {
  123. if (!$this->ordenItems->contains($ordenItem)) {
  124. $this->ordenItems[] = $ordenItem;
  125. $ordenItem->setOrden($this);
  126. }
  127. return $this;
  128. }
  129. public function removeOrdenItem(OrdenItem $ordenItem): self
  130. {
  131. if ($this->ordenItems->removeElement($ordenItem)) {
  132. // set the owning side to null (unless already changed)
  133. if ($ordenItem->getOrden() === $this) {
  134. $ordenItem->setOrden(null);
  135. }
  136. }
  137. return $this;
  138. }
  139. public function getIsCompleted(): ?bool
  140. {
  141. return $this->isCompleted;
  142. }
  143. public function setIsCompleted(bool $isCompleted): self
  144. {
  145. $this->isCompleted = $isCompleted;
  146. return $this;
  147. }
  148. public function getSubTotal(): ?float
  149. {
  150. return $this->subTotal;
  151. }
  152. public function setSubTotal(?float $subTotal): self
  153. {
  154. $this->subTotal = $subTotal;
  155. return $this;
  156. }
  157. /**
  158. * @return Collection<int, Transaction>
  159. */
  160. public function getTransactions(): Collection
  161. {
  162. return $this->transactions;
  163. }
  164. public function addTransaction(Transaction $transaction): self
  165. {
  166. if (!$this->transactions->contains($transaction)) {
  167. $this->transactions[] = $transaction;
  168. $transaction->setOrden($this);
  169. }
  170. return $this;
  171. }
  172. public function removeTransaction(Transaction $transaction): self
  173. {
  174. if ($this->transactions->removeElement($transaction)) {
  175. // set the owning side to null (unless already changed)
  176. if ($transaction->getOrden() === $this) {
  177. $transaction->setOrden(null);
  178. }
  179. }
  180. return $this;
  181. }
  182. public function getTaxes(): ?float
  183. {
  184. return $this->taxes;
  185. }
  186. public function setTaxes(?float $taxes): self
  187. {
  188. $this->taxes = $taxes;
  189. return $this;
  190. }
  191. public function getOrdenTotal(): ?float
  192. {
  193. return $this->ordenTotal;
  194. }
  195. public function setOrdenTotal(?float $ordenTotal): self
  196. {
  197. $this->ordenTotal = number_format($ordenTotal, 2);
  198. return $this;
  199. }
  200. public function calcOrdenTotal(): self
  201. {
  202. $this->ordenTotal = number_format($this->subTotal + $this->taxes, 2);
  203. return $this;
  204. }
  205. public function getBalance(): ?float
  206. {
  207. return $this->balance;
  208. }
  209. public function setBalance(?float $balance): self
  210. {
  211. $this->balance = number_format($balance, 2);
  212. return $this;
  213. }
  214. public function isHasSubsCreated(): ?bool
  215. {
  216. return $this->hasSubsCreated;
  217. }
  218. public function setHasSubsCreated(bool $hasSubsCreated): self
  219. {
  220. $this->hasSubsCreated = $hasSubsCreated;
  221. return $this;
  222. }
  223. public function getPromoCode(): ?PromoCode
  224. {
  225. return $this->promoCode;
  226. }
  227. public function setPromoCode(?PromoCode $promoCode): self
  228. {
  229. $this->promoCode = $promoCode;
  230. return $this;
  231. }
  232. public function getOrdenOrigen(): ?OrdenOrigen
  233. {
  234. return $this->ordenOrigen;
  235. }
  236. public function setOrdenOrigen(?OrdenOrigen $ordenOrigen): self
  237. {
  238. $this->ordenOrigen = $ordenOrigen;
  239. return $this;
  240. }
  241. public function getPaymentIntent(): ?string
  242. {
  243. return $this->paymentIntent;
  244. }
  245. public function setPaymentIntent(string $paymentIntent): self
  246. {
  247. $this->paymentIntent = $paymentIntent;
  248. return $this;
  249. }
  250. public function getReceiptUrl(): ?string
  251. {
  252. return $this->receiptUrl;
  253. }
  254. public function setReceiptUrl(?string $receiptUrl): self
  255. {
  256. $this->receiptUrl = $receiptUrl;
  257. return $this;
  258. }
  259. public function getCurrentPlace(): ?string
  260. {
  261. return $this->currentPlace;
  262. }
  263. public function setCurrentPlace(?string $currentPlace): self
  264. {
  265. $this->currentPlace = $currentPlace;
  266. return $this;
  267. }
  268. }