src/Entity/InvoiceDetail.php line 20

  1. <?php
  2. /*
  3.  *  @author Guerby Duval <info@tranzaksyon.com>
  4.  *  @link https://tranzaksyon.com
  5.  *  @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.
  6.  */
  7. namespace App\Entity;
  8. use App\Repository\InvoiceDetailRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
  15. use Symfony\Component\Validator\Constraints\NotNull;
  16. #[ORM\Entity(repositoryClassInvoiceDetailRepository::class)]
  17. class
  18. InvoiceDetail
  19. {
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(['invoice_detail_out'])]
  24.     private ?int $id null;
  25.     #[ORM\ManyToOne(inversedBy'invoiceDetails')]
  26.     #[ORM\JoinColumn(nullabletrue)]
  27.     private ?Invoice $Invoice null;
  28.     #[ORM\ManyToOne(cascade: ['persist'])]
  29.     #[ORM\JoinColumn(nullablefalse)]
  30.     #[NotNull]
  31.     #[Groups(['invoice_detail_out''invoice_detail_in'])]
  32.     private ?Product $product null;
  33.     #[ORM\Column(typeTypes::DECIMALprecision20scale6)]
  34.     #[GreaterThanOrEqual(0.001)]
  35.     #[NotNull]
  36.     #[Groups(['invoice_detail_out''invoice_detail_in'])]
  37.     private ?float $amount null;
  38.     #[ORM\Column(typeTypes::DECIMALprecision20scale6)]
  39.     #[GreaterThanOrEqual(0)]
  40.     #[NotNull]
  41.     #[Groups(['invoice_detail_out''invoice_detail_in'])]
  42.     private ?float $discount 0;
  43.     #[ORM\Column(typeTypes::DECIMALprecision20scale6)]
  44.     private ?float $totalWithoutTax 0;
  45.     #[ORM\OneToMany(mappedBy'invoiceDetail'targetEntityInvoiceDetailTaxes::class, cascade: ['persist'], orphanRemovaltrue)]
  46.     private Collection $invoiceDetailTaxes;
  47.     #[ORM\Column(typeTypes::DECIMALprecision20scale6nullabletrue)]
  48.     #[GreaterThanOrEqual(0)]
  49.     #[Groups(['invoice_detail_out''invoice_detail_in'])]
  50.     private ?float $price null;
  51.     #[ORM\Column(length230nullabletrue)]
  52.     #[Groups(['invoice_detail_out''invoice_detail_in'])]
  53.     private ?string $detail null;
  54.     #[ORM\Column(nullabletrue)]
  55.     private ?float $iva null;
  56.     #[ORM\Column(typeTypes::DECIMALprecision50scale8nullabletrue)]
  57.     private ?string $basGravIVA null;
  58.     #[ORM\Column(typeTypes::DECIMALprecision23scale8nullabletrue)]
  59.     private ?string $liqIVAItem null;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?float $ivaBase null;
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?int $discountType null;
  64.     public function __construct()
  65.     {
  66.         $this->invoiceDetailTaxes = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getInvoice(): ?Invoice
  73.     {
  74.         return $this->Invoice;
  75.     }
  76.     public function setInvoice(?Invoice $Invoice): self
  77.     {
  78.         $this->Invoice $Invoice;
  79.         return $this;
  80.     }
  81.     public function getProduct(): ?Product
  82.     {
  83.         return $this->product;
  84.     }
  85.     public function setProduct(?Product $product): self
  86.     {
  87.         $this->product $product;
  88.         return $this;
  89.     }
  90.     public function getAmount(): ?float
  91.     {
  92.         return $this->amount;
  93.     }
  94.     public function setAmount(float $amount): self
  95.     {
  96.         $this->amount $amount;
  97.         return $this;
  98.     }
  99.     public function getDiscount(): ?float
  100.     {
  101.         return $this->discount;
  102.     }
  103.     public function setDiscount(?float $discount): self
  104.     {
  105.         $this->discount $discount;
  106.         return $this;
  107.     }
  108.     public function getTotalWithoutTax(): float
  109.     {
  110.         return $this->totalWithoutTax;
  111.     }
  112.     public function setTotalWithoutTax(float $totalWithoutTax): self
  113.     {
  114.         $this->totalWithoutTax $totalWithoutTax;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return Collection<int, InvoiceDetailTaxes>
  119.      */
  120.     public function getInvoiceDetailTaxes(): Collection
  121.     {
  122.         return $this->invoiceDetailTaxes;
  123.     }
  124.     public function addInvoiceDetailTax(InvoiceDetailTaxes $invoiceDetailTax): self
  125.     {
  126.         if (!$this->invoiceDetailTaxes->contains($invoiceDetailTax)) {
  127.             $this->invoiceDetailTaxes->add($invoiceDetailTax);
  128.             $invoiceDetailTax->setInvoiceDetail($this);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeInvoiceDetailTax(InvoiceDetailTaxes $invoiceDetailTax): self
  133.     {
  134.         if ($this->invoiceDetailTaxes->removeElement($invoiceDetailTax)) {
  135.             // set the owning side to null (unless already changed)
  136.             if ($invoiceDetailTax->getInvoiceDetail() === $this) {
  137.                 $invoiceDetailTax->setInvoiceDetail(null);
  138.             }
  139.         }
  140.         return $this;
  141.     }
  142.     public function getPrice(): ?float
  143.     {
  144.         return $this->price;
  145.     }
  146.     public function setPrice(?float $price): self
  147.     {
  148.         $this->price $price;
  149.         return $this;
  150.     }
  151.     public function getDetail(): ?string
  152.     {
  153.         return $this->detail;
  154.     }
  155.     public function setDetail(?string $detail): self
  156.     {
  157.         $this->detail $detail;
  158.         return $this;
  159.     }
  160.     public function getIva(): ?float
  161.     {
  162.         return $this->iva;
  163.     }
  164.     public function setIva(?float $iva): static
  165.     {
  166.         $this->iva $iva;
  167.         return $this;
  168.     }
  169.     public function getBasGravIVA(): ?string
  170.     {
  171.         return $this->basGravIVA;
  172.     }
  173.     public function setBasGravIVA(?string $basGravIVA): static
  174.     {
  175.         $this->basGravIVA $basGravIVA;
  176.         return $this;
  177.     }
  178.     public function getLiqIVAItem(): ?string
  179.     {
  180.         return $this->liqIVAItem;
  181.     }
  182.     public function setLiqIVAItem(?string $liqIVAItem): static
  183.     {
  184.         $this->liqIVAItem $liqIVAItem;
  185.         return $this;
  186.     }
  187.     public function getIvaBase(): ?float
  188.     {
  189.         return $this->ivaBase;
  190.     }
  191.     public function setIvaBase(?float $ivaBase): static
  192.     {
  193.         $this->ivaBase $ivaBase;
  194.         return $this;
  195.     }
  196.     public function getDiscountType(): ?int
  197.     {
  198.         return $this->discountType;
  199.     }
  200.     public function setDiscountType(?int $discountType): static
  201.     {
  202.         $this->discountType $discountType;
  203.         return $this;
  204.     }
  205.     public function getUnitDesc()
  206.     {
  207.         if ($this->getSubProduct()) {
  208.             return number_format($this->getSubProduct()->getUnitValue()->getUnitValue(), 2) . " " $this->getSubProduct()->getUnitValue()->getUnit()->getAbreviation() . " (" $this->getSubProduct()->getUnitValue()->getUnit()->getName() . ")";
  209.         }
  210.         return "";
  211.     }
  212.     public function getItemName()
  213.     {
  214.         $name $this->getProduct()->getName();
  215.         if ($this->getSubProduct()) {
  216.             $name .= " " number_format($this->getSubProduct()->getUnitValue()->getUnitValue(), 2) . " " $this->getSubProduct()->getUnitValue()->getUnit()->describe();
  217.         } elseif ($this->getUnitDetail()) {
  218.             $name .= " " number_format($this->getUnitDetail()->getAmount(), 2) . " " $this->getUnitDetail()->getUnit()->describe();
  219.         }
  220.         return $name;
  221.     }
  222.     public function copy()
  223.     {
  224.         $id = new InvoiceDetail();
  225.         $id->setIva($this->getIva())
  226.             ->setProduct($this->getProduct())
  227.             ->setPrice($this->getPrice())
  228.             ->setDetail($this->getDetail())
  229.             ->setDiscount($this->getDiscount())
  230.             ->setDiscountType($this->getDiscountType())
  231.             ->setAmount($this->getAmount());
  232.         return $id;
  233.     }
  234.     public function getTotal()
  235.     {
  236.         if ($this->getProduct()->getTax()) {
  237.             return $this->getTotalWithoutTax() + ($this->getTotalWithoutTax() * ($this->getProduct()->getTax()->getAmount() / 100));
  238.         }
  239.         return $this->getTotalWithoutTax();
  240.     }
  241. }