src/Entity/InvoiceTaxes.php line 16

  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\Enums\IvaPurposeEnum;
  9. use App\Repository\InvoiceTaxesRepository;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassInvoiceTaxesRepository::class)]
  13. class InvoiceTaxes
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\ManyToOne(inversedBy'invoiceTaxes')]
  20.     #[ORM\JoinColumn(nullabletrue)]
  21.     private ?Invoice $invoice null;
  22.     #[ORM\Column]
  23.     private ?int $code null;
  24.     #[ORM\Column]
  25.     private ?int $percentage null;
  26.     #[ORM\Column(typeTypes::DECIMALprecision23scale8)]
  27.     private ?string $base null;
  28.     #[ORM\Column(typeTypes::DECIMALprecision23scale8)]
  29.     private ?string $fare null;
  30.     #[ORM\Column(typeTypes::DECIMALprecision23scale8)]
  31.     private ?string $taxAmount null;
  32.     #[ORM\Column(typeTypes::DECIMALprecision23scale8nullabletrue)]
  33.     private ?string $baseGravada null;
  34.     #[ORM\Column(length3nullabletrue)]
  35.     private ?string $purpose null;
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getInvoice(): ?Invoice
  41.     {
  42.         return $this->invoice;
  43.     }
  44.     public function setInvoice(?Invoice $invoice): self
  45.     {
  46.         $this->invoice $invoice;
  47.         return $this;
  48.     }
  49.     public function getCode(): ?int
  50.     {
  51.         return $this->code;
  52.     }
  53.     public function setCode(int $code): self
  54.     {
  55.         $this->code $code;
  56.         return $this;
  57.     }
  58.     public function getPercentage(): ?int
  59.     {
  60.         return $this->percentage;
  61.     }
  62.     public function setPercentage(int $percentage): self
  63.     {
  64.         $this->percentage $percentage;
  65.         return $this;
  66.     }
  67.     public function getBase(): ?string
  68.     {
  69.         return $this->base;
  70.     }
  71.     public function setBase(string $base): self
  72.     {
  73.         $this->base $base;
  74.         return $this;
  75.     }
  76.     public function getFare(): ?string
  77.     {
  78.         return $this->fare;
  79.     }
  80.     public function setFare(string $fare): self
  81.     {
  82.         $this->fare $fare;
  83.         return $this;
  84.     }
  85.     public function getTaxAmount(): ?string
  86.     {
  87.         return $this->taxAmount;
  88.     }
  89.     public function setTaxAmount(string $taxAmount): self
  90.     {
  91.         $this->taxAmount $taxAmount;
  92.         return $this;
  93.     }
  94.     public function getBaseGravada(): ?string
  95.     {
  96.         return $this->baseGravada;
  97.     }
  98.     public function setBaseGravada(?string $baseGravada): static
  99.     {
  100.         $this->baseGravada $baseGravada;
  101.         return $this;
  102.     }
  103.     public function getPurpose(): ?string
  104.     {
  105.         return $this->purpose;
  106.     }
  107.     public function setPurpose(?string $purpose): static
  108.     {
  109.         $this->purpose $purpose;
  110.         return $this;
  111.     }
  112.     public function copy(): InvoiceTaxes
  113.     {
  114.         $invoiceTax = new InvoiceTaxes();
  115.         $invoiceTax->setTaxAmount($this->getTaxAmount())
  116.             ->setCode($this->getCode())
  117.             ->setFare($this->getFare())
  118.             ->setBase($this->getBase())
  119.             ->setPercentage($this->getPercentage());
  120.         $invoiceTax->setPurpose(self::computePurpose($invoiceTax)->value);
  121.         return $invoiceTax;
  122.     }
  123.     /**
  124.      * @param InvoiceTaxes $invoiceTax
  125.      * @return IvaPurposeEnum
  126.      */
  127.     public static function computePurpose(InvoiceTaxes $invoiceTax): IvaPurposeEnum
  128.     {
  129.         if ($invoiceTax->getCode() === 2) {
  130.             if ($invoiceTax->getPercentage() === 6) {
  131.                 return IvaPurposeEnum::NoObjetoIva;
  132.             } elseif ($invoiceTax->getPercentage() === 0) {
  133.                 return IvaPurposeEnum::Base0;
  134.             } else {
  135.                 return IvaPurposeEnum::Iva;
  136.             }
  137.         }
  138.     }
  139. }