src/Entity/Finance/Chargeable.php line 23

  1. <?php
  2. namespace App\Entity\Finance;
  3. use App\Doctrine\Type\Finance\ExpenseType;
  4. use App\Validator\IsValidEnum\IsValidEnum;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Table(name'finance_chargeable')]
  11. #[ORM\Index(columns: ['bill_id'], name'finance_chargeable_bill_id_idx')]
  12. #[ORM\Index(columns: ['invoice_id'], name'finance_chargeable_invoice_id_idx')]
  13. #[ORM\InheritanceType('SINGLE_TABLE')]
  14. #[ORM\DiscriminatorColumn(name'chargeable_type')]
  15. #[ORM\DiscriminatorMap([
  16.     'COLLECTABLE' => Collectable::class,
  17.     'EXPENSE' => Expense::class,
  18. ])]
  19. #[ORM\Entity]
  20. abstract class Chargeable
  21. {
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  24.     #[ORM\SequenceGenerator(sequenceName'finance_chargeable_id_seq')]
  25.     #[ORM\Column(typeTypes::INTEGER)]
  26.     protected ?int $id null;
  27.     #[Assert\NotNull]
  28.     #[IsValidEnum(enumExpenseType::class)]
  29.     #[ORM\Column(name'expense_type'typeTypes::STRINGenumTypeExpenseType::class)]
  30.     protected ?ExpenseType $type null;
  31.     #[Assert\Type(typeTypes::STRING)]
  32.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  33.     protected ?string $serviceName null;
  34.     #[Assert\NotNull]
  35.     #[Assert\Type(typeTypes::INTEGER)]
  36.     #[ORM\Column(typeTypes::INTEGER)]
  37.     protected ?int $quantity null;
  38.     #[Assert\NotNull]
  39.     #[Assert\Type(typeTypes::FLOAT)]
  40.     #[ORM\Column(typeTypes::DECIMALprecision18scale2)]
  41.     protected ?float $unitPrice null;
  42.     #[Assert\NotNull]
  43.     #[Assert\Type(typeTypes::FLOAT)]
  44.     #[ORM\Column(typeTypes::DECIMALprecision18scale2)]
  45.     protected ?float $subTotal null;
  46.     #[Assert\NotNull]
  47.     #[Assert\Type(typeTypes::FLOAT)]
  48.     #[ORM\Column(typeTypes::DECIMALprecision18scale2)]
  49.     protected ?float $taxesSum null;
  50.     #[Assert\NotNull]
  51.     #[Assert\Type(typeTypes::FLOAT)]
  52.     #[ORM\Column(typeTypes::DECIMALprecision18scale2)]
  53.     protected ?float $grandTotal null;
  54.     /** @var Collection<int, Tax> */
  55.     #[ORM\OneToMany(mappedBy'chargeable'targetEntityTax::class, cascade: ['persist''remove'])]
  56.     protected Collection $taxes;
  57.     public function __construct()
  58.     {
  59.         $this->taxes = new ArrayCollection();
  60.     }
  61.     public function getId(): ?int
  62.     {
  63.         return $this->id;
  64.     }
  65.     public function getType(): ?ExpenseType
  66.     {
  67.         return $this->type;
  68.     }
  69.     public function setType(?ExpenseType $type): self
  70.     {
  71.         $this->type $type;
  72.         return $this;
  73.     }
  74.     public function getServiceName(): ?string
  75.     {
  76.         return $this->serviceName;
  77.     }
  78.     public function setServiceName(?string $serviceName): self
  79.     {
  80.         $this->serviceName $serviceName;
  81.         return $this;
  82.     }
  83.     public function getQuantity(): ?int
  84.     {
  85.         return $this->quantity;
  86.     }
  87.     public function setQuantity(?int $quantity): self
  88.     {
  89.         $this->quantity $quantity;
  90.         return $this;
  91.     }
  92.     public function getUnitPrice(): ?float
  93.     {
  94.         return $this->unitPrice;
  95.     }
  96.     public function setUnitPrice(?float $unitPrice): self
  97.     {
  98.         $this->unitPrice $unitPrice;
  99.         return $this;
  100.     }
  101.     public function getSubTotal(): ?float
  102.     {
  103.         return $this->subTotal;
  104.     }
  105.     public function setSubTotal(?float $subTotal): self
  106.     {
  107.         $this->subTotal $subTotal;
  108.         return $this;
  109.     }
  110.     public function getTaxesSum(): ?float
  111.     {
  112.         return $this->taxesSum;
  113.     }
  114.     public function setTaxesSum(?float $taxesSum): self
  115.     {
  116.         $this->taxesSum $taxesSum;
  117.         return $this;
  118.     }
  119.     public function getGrandTotal(): ?float
  120.     {
  121.         return $this->grandTotal;
  122.     }
  123.     public function setGrandTotal(?float $grandTotal): self
  124.     {
  125.         $this->grandTotal $grandTotal;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection<int, Tax>
  130.      */
  131.     public function getTaxes(): Collection
  132.     {
  133.         return $this->taxes;
  134.     }
  135.     public function addTax(Tax $tax): self
  136.     {
  137.         if (!$this->taxes->contains($tax)) {
  138.             $this->taxes->add($tax);
  139.             $tax->setChargeable($this);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeTax(Tax $tax): self
  144.     {
  145.         if ($this->taxes->removeElement($tax)) {
  146.             // set the owning side to null (unless already changed)
  147.             if ($tax->getChargeable() === $this) {
  148.                 $tax->setChargeable(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153. }