<?php
namespace App\Finance\Domain\Entity;
use App\Finance\Domain\Enum\SolvencyStatus;
use App\Finance\Domain\Repository\StudentFinancialAccountRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: StudentFinancialAccountRepository::class)]
#[ORM\Table(name: 'student_financial_accounts')]
#[ORM\Index(columns: ['student_id'], name: 'idx_student_id')]
#[ORM\Index(columns: ['school_year_id'], name: 'idx_school_year_id')]
#[ORM\Index(columns: ['solvency_status'], name: 'idx_solvency_status')]
class StudentFinancialAccount
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\Column(type: Types::INTEGER)]
#[Assert\NotNull]
private int $studentId;
#[ORM\Column(type: Types::INTEGER)]
#[Assert\NotNull]
private int $schoolYearId;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
private string $totalDue = '0.00';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
private string $totalPaid = '0.00';
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, options: ['default' => '0.00'])]
private string $balance = '0.00';
#[ORM\Column(type: Types::STRING, length: 20, enumType: SolvencyStatus::class)]
private SolvencyStatus $solvencyStatus = SolvencyStatus::SOLVENT;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $updatedAt;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getStudentId(): int
{
return $this->studentId;
}
public function setStudentId(int $studentId): self
{
$this->studentId = $studentId;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getSchoolYearId(): int
{
return $this->schoolYearId;
}
public function setSchoolYearId(int $schoolYearId): self
{
$this->schoolYearId = $schoolYearId;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getTotalDue(): string
{
return $this->totalDue;
}
public function setTotalDue(string $totalDue): self
{
$this->totalDue = $totalDue;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getTotalPaid(): string
{
return $this->totalPaid;
}
public function setTotalPaid(string $totalPaid): self
{
$this->totalPaid = $totalPaid;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getBalance(): string
{
return $this->balance;
}
public function setBalance(string $balance): self
{
$this->balance = $balance;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getSolvencyStatus(): SolvencyStatus
{
return $this->solvencyStatus;
}
public function setSolvencyStatus(SolvencyStatus $solvencyStatus): self
{
$this->solvencyStatus = $solvencyStatus;
$this->updatedAt = new \DateTimeImmutable();
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function recalculateBalance(): void
{
$this->balance = bcsub($this->totalDue, $this->totalPaid, 2);
$this->updatedAt = new \DateTimeImmutable();
}
}