src/Entity/Finance/BaseQuotation.php line 34
<?php
namespace App\Entity\Finance;
use ApiPlatform\Metadata\ApiProperty;
use App\Entity\Common;
use App\Entity\Common\Observation;
use App\Entity\Expediting\ShippingPlan;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Table(name: 'finance_bill')]
#[ORM\Index(columns: ['original_bill_id'], name: 'finance_bill_original_bill_id_idx')]
#[ORM\Index(columns: ['shipping_plan_id'], name: 'finance_bill_shipping_plan_id_idx')]
#[ORM\Index(columns: ['payable_by'], name: 'finance_bill_payable_by_idx')]
#[ORM\Index(columns: ['payable_to'], name: 'finance_bill_payable_to_idx')]
#[ORM\Index(columns: ['created_by'], name: 'finance_bill_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'finance_bill_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'finance_bill_number_key', columns: ['number'])]
#[ORM\UniqueConstraint(name: 'finance_bill_external_reference_key', columns: ['external_reference'])]
#[ORM\UniqueConstraint(name: 'finance_bill_identifier_key', columns: ['identifier'])]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type')]
#[ORM\DiscriminatorMap([
'BILL' => Bill::class,
'QUOTATION' => Quotation::class,
])]
#[ORM\Entity]
Abstract class BaseQuotation
{
use Quoteable;
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'finance_bill_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
protected ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
#[ApiProperty(identifier: true)]
protected ?Ulid $identifier = null;
#[Assert\Type(type: ShippingPlan::class)]
#[ORM\ManyToOne(targetEntity: ShippingPlan::class, inversedBy: 'quotations')]
#[ORM\JoinColumn(name: 'shipping_plan_id', nullable: false)]
#[ApiProperty(readableLink: true)]
protected ?ShippingPlan $shippingPlan = null;
#[Assert\Type(type: BaseQuotation::class)]
#[ORM\ManyToOne(targetEntity: BaseQuotation::class, inversedBy: 'editions')]
#[ORM\JoinColumn(name: 'original_bill_id')]
protected ?BaseQuotation $originalForm = null;
#[ORM\OneToMany(mappedBy: 'originalForm', targetEntity: BaseQuotation::class)]
protected Collection $editions;
/** @var Collection<int, Expense> */
#[ORM\OneToMany(mappedBy: 'form', targetEntity: Expense::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $expenses;
/** @var Collection<int, Tax> */
#[ORM\OneToMany(mappedBy: 'quotation', targetEntity: Tax::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $taxes;
/** @var Collection<int, Observation> */
#[ORM\OneToMany(mappedBy: 'quotation', targetEntity: Observation::class, cascade: ['persist', 'remove'])]
protected Collection $observations;
public function __construct()
{
$this->identifier = new Ulid();
$this->expenses = new ArrayCollection();
$this->taxes = new ArrayCollection();
$this->observations = new ArrayCollection();
$this->editions = new ArrayCollection();
}
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (empty($this->workOrder) && empty($this->shipment)) {
$context->buildViolation('Quotation must be associated only with either, a work order, or a shipment')
->atPath('workOrder')
->addViolation();
$context->buildViolation('Quotation must be associated only with either, a work order, or a shipment')
->atPath('shipment')
->addViolation();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier($identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getShippingPlan(): ?ShippingPlan
{
return $this->shippingPlan;
}
public function setShippingPlan(?ShippingPlan $shippingPlan): self
{
$this->shippingPlan = $shippingPlan;
return $this;
}
public function getOriginalForm(): ?self
{
return $this->originalForm;
}
public function setOriginalForm(?self $originalForm): self
{
$form = $originalForm;
while ($form?->getOriginalForm() instanceof BaseQuotation) {
$form = $form->getOriginalForm();
}
$this->originalForm = $form;
return $this;
}
/**
* @return Collection<int, BaseQuotation>
*/
public function getEditions(): Collection
{
return $this->editions;
}
public function addEdition(BaseQuotation $edition): self
{
if (!$this->editions->contains($edition)) {
$this->editions->add($edition);
$edition->setOriginalForm($this);
}
return $this;
}
public function removeEdition(BaseQuotation $edition): self
{
if ($this->editions->removeElement($edition)) {
// set the owning side to null (unless already changed)
if ($edition->getOriginalForm() === $this) {
$edition->setOriginalForm(null);
}
}
return $this;
}
/**
* @return Collection<int, Expense>
*/
public function getExpenses(): Collection
{
return $this->expenses;
}
public function addExpense(Expense $expense): self
{
if (!$this->expenses->contains($expense)) {
$this->expenses->add($expense);
$expense->setForm($this);
}
return $this;
}
public function removeExpense(Expense $expense): self
{
if ($this->expenses->removeElement($expense)) {
// set the owning side to null (unless already changed)
if ($expense->getForm() === $this) {
$expense->setForm(null);
}
}
return $this;
}
/**
* @return Collection<int, Tax>
*/
public function getTaxes(): Collection
{
return $this->taxes;
}
public function addTax(Tax $tax): self
{
if (!$this->taxes->contains($tax)) {
$this->taxes->add($tax);
$tax->setQuotation($this);
}
return $this;
}
public function removeTax(Tax $tax): self
{
if ($this->taxes->removeElement($tax)) {
// set the owning side to null (unless already changed)
if ($tax->getQuotation() === $this) {
$tax->setQuotation(null);
}
}
return $this;
}
public function isFilled(): bool
{
return ($this->expenses->count() > 0);
}
/**
* @return Collection<int, Observation>
*/
public function getObservations(): Collection
{
return $this->observations;
}
public function addObservation(Observation $observation): self
{
if (!$this->observations->contains($observation)) {
$this->observations->add($observation);
$observation->setQuotation($this);
}
return $this;
}
public function removeObservation(Observation $observation): self
{
if ($this->observations->removeElement($observation)) {
// set the owning side to null (unless already changed)
if ($observation->getQuotation() === $this) {
$observation->setQuotation(null);
}
}
return $this;
}
}