src/Finance/Domain/Entity/CashPayment.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Finance\Domain\Entity;
  3. use App\Entity\Student;
  4. use App\Entity\SchoolYear;
  5. use App\Finance\Domain\Repository\CashPaymentRepository;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClass: CashPaymentRepository::class)]
  10. #[ORM\Table(name: 'cash_payments')]
  11. #[ORM\Index(columns: ['student_id'], name: 'idx_student_id')]
  12. #[ORM\Index(columns: ['school_year_id'], name: 'idx_school_year_id')]
  13. #[ORM\Index(columns: ['payment_date'], name: 'idx_payment_date')]
  14. class CashPayment
  15. {
  16. #[ORM\Id]
  17. #[ORM\GeneratedValue]
  18. #[ORM\Column(type: Types::INTEGER)]
  19. private ?int $id = null;
  20. #[ORM\Column(type: Types::STRING, length: 50, unique: true)]
  21. private string $receiptNumber;
  22. #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
  23. #[Assert\NotBlank(message: 'Le montant est obligatoire.')]
  24. #[Assert\Positive(message: 'Le montant doit être supérieur à zéro.')]
  25. private string $amount;
  26. #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  27. private \DateTimeImmutable $paymentDate;
  28. #[ORM\Column(type: Types::STRING, length: 255)]
  29. private string $receivedBy;
  30. #[ORM\Column(type: Types::TEXT, nullable: true)]
  31. private ?string $notes = null;
  32. #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
  33. private ?string $pdfPath = null;
  34. #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  35. private \DateTimeImmutable $createdAt;
  36. // Relations
  37. #[ORM\ManyToOne(targetEntity: Student::class)]
  38. #[ORM\JoinColumn(nullable: false, name: 'student_id')]
  39. #[Assert\NotNull(message: 'Veuillez sélectionner un élève.')]
  40. private ?Student $student = null;
  41. #[ORM\ManyToOne(targetEntity: SchoolYear::class)]
  42. #[ORM\JoinColumn(nullable: false, name: 'school_year_id')]
  43. #[Assert\NotNull(message: 'Veuillez sélectionner une année scolaire.')]
  44. private ?SchoolYear $schoolYear = null;
  45. public function __construct()
  46. {
  47. $this->paymentDate = new \DateTimeImmutable();
  48. $this->createdAt = new \DateTimeImmutable();
  49. $this->generateReceiptNumber();
  50. }
  51. private function generateReceiptNumber(): void
  52. {
  53. $this->receiptNumber = 'RCP-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -6));
  54. }
  55. // ----- Getters & Setters -----
  56. public function getId(): ?int
  57. {
  58. return $this->id;
  59. }
  60. public function getReceiptNumber(): string
  61. {
  62. return $this->receiptNumber;
  63. }
  64. public function setReceiptNumber(string $receiptNumber): self
  65. {
  66. $this->receiptNumber = $receiptNumber;
  67. return $this;
  68. }
  69. public function getAmount(): string
  70. {
  71. return $this->amount;
  72. }
  73. public function setAmount(string|float|int $amount): self
  74. {
  75. // Conversion propre en string avec 2 décimales
  76. $this->amount = number_format((float) $amount, 2, '.', '');
  77. return $this;
  78. }
  79. public function getPaymentDate(): \DateTimeImmutable
  80. {
  81. return $this->paymentDate;
  82. }
  83. public function setPaymentDate(\DateTimeImmutable $paymentDate): self
  84. {
  85. $this->paymentDate = $paymentDate;
  86. return $this;
  87. }
  88. public function getReceivedBy(): string
  89. {
  90. return $this->receivedBy;
  91. }
  92. public function setReceivedBy(string $receivedBy): self
  93. {
  94. $this->receivedBy = $receivedBy;
  95. return $this;
  96. }
  97. public function getNotes(): ?string
  98. {
  99. return $this->notes;
  100. }
  101. public function setNotes(?string $notes): self
  102. {
  103. $this->notes = $notes;
  104. return $this;
  105. }
  106. public function getPdfPath(): ?string
  107. {
  108. return $this->pdfPath;
  109. }
  110. public function setPdfPath(?string $pdfPath): self
  111. {
  112. $this->pdfPath = $pdfPath;
  113. return $this;
  114. }
  115. public function getCreatedAt(): \DateTimeImmutable
  116. {
  117. return $this->createdAt;
  118. }
  119. public function getStudent(): ?Student
  120. {
  121. return $this->student;
  122. }
  123. public function setStudent(?Student $student): self
  124. {
  125. $this->student = $student;
  126. return $this;
  127. }
  128. public function getSchoolYear(): ?SchoolYear
  129. {
  130. return $this->schoolYear;
  131. }
  132. public function setSchoolYear(?SchoolYear $schoolYear): self
  133. {
  134. $this->schoolYear = $schoolYear;
  135. return $this;
  136. }
  137. }