src/Entity/Invoice.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\InvoiceRepository;
  4. use DateTime;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * @ORM\Entity(repositoryClass=InvoiceRepository::class)
  11. */
  12. class Invoice
  13. {
  14. const TYPE_INVOICE = 'facture';
  15. const TYPE_CREDIT = 'avoir';
  16. const SEND_TO_CUSTOMER = 'invoice_send_to_customer';
  17. const SEND_TO_SPECIFIC = 'invoice_send_to_specific';
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * @ORM\Column(type="string", length=10)
  26. */
  27. private ?string $reference = null;
  28. /**
  29. * @ORM\Column(type="string", length=20)
  30. */
  31. private ?string $type = null;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. */
  35. private ?string $filePath = null;
  36. /**
  37. * @ORM\Column(type="datetime_immutable")
  38. */
  39. private ?DateTimeImmutable $createdAt = null;
  40. /**
  41. * @ORM\Column(type="datetime", nullable=true)
  42. */
  43. private ?DateTime $updatedAt = null;
  44. /**
  45. * @ORM\ManyToOne(targetEntity=Invoice::class, inversedBy="cancelledBy", cascade={"persist"})
  46. */
  47. private ?Invoice $cancels = null;
  48. /**
  49. * @ORM\OneToMany(targetEntity=Invoice::class, mappedBy="cancels", cascade={"persist"})
  50. */
  51. private Collection $cancelledBy;
  52. /**
  53. * @ORM\ManyToOne(targetEntity=SaleOrder::class, inversedBy="invoices")
  54. */
  55. private ?SaleOrder $saleOrder = null;
  56. /**
  57. * @ORM\ManyToMany(targetEntity=PointTransaction::class, inversedBy="invoices")
  58. */
  59. private Collection $transactionPoints;
  60. public function __construct()
  61. {
  62. $this->transactionPoints = new ArrayCollection();
  63. $this->cancelledBy = new ArrayCollection();
  64. }
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69. public function getReference(): ?string
  70. {
  71. return $this->reference;
  72. }
  73. public function setReference(string $reference): self
  74. {
  75. $this->reference = $reference;
  76. return $this;
  77. }
  78. public function getInvoiceNumber(): ?string
  79. {
  80. return strtoupper(substr($this->getType(), 0, 1)) . '-' . (str_pad($this->reference, 10, "0", STR_PAD_LEFT));
  81. }
  82. public function getType(): ?string
  83. {
  84. return $this->type;
  85. }
  86. public function setType(string $type): self
  87. {
  88. $this->type = $type;
  89. return $this;
  90. }
  91. public function getFilePath(): ?string
  92. {
  93. return $this->filePath;
  94. }
  95. public function setFilePath(?string $filePath): self
  96. {
  97. $this->filePath = $filePath;
  98. return $this;
  99. }
  100. public function getCreatedAt(): ?DateTimeImmutable
  101. {
  102. return $this->createdAt;
  103. }
  104. public function setCreatedAt(DateTimeImmutable $createdAt): self
  105. {
  106. $this->createdAt = $createdAt;
  107. return $this;
  108. }
  109. public function getUpdatedAt(): ?DateTime
  110. {
  111. return $this->updatedAt;
  112. }
  113. public function setUpdatedAt(?DateTime $updatedAt): self
  114. {
  115. $this->updatedAt = $updatedAt;
  116. return $this;
  117. }
  118. public function getCancels(): ?self
  119. {
  120. return $this->cancels;
  121. }
  122. public function setCancels(?self $cancels): self
  123. {
  124. $this->cancels = $cancels;
  125. return $this;
  126. }
  127. /**
  128. * @return Collection<int, Invoice>
  129. */
  130. public function getCancelledBy(): Collection
  131. {
  132. return $this->cancelledBy;
  133. }
  134. public function addCancelledBy(Invoice $invoice): self
  135. {
  136. if (!$this->cancelledBy->contains($invoice)) {
  137. $this->cancelledBy[] = $invoice;
  138. $invoice->setCancels($this);
  139. }
  140. return $this;
  141. }
  142. public function removeCancelledBy(Invoice $invoice): self
  143. {
  144. if ($this->cancelledBy->removeElement($invoice)) {
  145. if ($invoice->getCancels() === $this) {
  146. $invoice->setCancels(null);
  147. }
  148. }
  149. return $this;
  150. }
  151. public function getSaleOrder(): ?SaleOrder
  152. {
  153. return $this->saleOrder;
  154. }
  155. public function setSaleOrder(?SaleOrder $saleOrder): self
  156. {
  157. $this->saleOrder = $saleOrder;
  158. return $this;
  159. }
  160. /**
  161. * @return Collection<int, PointTransaction>
  162. */
  163. public function getPointTransactions(): Collection
  164. {
  165. return $this->transactionPoints;
  166. }
  167. public function addPointTransaction(PointTransaction $transactionPoint): self
  168. {
  169. if (!$this->transactionPoints->contains($transactionPoint)) {
  170. $this->transactionPoints[] = $transactionPoint;
  171. }
  172. return $this;
  173. }
  174. public function removePointTransaction(PointTransaction $transactionPoint): self
  175. {
  176. $this->transactionPoints->removeElement($transactionPoint);
  177. return $this;
  178. }
  179. }