<?php
namespace App\Billing\Entity;
use App\Repository\PaymentScheduleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PaymentScheduleRepository::class)]
class PaymentSchedule
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToOne(inversedBy: 'paymentSchedule', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Invoice $invoice = null;
#[ORM\OneToMany(mappedBy: 'schedule', targetEntity: Installment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $installments;
public function __construct()
{
$this->installments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(Invoice $invoice): static
{
$this->invoice = $invoice;
return $this;
}
/**
* @return Collection<int, Installment>
*/
public function getInstallments(): Collection
{
return $this->installments;
}
public function addInstallment(Installment $installment): static
{
if (!$this->installments->contains($installment)) {
$this->installments->add($installment);
$installment->setSchedule($this);
}
return $this;
}
public function removeInstallment(Installment $installment): static
{
if ($this->installments->removeElement($installment)) {
// set the owning side to null (unless already changed)
if ($installment->getSchedule() === $this) {
$installment->setSchedule(null);
}
}
return $this;
}
}