vendor/crosiersource/crosierlib-radx/src/Entity/Fiscal/DistDFe.php line 50

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibRadxBundle\Entity\Fiscal;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\EntityHandler;
  9. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\NotUppercase;
  10. use CrosierSource\CrosierLibBaseBundle\Entity\EntityId;
  11. use CrosierSource\CrosierLibBaseBundle\Entity\EntityIdTrait;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use SimpleXMLElement;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. /**
  16.  * @ApiResource(
  17.  *     normalizationContext={"groups"={"distDFe","entityId"},"enable_max_depth"=true},
  18.  *     denormalizationContext={"groups"={"distDFe"},"enable_max_depth"=true},
  19.  *
  20.  *     itemOperations={
  21.  *          "get"={"path"="/fis/distDFe/{id}", "security"="is_granted('ROLE_FISCAL')"},
  22.  *          "put"={"path"="/fis/distDFe/{id}", "security"="is_granted('ROLE_FISCAL')"},
  23.  *          "delete"={"path"="/fis/distDFe/{id}", "security"="is_granted('ROLE_ADMIN')"}
  24.  *     },
  25.  *     collectionOperations={
  26.  *          "get"={"path"="/fis/distDFe", "security"="is_granted('ROLE_FISCAL')"},
  27.  *          "post"={"path"="/fis/distDFe", "security"="is_granted('ROLE_FISCAL')"}
  28.  *     },
  29.  *
  30.  *     attributes={
  31.  *          "pagination_items_per_page"=10,
  32.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  33.  *     }
  34.  * )
  35.  * @ApiFilter(PropertyFilter::class)
  36.  *
  37.  * @ApiFilter(SearchFilter::class, properties={"nome": "partial", "documento": "exact", "id": "exact"})
  38.  * @ApiFilter(OrderFilter::class, properties={"id", "documento", "nome", "updated"}, arguments={"orderParameterName"="order"})
  39.  *
  40.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibRadxBundle\EntityHandler\Fiscal\DistDFeEntityHandler")
  41.  *
  42.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibRadxBundle\Repository\Fiscal\DistDFeRepository")
  43.  * @ORM\Table(name="fis_distdfe")
  44.  *
  45.  * @author Carlos Eduardo Pauluk
  46.  */
  47. class DistDFe implements EntityId
  48. {
  49.     use EntityIdTrait;
  50.     /**
  51.      *
  52.      * @ORM\Column(name="documento", type="string")
  53.      * @var null|string
  54.      * @Groups("distDFe")
  55.      */
  56.     public ?string $documento null;
  57.     /**
  58.      *
  59.      * @ORM\Column(name="tipo_distdfe", type="string")
  60.      * @var null|string
  61.      * @Groups("distDFe")
  62.      */
  63.     public ?string $tipoDistDFe null;
  64.     /**
  65.      * Se é referente a um DF próprio.
  66.      *
  67.      * @ORM\Column(name="proprio", type="boolean")
  68.      * @var null|bool
  69.      * @Groups("distDFe")
  70.      */
  71.     public ?bool $proprio null;
  72.     /**
  73.      *
  74.      * @ORM\Column(name="chnfe", type="string", length=44)
  75.      * @var null|string
  76.      * @Groups("distDFe")
  77.      */
  78.     public ?string $chave null;
  79.     /**
  80.      *
  81.      * @ORM\Column(name="tp_evento", type="integer")
  82.      * @var null|int
  83.      * @Groups("distDFe")
  84.      */
  85.     public ?int $tpEvento null;
  86.     /**
  87.      *
  88.      * @ORM\Column(name="nseq_evento", type="integer")
  89.      * @var null|int
  90.      * @Groups("distDFe")
  91.      */
  92.     public ?int $nSeqEvento null;
  93.     /**
  94.      *
  95.      * @ORM\Column(name="nsu", type="bigint", nullable=false)
  96.      * @var null|int
  97.      * @Groups("distDFe")
  98.      */
  99.     public ?int $nsu null;
  100.     /**
  101.      *
  102.      * @ORM\Column(name="xml", type="string")
  103.      * @var null|string
  104.      *
  105.      * @NotUppercase()
  106.      */
  107.     public ?string $xml null;
  108.     /**
  109.      *
  110.      * @ORM\Column(name="status", length=255, type="string")
  111.      * @var null|string
  112.      * @Groups("distDFe")
  113.      * @NotUppercase()
  114.      */
  115.     public ?string $status null;
  116.     /**
  117.      *
  118.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Fiscal\NotaFiscal")
  119.      * @ORM\JoinColumn(name="nota_fiscal_id")
  120.      *
  121.      * @var $notaFiscal null|NotaFiscal
  122.      */
  123.     public ?NotaFiscal $notaFiscal null;
  124.     /**
  125.      *
  126.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Fiscal\NotaFiscalEvento")
  127.      * @ORM\JoinColumn(name="nota_fiscal_evento_id")
  128.      *
  129.      * @var $notaFiscalEvento null|NotaFiscalEvento
  130.      */
  131.     public ?NotaFiscalEvento $notaFiscalEvento null;
  132.     /**
  133.      * @return SimpleXMLElement|null
  134.      */
  135.     public function getXMLDecoded(): ?SimpleXMLElement
  136.     {
  137.         if ($this->xml && $this->xml !== 'Nenhum documento localizado') {
  138.             $xmlUnzip gzdecode(base64_decode($this->xml));
  139.             return simplexml_load_string($xmlUnzip);
  140.         }
  141.         return null;
  142.     }
  143.     
  144.     public function getXMLDecodedAsString(): ?string
  145.     {
  146.         if ($this->xml && $this->xml !== 'Nenhum documento localizado') {
  147.             return gzdecode(base64_decode($this->xml));
  148.         }
  149.         return null;
  150.     }
  151.     /**
  152.      * Transient.
  153.      * Para não precisar retornar toda a notaFiscal como JSON para o list.
  154.      *
  155.      * @Groups("distDFe")
  156.      */
  157.     public function getNotaFiscalId(): ?int
  158.     {
  159.         return isset($this->notaFiscal) && $this->notaFiscal->getId() ? $this->notaFiscal->getId() : null;
  160.     }
  161.     /**
  162.      * Transient.
  163.      * Para não precisar retornar toda o notaFiscalEvento como JSON para o list.
  164.      *
  165.      * @Groups("distDFe")
  166.      */
  167.     public function getEventoId(): ?int
  168.     {
  169.         return isset($this->notaFiscalEvento) && $this->notaFiscalEvento->getId() ? $this->notaFiscalEvento->getId() : null;
  170.     }
  171. }