src/Entity/Invoice.php line 13

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