src/Finance/Domain/Entity/StudentFinancialAccount.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Finance\Domain\Entity;
  3. use App\Finance\Domain\Enum\SolvencyStatus;
  4. use App\Finance\Domain\Repository\StudentFinancialAccountRepository;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. #[ORM\Entity(repositoryClass: StudentFinancialAccountRepository::class)]
  9. #[ORM\Table(name: 'student_financial_accounts')]
  10. #[ORM\Index(columns: ['student_id'], name: 'idx_student_id')]
  11. #[ORM\Index(columns: ['school_year_id'], name: 'idx_school_year_id')]
  12. #[ORM\Index(columns: ['solvency_status'], name: 'idx_solvency_status')]
  13. class StudentFinancialAccount
  14. {
  15. #[ORM\Id]
  16. #[ORM\GeneratedValue]
  17. #[ORM\Column(type: Types::INTEGER)]
  18. private ?int $id = null;
  19. #[ORM\Column(type: Types::INTEGER)]
  20. #[Assert\NotNull]
  21. private int $studentId;
  22. #[ORM\Column(type: Types::INTEGER)]
  23. #[Assert\NotNull]
  24. private int $schoolYearId;
  25. #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
  26. private string $totalDue = '0.00';
  27. #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
  28. private string $totalPaid = '0.00';
  29. #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
  30. private string $balance = '0.00';
  31. #[ORM\Column(type: Types::STRING, length: 20, enumType: SolvencyStatus::class)]
  32. private SolvencyStatus $solvencyStatus = SolvencyStatus::SOLVENT;
  33. #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  34. private \DateTimeImmutable $createdAt;
  35. #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  36. private \DateTimeImmutable $updatedAt;
  37. public function __construct()
  38. {
  39. $this->createdAt = new \DateTimeImmutable();
  40. $this->updatedAt = new \DateTimeImmutable();
  41. }
  42. public function getId(): ?int
  43. {
  44. return $this->id;
  45. }
  46. public function getStudentId(): int
  47. {
  48. return $this->studentId;
  49. }
  50. public function setStudentId(int $studentId): self
  51. {
  52. $this->studentId = $studentId;
  53. $this->updatedAt = new \DateTimeImmutable();
  54. return $this;
  55. }
  56. public function getSchoolYearId(): int
  57. {
  58. return $this->schoolYearId;
  59. }
  60. public function setSchoolYearId(int $schoolYearId): self
  61. {
  62. $this->schoolYearId = $schoolYearId;
  63. $this->updatedAt = new \DateTimeImmutable();
  64. return $this;
  65. }
  66. public function getTotalDue(): string
  67. {
  68. return $this->totalDue;
  69. }
  70. public function setTotalDue(string $totalDue): self
  71. {
  72. $this->totalDue = $totalDue;
  73. $this->updatedAt = new \DateTimeImmutable();
  74. return $this;
  75. }
  76. public function getTotalPaid(): string
  77. {
  78. return $this->totalPaid;
  79. }
  80. public function setTotalPaid(string $totalPaid): self
  81. {
  82. $this->totalPaid = $totalPaid;
  83. $this->updatedAt = new \DateTimeImmutable();
  84. return $this;
  85. }
  86. public function getBalance(): string
  87. {
  88. return $this->balance;
  89. }
  90. public function setBalance(string $balance): self
  91. {
  92. $this->balance = $balance;
  93. $this->updatedAt = new \DateTimeImmutable();
  94. return $this;
  95. }
  96. public function getSolvencyStatus(): SolvencyStatus
  97. {
  98. return $this->solvencyStatus;
  99. }
  100. public function setSolvencyStatus(SolvencyStatus $solvencyStatus): self
  101. {
  102. $this->solvencyStatus = $solvencyStatus;
  103. $this->updatedAt = new \DateTimeImmutable();
  104. return $this;
  105. }
  106. public function getCreatedAt(): \DateTimeImmutable
  107. {
  108. return $this->createdAt;
  109. }
  110. public function getUpdatedAt(): \DateTimeImmutable
  111. {
  112. return $this->updatedAt;
  113. }
  114. public function recalculateBalance(): void
  115. {
  116. $this->balance = bcsub($this->totalDue, $this->totalPaid, 2);
  117. $this->updatedAt = new \DateTimeImmutable();
  118. }
  119. }