<?php
namespace App\Billing\Entity;
use App\Repository\InstallmentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: InstallmentRepository::class)]
class Installment
{
const STATUS_PENDING = 'PENDING';
const STATUS_PAID = 'PAID';
const STATUS_LATE = 'LATE';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'installments')]
#[ORM\JoinColumn(nullable: false)]
private ?PaymentSchedule $schedule = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $amount = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $dueDate = null;
#[ORM\Column(length: 50)]
private ?string $status = self::STATUS_PENDING;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $paidAt = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
private ?string $paidAmount = '0.00';
#[ORM\ManyToMany(targetEntity: Payment::class, mappedBy: 'installments')]
private Collection $payments;
public function __construct()
{
$this->payments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPaymentSchedule(): ?PaymentSchedule
{
return $this->schedule;
}
public function getSchedule(): ?PaymentSchedule
{
return $this->schedule;
}
public function setSchedule(?PaymentSchedule $schedule): static
{
$this->schedule = $schedule;
return $this;
}
public function getAmount(): ?string
{
return $this->amount;
}
public function setAmount(string $amount): static
{
$this->amount = $amount;
return $this;
}
public function getPaidAmount(): ?string
{
return $this->paidAmount;
}
public function setPaidAmount(string $paidAmount): static
{
$this->paidAmount = $paidAmount;
return $this;
}
public function getDueDate(): ?\DateTimeInterface
{
return $this->dueDate;
}
public function setDueDate(\DateTimeInterface $dueDate): static
{
$this->dueDate = $dueDate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function getPaidAt(): ?\DateTimeInterface
{
return $this->paidAt;
}
public function setPaidAt(?\DateTimeInterface $paidAt): static
{
$this->paidAt = $paidAt;
return $this;
}
/**
* @return Collection<int, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): static
{
if (!$this->payments->contains($payment)) {
$this->payments->add($payment);
$payment->addInstallment($this);
}
return $this;
}
public function removePayment(Payment $payment): static
{
if ($this->payments->removeElement($payment)) {
$payment->removeInstallment($this);
}
return $this;
}
}