src/Entity/Finance/Tax.php line 17

  1. <?php
  2. namespace App\Entity\Finance;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  8. #[ORM\Table(name'finance_tax')]
  9. #[ORM\Index(columns: ['bill_id'], name'finance_tax_bill_id_idx')]
  10. #[ORM\Index(columns: ['invoice_id'], name'finance_tax_invoice_id_idx')]
  11. #[ORM\Index(columns: ['chargeable_id'], name'finance_tax_chargeable_id_idx')]
  12. #[ORM\Entity]
  13. #[ApiResource(routePrefix'/finance')]
  14. class Tax
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  18.     #[ORM\SequenceGenerator(sequenceName'finance_tax_id_seq')]
  19.     #[ORM\Column(typeTypes::INTEGER)]
  20.     protected ?int $id null;
  21.     #[Assert\NotNull]
  22.     #[Assert\Type(typeBaseQuotation::class)]
  23.     #[ORM\ManyToOne(targetEntityBaseQuotation::class, inversedBy'taxes')]
  24.     #[ORM\JoinColumn(name'bill_id')]
  25.     private ?BaseQuotation $quotation null;
  26.     #[Assert\NotNull]
  27.     #[Assert\Type(typeProforma::class)]
  28.     #[ORM\ManyToOne(targetEntityProforma::class, inversedBy'taxes')]
  29.     #[ORM\JoinColumn(name'invoice_id')]
  30.     private ?Proforma $invoice null;
  31.     #[Assert\NotNull]
  32.     #[Assert\Type(typeChargeable::class)]
  33.     #[ORM\ManyToOne(targetEntityChargeable::class, inversedBy'taxes')]
  34.     #[ORM\JoinColumn(name'chargeable_id')]
  35.     private ?Chargeable $chargeable null;
  36.     #[Assert\Type(typeTypes::STRING)]
  37.     #[ORM\Column(typeTypes::STRING)]
  38.     private ?string $name null;
  39.     #[Assert\NotNull]
  40.     #[Assert\Type(typeTypes::FLOAT)]
  41.     #[ORM\Column(typeTypes::DECIMALprecision18scale2)]
  42.     private ?float $amount null;
  43.     #[Assert\NotNull]
  44.     #[Assert\Type(typeTypes::FLOAT)]
  45.     #[ORM\Column(typeTypes::DECIMALprecision5scale2)]
  46.     private ?float $rate null;
  47.     #[Assert\Callback]
  48.     public function validate(ExecutionContextInterface $context$payload): void
  49.     {
  50.         if (empty($this->workOrder) && empty($this->shipment)) {
  51.             $context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
  52.                 ->atPath('quotation')
  53.                 ->addViolation();
  54.             $context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
  55.                 ->atPath('invoice')
  56.                 ->addViolation();
  57.             $context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
  58.                 ->atPath('chargeable')
  59.                 ->addViolation();
  60.         }
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getQuotation(): ?BaseQuotation
  67.     {
  68.         return $this->quotation;
  69.     }
  70.     public function setQuotation(?BaseQuotation $quotation): static
  71.     {
  72.         $this->quotation $quotation;
  73.         return $this;
  74.     }
  75.     public function getInvoice(): ?Proforma
  76.     {
  77.         return $this->invoice;
  78.     }
  79.     public function setInvoice(?Proforma $invoice): static
  80.     {
  81.         $this->invoice $invoice;
  82.         return $this;
  83.     }
  84.     public function getChargeable(): ?Chargeable
  85.     {
  86.         return $this->chargeable;
  87.     }
  88.     public function setChargeable(?Chargeable $chargeable): static
  89.     {
  90.         $this->chargeable $chargeable;
  91.         return $this;
  92.     }
  93.     public function getName(): ?string
  94.     {
  95.         return $this->name;
  96.     }
  97.     public function setName(?string $name): static
  98.     {
  99.         $this->name $name;
  100.         return $this;
  101.     }
  102.     public function getAmount(): ?string
  103.     {
  104.         return $this->amount;
  105.     }
  106.     public function setAmount(?string $amount): static
  107.     {
  108.         $this->amount $amount;
  109.         return $this;
  110.     }
  111.     public function getRate(): ?float
  112.     {
  113.         return $this->rate;
  114.     }
  115.     public function setRate(?float $rate): static
  116.     {
  117.         $this->rate $rate;
  118.         return $this;
  119.     }
  120. }