src/Entity/Finance/Chargeable.php line 23
<?php
namespace App\Entity\Finance;
use App\Doctrine\Type\Finance\ExpenseType;
use App\Validator\IsValidEnum\IsValidEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'finance_chargeable')]
#[ORM\Index(columns: ['bill_id'], name: 'finance_chargeable_bill_id_idx')]
#[ORM\Index(columns: ['invoice_id'], name: 'finance_chargeable_invoice_id_idx')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'chargeable_type')]
#[ORM\DiscriminatorMap([
'COLLECTABLE' => Collectable::class,
'EXPENSE' => Expense::class,
])]
#[ORM\Entity]
abstract class Chargeable
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'finance_chargeable_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
protected ?int $id = null;
#[Assert\NotNull]
#[IsValidEnum(enum: ExpenseType::class)]
#[ORM\Column(name: 'expense_type', type: Types::STRING, enumType: ExpenseType::class)]
protected ?ExpenseType $type = null;
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING, nullable: true)]
protected ?string $serviceName = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::INTEGER)]
#[ORM\Column(type: Types::INTEGER)]
protected ?int $quantity = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2)]
protected ?float $unitPrice = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2)]
protected ?float $subTotal = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2)]
protected ?float $taxesSum = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 2)]
protected ?float $grandTotal = null;
/** @var Collection<int, Tax> */
#[ORM\OneToMany(mappedBy: 'chargeable', targetEntity: Tax::class, cascade: ['persist', 'remove'])]
protected Collection $taxes;
public function __construct()
{
$this->taxes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?ExpenseType
{
return $this->type;
}
public function setType(?ExpenseType $type): self
{
$this->type = $type;
return $this;
}
public function getServiceName(): ?string
{
return $this->serviceName;
}
public function setServiceName(?string $serviceName): self
{
$this->serviceName = $serviceName;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(?int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getUnitPrice(): ?float
{
return $this->unitPrice;
}
public function setUnitPrice(?float $unitPrice): self
{
$this->unitPrice = $unitPrice;
return $this;
}
public function getSubTotal(): ?float
{
return $this->subTotal;
}
public function setSubTotal(?float $subTotal): self
{
$this->subTotal = $subTotal;
return $this;
}
public function getTaxesSum(): ?float
{
return $this->taxesSum;
}
public function setTaxesSum(?float $taxesSum): self
{
$this->taxesSum = $taxesSum;
return $this;
}
public function getGrandTotal(): ?float
{
return $this->grandTotal;
}
public function setGrandTotal(?float $grandTotal): self
{
$this->grandTotal = $grandTotal;
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->setChargeable($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->getChargeable() === $this) {
$tax->setChargeable(null);
}
}
return $this;
}
}