src/Entity/Tax.php line 32

  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 ApiPlatform\Metadata\ApiResource;
  9. use ApiPlatform\Metadata\Get;
  10. use ApiPlatform\Metadata\GetCollection;
  11. use App\Repository\TaxRepository;
  12. use Doctrine\DBAL\Types\Types;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. use Symfony\Component\Validator\Constraints\NotNull;
  18. #[ORM\Entity(repositoryClassTaxRepository::class)]
  19. #[ApiResource(
  20.     normalizationContext: ['groups' => ['tax_out']], denormalizationContext: ['groups' => ['tax_in']],
  21. //    security: "is_granted('View', object)"
  22.     security"is_granted('ROLE_USER')"
  23. )]
  24. //#[Post(processor: CurrentCompanyStateProcesor::class)]
  25. #[Get]
  26. #[GetCollection]
  27. //#[Put]
  28. //#[Delete]
  29. class Tax
  30. {
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     #[Groups(['tax_out'])]
  35.     private ?int $id null;
  36.     #[ORM\Column(length20)]
  37.     #[NotBlank]
  38.     #[Groups(['tax_out''tax_in'])]
  39.     private ?string $name null;
  40.     #[ORM\Column(typeTypes::DECIMALprecision10scale2)]
  41.     #[NotNull]
  42.     #[GreaterThanOrEqual(0)]
  43.     #[Groups(['tax_out''tax_in'])]
  44.     private ?string $amount null;
  45.     #[ORM\ManyToOne(inversedBy'taxes')]
  46.     #[ORM\JoinColumn(nullabletrue)]
  47.     private ?SriInfo $sriInfo null;
  48.     #[ORM\Column(length20nullabletrue)]
  49.     private ?string $externalId null;
  50.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  51.     private ?\DateTimeInterface $validUntil null;
  52.     #[ORM\Column(nullabletrue)]
  53.     private ?bool $isDefault null;
  54.     #[ORM\Column(length3nullabletrue)]
  55.     private ?string $iAfecIVA null;
  56.     #[ORM\Column(nullabletrue)]
  57.     private ?float $dPropIVA null;
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getName(): ?string
  63.     {
  64.         return $this->name;
  65.     }
  66.     public function setName(string $name): self
  67.     {
  68.         $this->name $name;
  69.         return $this;
  70.     }
  71.     public function getAmount(): ?string
  72.     {
  73.         return $this->amount;
  74.     }
  75.     public function setAmount(string $amount): self
  76.     {
  77.         $this->amount $amount;
  78.         return $this;
  79.     }
  80.     public function getSriInfo(): ?SriInfo
  81.     {
  82.         return $this->sriInfo;
  83.     }
  84.     public function setSriInfo(?SriInfo $sriInfo): self
  85.     {
  86.         $this->sriInfo $sriInfo;
  87.         return $this;
  88.     }
  89.     public function getExternalId(): ?string
  90.     {
  91.         return $this->externalId;
  92.     }
  93.     public function setExternalId(?string $externalId): static
  94.     {
  95.         $this->externalId $externalId;
  96.         return $this;
  97.     }
  98.     public function getValidUntil(): ?\DateTimeInterface
  99.     {
  100.         return $this->validUntil;
  101.     }
  102.     public function setValidUntil(?\DateTimeInterface $validUntil): static
  103.     {
  104.         $this->validUntil $validUntil;
  105.         return $this;
  106.     }
  107.     public function computeTax(?\DateTime $date): ?string
  108.     {
  109.         if ($date == null || $this->validUntil === null || $this->validUntil >= $date) {
  110.             return $this->getAmount();
  111.         }
  112.         foreach ($this->getTaxRanges() as $taxRange) {
  113.             if ($taxRange->getValidFrom() <= $date && ($taxRange->getValidTo() === null || $date <= $taxRange->getValidTo())) {
  114.                 return $taxRange->getValue();
  115.             }
  116.         }
  117.         return null;
  118.     }
  119.     public function isIsDefault(): ?bool
  120.     {
  121.         return $this->isDefault;
  122.     }
  123.     public function setIsDefault(?bool $isDefault): static
  124.     {
  125.         $this->isDefault $isDefault;
  126.         return $this;
  127.     }
  128.     public function getCode(): ?int
  129.     {
  130.         return $this->code;
  131.     }
  132.     public function setCode(?int $code): static
  133.     {
  134.         $this->code $code;
  135.         return $this;
  136.     }
  137.     public function getIAfecIVA(): ?string
  138.     {
  139.         return $this->iAfecIVA;
  140.     }
  141.     public function setIAfecIVA(?string $iAfecIVA): static
  142.     {
  143.         $this->iAfecIVA $iAfecIVA;
  144.         return $this;
  145.     }
  146.     public function getDPropIVA(): ?float
  147.     {
  148.         return $this->dPropIVA;
  149.     }
  150.     public function setDPropIVA(?float $dPropIVA): static
  151.     {
  152.         $this->dPropIVA $dPropIVA;
  153.         return $this;
  154.     }
  155. }