<?php
namespace App\Finance\Domain\Entity;
use App\Finance\Domain\Repository\PaymentAllocationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PaymentAllocationRepository::class)]
#[ORM\Table(name: 'payment_allocations')]
#[ORM\Index(columns: ['cash_payment_id'], name: 'idx_cash_payment_id')]
#[ORM\Index(columns: ['student_fee_id'], name: 'idx_student_fee_id')]
class PaymentAllocation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: CashPayment::class)]
#[ORM\JoinColumn(nullable: false)]
private CashPayment $cashPayment;
#[ORM\ManyToOne(targetEntity: StudentFee::class)]
#[ORM\JoinColumn(nullable: false)]
private StudentFee $studentFee;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
#[Assert\NotNull]
#[Assert\Positive]
private string $allocatedAmount;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getCashPayment(): CashPayment
{
return $this->cashPayment;
}
public function setCashPayment(CashPayment $cashPayment): self
{
$this->cashPayment = $cashPayment;
return $this;
}
public function getStudentFee(): StudentFee
{
return $this->studentFee;
}
public function setStudentFee(StudentFee $studentFee): self
{
$this->studentFee = $studentFee;
return $this;
}
public function getAllocatedAmount(): string
{
return $this->allocatedAmount;
}
public function setAllocatedAmount(string $allocatedAmount): self
{
$this->allocatedAmount = $allocatedAmount;
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
// Optional: helper methods pour récupérer juste les IDs
public function getCashPaymentId(): int
{
return $this->cashPayment->getId();
}
public function getStudentFeeId(): int
{
return $this->studentFee->getId();
}
}