src/Entity/Finance/Tax.php line 17
<?php
namespace App\Entity\Finance;
use ApiPlatform\Metadata\ApiResource;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Table(name: 'finance_tax')]
#[ORM\Index(columns: ['bill_id'], name: 'finance_tax_bill_id_idx')]
#[ORM\Index(columns: ['invoice_id'], name: 'finance_tax_invoice_id_idx')]
#[ORM\Index(columns: ['chargeable_id'], name: 'finance_tax_chargeable_id_idx')]
#[ORM\Entity]
#[ApiResource(routePrefix: '/finance')]
class Tax
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'finance_tax_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
protected ?int $id = null;
#[Assert\NotNull]
#[Assert\Type(type: BaseQuotation::class)]
#[ORM\ManyToOne(targetEntity: BaseQuotation::class, inversedBy: 'taxes')]
#[ORM\JoinColumn(name: 'bill_id')]
private ?BaseQuotation $quotation = null;
#[Assert\NotNull]
#[Assert\Type(type: Proforma::class)]
#[ORM\ManyToOne(targetEntity: Proforma::class, inversedBy: 'taxes')]
#[ORM\JoinColumn(name: 'invoice_id')]
private ?Proforma $invoice = null;
#[Assert\NotNull]
#[Assert\Type(type: Chargeable::class)]
#[ORM\ManyToOne(targetEntity: Chargeable::class, inversedBy: 'taxes')]
#[ORM\JoinColumn(name: 'chargeable_id')]
private ?Chargeable $chargeable = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $name = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2)]
private ?float $amount = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 5, scale: 2)]
private ?float $rate = null;
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (empty($this->workOrder) && empty($this->shipment)) {
$context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
->atPath('quotation')
->addViolation();
$context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
->atPath('invoice')
->addViolation();
$context->buildViolation('Tax must be associated only with either, a quotation, an invoice, or a chargeable')
->atPath('chargeable')
->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getQuotation(): ?BaseQuotation
{
return $this->quotation;
}
public function setQuotation(?BaseQuotation $quotation): static
{
$this->quotation = $quotation;
return $this;
}
public function getInvoice(): ?Proforma
{
return $this->invoice;
}
public function setInvoice(?Proforma $invoice): static
{
$this->invoice = $invoice;
return $this;
}
public function getChargeable(): ?Chargeable
{
return $this->chargeable;
}
public function setChargeable(?Chargeable $chargeable): static
{
$this->chargeable = $chargeable;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getAmount(): ?string
{
return $this->amount;
}
public function setAmount(?string $amount): static
{
$this->amount = $amount;
return $this;
}
public function getRate(): ?float
{
return $this->rate;
}
public function setRate(?float $rate): static
{
$this->rate = $rate;
return $this;
}
}