src/Entity/Finance/Collectable.php line 10

  1. <?php
  2. namespace App\Entity\Finance;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  6. #[ORM\Entity]
  7. class Collectable extends Chargeable
  8. {
  9.     #[Assert\NotNull]
  10.     #[Assert\Type(typeProforma::class)]
  11.     #[ORM\ManyToOne(targetEntityProforma::class, inversedBy'collectables')]
  12.     #[ORM\JoinColumn(name'invoice_id')]
  13.     private ?Proforma $form null;
  14.     #[Assert\Callback]
  15.     public function validate(ExecutionContextInterface $context$payload): void
  16.     {
  17.         if (empty($this->form)) {
  18.             $context->buildViolation('A collectable must be associated only with either, a proforma, or an invoice')
  19.                 ->atPath('form')
  20.                 ->addViolation();
  21.         }
  22.     }
  23.     public function getForm(): ?Proforma
  24.     {
  25.         return $this->form;
  26.     }
  27.     public function setForm(?Proforma $form): self
  28.     {
  29.         $this->form $form;
  30.         return $this;
  31.     }
  32. }