src/Entity/Finance/Collectable.php line 10
<?php
namespace App\Entity\Finance;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity]
class Collectable extends Chargeable
{
#[Assert\NotNull]
#[Assert\Type(type: Proforma::class)]
#[ORM\ManyToOne(targetEntity: Proforma::class, inversedBy: 'collectables')]
#[ORM\JoinColumn(name: 'invoice_id')]
private ?Proforma $form = null;
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (empty($this->form)) {
$context->buildViolation('A collectable must be associated only with either, a proforma, or an invoice')
->atPath('form')
->addViolation();
}
}
public function getForm(): ?Proforma
{
return $this->form;
}
public function setForm(?Proforma $form): self
{
$this->form = $form;
return $this;
}
}