vendor/crosiersource/crosierlib-radx/src/Entity/Fiscal/NotaFiscal.php line 91

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\BooleanFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\EntityHandler;
  11. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\NotUppercase;
  12. use CrosierSource\CrosierLibBaseBundle\Entity\EntityId;
  13. use CrosierSource\CrosierLibBaseBundle\Entity\EntityIdTrait;
  14. use CrosierSource\CrosierLibBaseBundle\Utils\StringUtils\StringUtils;
  15. use DateTime;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use SimpleXMLElement;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Serializer\Annotation\SerializedName;
  21. use Symfony\Component\Validator\Constraints as Assert;
  22. use Throwable;
  23. /**
  24.  * Entidade Nota Fiscal.
  25.  *
  26.  * @ApiResource(
  27.  *     normalizationContext={"groups"={"notaFiscal","entityId"},"enable_max_depth"=true},
  28.  *     denormalizationContext={"groups"={"notaFiscal"},"enable_max_depth"=true},
  29.  *
  30.  *     itemOperations={
  31.  *          "get"={"path"="/fis/notaFiscal/{id}", "security"="is_granted('ROLE_FISCAL')"},
  32.  *          "put"={"path"="/fis/notaFiscal/{id}", "security"="is_granted('ROLE_FISCAL')"},
  33.  *          "delete"={"path"="/fis/notaFiscal/{id}", "security"="is_granted('ROLE_ADMIN')"}
  34.  *     },
  35.  *     collectionOperations={
  36.  *          "get"={"path"="/fis/notaFiscal", "security"="is_granted('ROLE_FISCAL')"},
  37.  *          "post"={"path"="/fis/notaFiscal", "security"="is_granted('ROLE_FISCAL')"}
  38.  *     },
  39.  *
  40.  *     attributes={
  41.  *          "pagination_items_per_page"=10,
  42.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  43.  *     }
  44.  * )
  45.  * @ApiFilter(PropertyFilter::class)
  46.  *
  47.  * @ApiFilter(SearchFilter::class, properties={
  48.  *     "documentoEmitente": "exact",
  49.  *     "xNomeEmitente": "partial",
  50.  *     "documentoDestinatario": "exact",
  51.  *     "xNomeDestinatario": "partial",
  52.  *     "chaveAcesso": "exact",
  53.  *     "numero": "exact",
  54.  *     "serie": "exact",
  55.  *     "cidadeEmitente": "partial",
  56.  *     "cidadeDestinatario": "partial",
  57.  *     "valorTotal": "exact",
  58.  *     "nsu": "exact",
  59.  *     "manifestDest": "exact",
  60.  *     "entradaSaida": "exact",
  61.  *     "id": "exact"
  62.  * })
  63.  *
  64.  * @ApiFilter(DateFilter::class, properties={"dtEmissao"})
  65.  *
  66.  * @ApiFilter(BooleanFilter::class, properties={"resumo"})
  67.  *
  68.  * ApiFilter(NotLikeFilter::class, properties={"documentoDestinatario"})
  69.  *
  70.  * @ApiFilter(OrderFilter::class, properties={
  71.  *     "id",
  72.  *     "numero",
  73.  *     "documentoDestinatario",
  74.  *     "valorTotal",
  75.  *     "dtEmissao",
  76.  *     "updated",
  77.  *     "cStat"
  78.  * }, arguments={"orderParameterName"="order"})
  79.  *
  80.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibRadxBundle\EntityHandler\Fiscal\NotaFiscalEntityHandler")
  81.  *
  82.  *
  83.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibRadxBundle\Repository\Fiscal\NotaFiscalRepository")
  84.  * @ORM\Table(name="fis_nf")
  85.  *
  86.  * @author Carlos Eduardo Pauluk
  87.  */
  88. class NotaFiscal implements EntityId
  89. {
  90.     use EntityIdTrait;
  91.     /**
  92.      * @ORM\Column(name="uuid", type="string", nullable=true, length=32)
  93.      * @var null|string
  94.      * @NotUppercase()
  95.      * @Groups("notaFiscal")
  96.      */
  97.     public ?string $uuid null;
  98.     /**
  99.      * @ORM\Column(name="ambiente", type="string", nullable=true, length=4)
  100.      * @Groups("notaFiscal")
  101.      * @var null|string
  102.      */
  103.     public ?string $ambiente null;
  104.     /**
  105.      * Número randômico utilizado na geração do nome do arquivo XML, para poder saber qual foi o nome do último arquivo gerado, evitando duplicidades.
  106.      * @ORM\Column(name="rand_faturam", type="string", nullable=true)
  107.      * @var null|string
  108.      */
  109.     public ?string $randFaturam null;
  110.     /**
  111.      * $cNF = rand(10000000, 99999999);
  112.      * @ORM\Column(name="cnf", type="string", nullable=true, length=8)
  113.      * @Groups("notaFiscal")
  114.      * @var null|string
  115.      */
  116.     public ?string $cnf null;
  117.     /**
  118.      * @ORM\Column(name="natureza_operacao", type="string", nullable=true, length=60)
  119.      * @Groups("notaFiscal")
  120.      * @var null|string
  121.      */
  122.     public ?string $naturezaOperacao null;
  123.     /**
  124.      * @ORM\Column(name="finalidade_nf", type="string", nullable=false, length=30)
  125.      * @var null|string
  126.      * @Groups("notaFiscal")
  127.      */
  128.     public ?string $finalidadeNf null;
  129.     /**
  130.      * @ORM\Column(name="chave_acesso", type="string", nullable=true, length=44)
  131.      * @Groups("notaFiscal")
  132.      * @var null|string
  133.      */
  134.     public ?string $chaveAcesso null;
  135.     /**
  136.      * @ORM\Column(name="protocolo_autoriz", type="string", nullable=true, length=255)
  137.      * @var null|string
  138.      * @Groups("notaFiscal")
  139.      */
  140.     public ?string $protocoloAutorizacao null;
  141.     /**
  142.      * @ORM\Column(name="dt_protocolo_autoriz", type="datetime", nullable=true)
  143.      * @var null|DateTime
  144.      * @Groups("notaFiscal")
  145.      */
  146.     public ?DateTime $dtProtocoloAutorizacao null;
  147.     /**
  148.      * @ORM\Column(name="dt_emissao", type="datetime", nullable=true)
  149.      * @var null|DateTime
  150.      * @Groups("notaFiscal")
  151.      */
  152.     public ?DateTime $dtEmissao null;
  153.     /**
  154.      * @ORM\Column(name="dt_saient", type="datetime", nullable=true)
  155.      * @var null|DateTime
  156.      * @Groups("notaFiscal")
  157.      */
  158.     public ?DateTime $dtSaiEnt null;
  159.     /**
  160.      * @ORM\Column(name="numero", type="integer", nullable=false)
  161.      * @var null|int
  162.      * @Groups("notaFiscal")
  163.      */
  164.     public ?int $numero null;
  165.     /**
  166.      * @ORM\Column(name="serie", type="integer", nullable=false)
  167.      * @var null|int
  168.      * @Groups("notaFiscal")
  169.      */
  170.     public ?int $serie null;
  171.     /**
  172.      * @ORM\Column(name="tipo", type="string", nullable=true, length=30)
  173.      * @var null|string
  174.      * @Groups("notaFiscal")
  175.      */
  176.     public ?string $tipoNotaFiscal null;
  177.     /**
  178.      * @ORM\Column(name="entrada_saida", nullable=false)
  179.      * @var null|string
  180.      * @Groups("notaFiscal")
  181.      */
  182.     public ?string $entradaSaida null;
  183.     /**
  184.      * @ORM\Column(name="documento_emitente", type="string", nullable=false)
  185.      * @var null|string
  186.      * @Groups("notaFiscal")
  187.      */
  188.     public ?string $documentoEmitente null;
  189.     /**
  190.      * @ORM\Column(name="xnome_emitente", type="string", nullable=false)
  191.      * @var null|string
  192.      * @Groups("notaFiscal")
  193.      */
  194.     public ?string $xNomeEmitente null;
  195.     /**
  196.      * @ORM\Column(name="inscr_est_emitente", type="string", nullable=true)
  197.      * @var null|string
  198.      * @Groups("notaFiscal")
  199.      */
  200.     public ?string $inscricaoEstadualEmitente null;
  201.     /**
  202.      * @ORM\Column(name="cep_emitente", type="string", nullable=true, length=9)
  203.      * @var string|null
  204.      * @Groups("notaFiscal")
  205.      */
  206.     public ?string $cepEmitente null;
  207.     /**
  208.      * @ORM\Column(name="logradouro_emitente", type="string", nullable=true, length=200)
  209.      * @var string|null
  210.      * @Groups("notaFiscal")
  211.      */
  212.     public ?string $logradouroEmitente null;
  213.     /**
  214.      * @ORM\Column(name="numero_emitente", type="string", nullable=true, length=200)
  215.      * @var string|null
  216.      * @Groups("notaFiscal")
  217.      */
  218.     public ?string $numeroEmitente null;
  219.     /**
  220.      * @ORM\Column(name="complemento_emitente", type="string", nullable=true, length=60)
  221.      * @var string|null
  222.      * @Groups("notaFiscal")
  223.      */
  224.     public ?string $complementoEmitente null;
  225.     /**
  226.      * @ORM\Column(name="fone_emitente", type="string", nullable=true, length=50)
  227.      * @var string|null
  228.      * @Groups("notaFiscal")
  229.      */
  230.     public ?string $foneEmitente null;
  231.     /**
  232.      * @ORM\Column(name="bairro_emitente", type="string", nullable=true, length=120)
  233.      * @var string|null
  234.      * @Groups("notaFiscal")
  235.      */
  236.     public ?string $bairroEmitente null;
  237.     /**
  238.      * @ORM\Column(name="cidade_emitente", type="string", nullable=true, length=120)
  239.      * @var string|null
  240.      * @Groups("notaFiscal")
  241.      */
  242.     public ?string $cidadeEmitente null;
  243.     /**
  244.      * @ORM\Column(name="estado_emitente", type="string", nullable=true, length=2)
  245.      * @var string|null
  246.      * @Groups("notaFiscal")
  247.      */
  248.     public ?string $estadoEmitente null;
  249.     /**
  250.      * @ORM\Column(name="documento_destinatario", type="string", nullable=false)
  251.      * @var null|string
  252.      * @Groups("notaFiscal")
  253.      */
  254.     public ?string $documentoDestinatario null;
  255.     /**
  256.      * @ORM\Column(name="xnome_destinatario", type="string", nullable=false)
  257.      * @var null|string
  258.      * @Groups("notaFiscal")
  259.      */
  260.     public ?string $xNomeDestinatario null;
  261.     /**
  262.      * @ORM\Column(name="inscr_est", type="string", nullable=false)
  263.      * @var null|string
  264.      * @Groups("notaFiscal")
  265.      */
  266.     public ?string $inscricaoEstadualDestinatario null;
  267.     /**
  268.      * @ORM\Column(name="logradouro_destinatario", type="string", nullable=true, length=200)
  269.      * @var string|null
  270.      * @Groups("notaFiscal")
  271.      */
  272.     public ?string $logradouroDestinatario null;
  273.     /**
  274.      * @ORM\Column(name="numero_destinatario", type="string", nullable=true, length=200)
  275.      * @var string|null
  276.      * @Groups("notaFiscal")
  277.      */
  278.     public ?string $numeroDestinatario null;
  279.     /**
  280.      * @ORM\Column(name="complemento_destinatario", type="string", nullable=true, length=60)
  281.      * @var string|null
  282.      * @Groups("notaFiscal")
  283.      */
  284.     public ?string $complementoDestinatario null;
  285.     /**
  286.      * @ORM\Column(name="bairro_destinatario", type="string", nullable=true, length=120)
  287.      * @var string|null
  288.      * @Groups("notaFiscal")
  289.      */
  290.     public ?string $bairroDestinatario null;
  291.     /**
  292.      * @ORM\Column(name="cidade_destinatario", type="string", nullable=true, length=120)
  293.      * @var string|null
  294.      * @Groups("notaFiscal")
  295.      */
  296.     public ?string $cidadeDestinatario null;
  297.     /**
  298.      * @ORM\Column(name="estado_destinatario", type="string", nullable=true, length=2)
  299.      * @var string|null
  300.      * @Groups("notaFiscal")
  301.      */
  302.     public ?string $estadoDestinatario null;
  303.     /**
  304.      * @ORM\Column(name="cep_destinatario", type="string", nullable=true, length=9)
  305.      * @var string|null
  306.      * @Groups("notaFiscal")
  307.      */
  308.     public ?string $cepDestinatario null;
  309.     /**
  310.      * @ORM\Column(name="fone_destinatario", type="string", nullable=true, length=50)
  311.      * @var string|null
  312.      * @Groups("notaFiscal")
  313.      */
  314.     public ?string $foneDestinatario null;
  315.     /**
  316.      * @ORM\Column(name="email_destinatario", type="string", nullable=true, length=200)
  317.      * @var string|null
  318.      * @Groups("notaFiscal")
  319.      */
  320.     public ?string $emailDestinatario null;
  321.     /**
  322.      * @ORM\Column(name="motivo_cancelamento", type="string", nullable=true, length=3000)
  323.      * @var null|string
  324.      * @Groups("notaFiscal")
  325.      */
  326.     public ?string $motivoCancelamento null;
  327.     /**
  328.      * @ORM\Column(name="info_compl", type="string", nullable=true, length=3000)
  329.      * @var null|string
  330.      * @Groups("notaFiscal")
  331.      */
  332.     public ?string $infoCompl null;
  333.     /**
  334.      * @ORM\Column(name="total_descontos", type="decimal", nullable=false, precision=15, scale=2)
  335.      * @Groups("N")
  336.      * @Assert\Type(type="string")
  337.      */
  338.     public ?string $totalDescontos null;
  339.     /**
  340.      * @ORM\Column(name="subtotal", type="decimal", nullable=false, precision=15, scale=2)
  341.      * @Groups("N")
  342.      * @Assert\Type(type="string")
  343.      */
  344.     public ?string $subtotal null;
  345.     /**
  346.      * @ORM\Column(name="valor_total", type="decimal", nullable=false, precision=15, scale=2)
  347.      * @Groups("N")
  348.      * @Assert\Type(type="string")
  349.      */
  350.     public ?string $valorTotal null;
  351.     /**
  352.      * @ORM\Column(name="transp_documento", type="string", nullable=true)
  353.      * @var null|string
  354.      * @Groups("notaFiscal")
  355.      */
  356.     public ?string $transpDocumento null;
  357.     /**
  358.      * @ORM\Column(name="transp_nome", type="string", nullable=true)
  359.      * @var null|string
  360.      * @Groups("notaFiscal")
  361.      */
  362.     public ?string $transpNome null;
  363.     /**
  364.      * @ORM\Column(name="transp_inscr_est", type="string", nullable=true)
  365.      * @var null|string
  366.      * @Groups("notaFiscal")
  367.      */
  368.     public ?string $transpInscricaoEstadual null;
  369.     /**
  370.      * @ORM\Column(name="transp_endereco", type="string", nullable=true)
  371.      * @var null|string
  372.      * @Groups("notaFiscal")
  373.      */
  374.     public ?string $transpEndereco null;
  375.     /**
  376.      * @ORM\Column(name="transp_cidade", type="string", nullable=true, length=120)
  377.      * @var string|null
  378.      * @Groups("notaFiscal")
  379.      */
  380.     public ?string $transpCidade null;
  381.     /**
  382.      * @ORM\Column(name="transp_estado", type="string", nullable=true, length=2)
  383.      * @var string|null
  384.      * @Groups("notaFiscal")
  385.      */
  386.     public ?string $transpEstado null;
  387.     /**
  388.      * @ORM\Column(name="transp_especie_volumes", type="string", nullable=true, length=200)
  389.      * @var null|string
  390.      * @Groups("notaFiscal")
  391.      */
  392.     public ?string $transpEspecieVolumes null;
  393.     /**
  394.      * @ORM\Column(name="transp_marca_volumes", type="string", nullable=true, length=200)
  395.      * @var null|string
  396.      * @Groups("notaFiscal")
  397.      */
  398.     public ?string $transpMarcaVolumes null;
  399.     /**
  400.      * @ORM\Column(name="transp_modalidade_frete", type="string", nullable=false, length=30)
  401.      * @var null|string
  402.      * @Groups("notaFiscal")
  403.      */
  404.     public ?string $transpModalidadeFrete null;
  405.     /**
  406.      * @ORM\Column(name="transp_numeracao_volumes", type="string", nullable=true, length=200)
  407.      * @var null|string
  408.      * @Groups("notaFiscal")
  409.      */
  410.     public ?string $transpNumeracaoVolumes null;
  411.     /**
  412.      * @ORM\Column(name="transp_peso_bruto", type="decimal", nullable=true, precision=15, scale=2)
  413.      * @Groups("N")
  414.      * @Assert\Type(type="string")
  415.      */
  416.     public ?string $transpPesoBruto null;
  417.     /**
  418.      * @ORM\Column(name="transp_peso_liquido", type="decimal", nullable=true, precision=15, scale=2)
  419.      * @Groups("N")
  420.      * @Assert\Type(type="string")
  421.      */
  422.     public ?string $transpPesoLiquido null;
  423.     /**
  424.      * @ORM\Column(name="transp_qtde_volumes", type="decimal", nullable=true, precision=15, scale=2)
  425.      * @Groups("N")
  426.      * @Assert\Type(type="string")
  427.      */
  428.     public ?string $transpQtdeVolumes null;
  429.     /**
  430.      * @ORM\Column(name="transp_valor_total_frete", type="decimal", nullable=true, precision=15, scale=2)
  431.      * @Groups("N")
  432.      * @Assert\Type(type="string")
  433.      */
  434.     public ?string $transpValorTotalFrete null;
  435.     /**
  436.      * @ORM\Column(name="indicador_forma_pagto", type="string", nullable=false, length=30)
  437.      * @var null|string
  438.      * @Groups("notaFiscal")
  439.      */
  440.     public ?string $indicadorFormaPagto null;
  441.     /**
  442.      * @ORM\Column(name="a03id_nf_referenciada", type="string", nullable=true, length=100)
  443.      * @var null|string
  444.      * @Groups("notaFiscal")
  445.      */
  446.     public ?string $a03idNfReferenciada null;
  447.     /**
  448.      * @ORM\Column(name="xml_nota", type="string", nullable=true)
  449.      * @var null|string
  450.      * @NotUppercase()
  451.      */
  452.     private ?string $xmlNota null;
  453.     /**
  454.      * Informa se o XML é de um resumo <resNFe> (ainda não foi baixada o XML da nota completa).
  455.      * @ORM\Column(name="resumo", type="boolean", nullable=true)
  456.      * @var null|bool
  457.      * @Groups("notaFiscal")
  458.      */
  459.     public ?bool $resumo null;
  460.     /**
  461.      * @ORM\Column(name="nrec", type="string", length=30, nullable=true)
  462.      * @var null|string
  463.      */
  464.     public ?string $nRec null;
  465.     /**
  466.      * @ORM\Column(name="cstat_lote", type="integer", nullable=true)
  467.      * @var null|string
  468.      * @Groups("notaFiscal")
  469.      */
  470.     public ?string $cStatLote null;
  471.     /**
  472.      * @ORM\Column(name="xmotivo_lote", type="string", length=255, nullable=true)
  473.      * @var null|string
  474.      * @Groups("notaFiscal")
  475.      */
  476.     public ?string $xMotivoLote null;
  477.     /**
  478.      * @ORM\Column(name="cstat", type="integer", nullable=true)
  479.      * @var null|int
  480.      * @Groups("notaFiscal")
  481.      */
  482.     public ?int $cStat null;
  483.     /**
  484.      * @ORM\Column(name="xmotivo", type="string", length=255, nullable=true)
  485.      * @var null|string
  486.      * @Groups("notaFiscal")
  487.      */
  488.     public ?string $xMotivo null;
  489.     /**
  490.      * @ORM\Column(name="manifest_dest", type="string", length=255, nullable=true)
  491.      * @var null|string
  492.      * @Groups("notaFiscal")
  493.      */
  494.     public ?string $manifestDest null;
  495.     /**
  496.      * Informa quando foi alterado o status do último $manifestDest.
  497.      * @ORM\Column(name="dt_manifest_dest", type="datetime", nullable=true)
  498.      * @var null|DateTime
  499.      * @Groups("notaFiscal")
  500.      */
  501.     public ?DateTime $dtManifestDest null;
  502.     /**
  503.      * @ORM\Column(name="nsu", type="integer", nullable=false)
  504.      * @var null|int
  505.      * @Groups("notaFiscal")
  506.      */
  507.     public ?int $nsu null;
  508.     /**
  509.      * @ORM\Column(name="json_data", type="json")
  510.      * @var null|array
  511.      * @NotUppercase()
  512.      * @Groups("notaFiscal")
  513.      */
  514.     public ?array $jsonData null;
  515.     /**
  516.      * Transient (ver getters e setters).
  517.      * @var int|null
  518.      * @Groups("notaFiscal")
  519.      */
  520.     private ?int $idDest null;
  521.     /**
  522.      * @var NotaFiscalItem[]|ArrayCollection
  523.      * @ORM\OneToMany(
  524.      *      targetEntity="NotaFiscalItem",
  525.      *      mappedBy="notaFiscal"
  526.      * )
  527.      * @ORM\OrderBy({"ordem" = "ASC"})
  528.      */
  529.     public $itens;
  530.     /**
  531.      * @var NotaFiscalEvento[]|ArrayCollection
  532.      * @ORM\OneToMany(
  533.      *      targetEntity="NotaFiscalEvento",
  534.      *      cascade={"all"},
  535.      *      mappedBy="notaFiscal",
  536.      *      orphanRemoval=true
  537.      * )
  538.      */
  539.     public $eventos;
  540.     /**
  541.      * @var NotaFiscalCartaCorrecao[]|ArrayCollection
  542.      * @ORM\OneToMany(
  543.      *      targetEntity="NotaFiscalCartaCorrecao",
  544.      *      cascade={"all"},
  545.      *      mappedBy="notaFiscal",
  546.      *      orphanRemoval=true
  547.      * )
  548.      */
  549.     public $cartasCorrecao;
  550.     /**
  551.      * @var NotaFiscalHistorico[]|ArrayCollection
  552.      * @ORM\OneToMany(
  553.      *      targetEntity="NotaFiscalHistorico",
  554.      *      cascade={"all"},
  555.      *      mappedBy="notaFiscal",
  556.      *      orphanRemoval=true
  557.      * )
  558.      */
  559.     public $historicos;
  560.     public function __construct()
  561.     {
  562.         $this->itens = new ArrayCollection();
  563.         $this->eventos = new ArrayCollection();
  564.         $this->historicos = new ArrayCollection();
  565.     }
  566.     /**
  567.      * @return NotaFiscalItem[]|ArrayCollection
  568.      */
  569.     public function getItens()
  570.     {
  571.         return $this->itens;
  572.     }
  573.     /**
  574.      * @param NotaFiscalItem[]|ArrayCollection $itens
  575.      * @return NotaFiscal
  576.      */
  577.     public function setItens($itens): NotaFiscal
  578.     {
  579.         $this->itens $itens;
  580.         return $this;
  581.     }
  582.     public function deleteAllItens(): NotaFiscal
  583.     {
  584.         if ($this->itens) {
  585.             foreach ($this->itens as $item) {
  586.                 $item->notaFiscal null;
  587.             }
  588.             $this->itens->clear();
  589.         }
  590.         return $this;
  591.     }
  592.     /**
  593.      * @return NotaFiscalEvento[]|ArrayCollection
  594.      */
  595.     public function getEventos()
  596.     {
  597.         return $this->eventos;
  598.     }
  599.     /**
  600.      * @param NotaFiscalEvento[]|ArrayCollection $eventos
  601.      * @return NotaFiscal
  602.      */
  603.     public function setEventos($eventos): NotaFiscal
  604.     {
  605.         $this->eventos $eventos;
  606.         return $this;
  607.     }
  608.     /**
  609.      * @param NotaFiscalItem $item
  610.      */
  611.     public function addItem(NotaFiscalItem $item): void
  612.     {
  613.         if (!$this->itens->contains($item)) {
  614.             $this->itens->add($item);
  615.             $item->notaFiscal $this;
  616.         }
  617.     }
  618.     /**
  619.      * @return NotaFiscalCartaCorrecao[]|ArrayCollection
  620.      */
  621.     public function getCartasCorrecao()
  622.     {
  623.         return $this->cartasCorrecao;
  624.     }
  625.     /**
  626.      * @param NotaFiscalCartaCorrecao[]|ArrayCollection $cartaCorrecaos
  627.      * @return NotaFiscal
  628.      */
  629.     public function setCartasCorrecao($cartaCorrecaos): NotaFiscal
  630.     {
  631.         $this->cartasCorrecao $cartaCorrecaos;
  632.         return $this;
  633.     }
  634.     /**
  635.      * @param NotaFiscalCartaCorrecao $cartaCorrecao
  636.      */
  637.     public function addCartaCorrecao(NotaFiscalCartaCorrecao $cartaCorrecao): void
  638.     {
  639.         if (!$this->cartasCorrecao->contains($cartaCorrecao)) {
  640.             $this->cartasCorrecao->add($cartaCorrecao);
  641.         }
  642.     }
  643.     /**
  644.      * @return NotaFiscalHistorico[]|ArrayCollection
  645.      */
  646.     public function getHistoricos()
  647.     {
  648.         return $this->historicos;
  649.     }
  650.     /**
  651.      * @param NotaFiscalHistorico[]|ArrayCollection $historicos
  652.      * @return NotaFiscal
  653.      */
  654.     public function setHistoricos($historicos): NotaFiscal
  655.     {
  656.         $this->historicos $historicos;
  657.         return $this;
  658.     }
  659.     /**
  660.      * @param NotaFiscalHistorico $historico
  661.      */
  662.     public function addHistorico(NotaFiscalHistorico $historico): void
  663.     {
  664.         if (!$this->historicos->contains($historico)) {
  665.             $this->historicos->add($historico);
  666.         }
  667.     }
  668.     /**
  669.      * @return string
  670.      * @SerializedName("infoStatus")
  671.      * @Groups("notaFiscal")
  672.      */
  673.     public function getInfoStatus(): string
  674.     {
  675.         $infoStatus '';
  676.         if ($this->cStat) {
  677.             $infoStatus .= $this->cStat ' - ' $this->xMotivo;
  678.         }
  679.         if ($this->cStatLote) {
  680.             $infoStatus .= ' (' $this->cStatLote ' - ' $this->xMotivoLote ')';
  681.         }
  682.         if ($this->ambiente === 'HOM') {
  683.             $infoStatus .= ' *** EMITIDA EM HOMOLOGAÇÃO';
  684.         }
  685.         return $infoStatus ?: 'SEM STATUS';
  686.     }
  687.     /**
  688.      * @return SimpleXMLElement|null
  689.      */
  690.     public function getXMLDecoded(): ?SimpleXMLElement
  691.     {
  692.         $xmlDecodedAsString $this->getXMLDecodedAsString();
  693.         if ($xmlDecodedAsString) {
  694.             $r simplexml_load_string($xmlDecodedAsString);
  695.             return ($r === null || $r instanceof SimpleXMLElement) ? $r null;
  696.         } else {
  697.             return null;
  698.         }
  699.     }
  700.     /**
  701.      * @Groups("notaFiscal")
  702.      * @return bool
  703.      */
  704.     public function isPossuiXml(): bool
  705.     {
  706.         return $this->xmlNota !== null;
  707.     }
  708.     /**
  709.      * @Groups("notaFiscal")
  710.      * @return bool
  711.      */
  712.     public function isPossuiXmlAssinado(): bool
  713.     {
  714.         return $this->xmlNota !== null && $this->getXMLDecoded()->getName() === 'nfeProc';
  715.     }
  716.     /**
  717.      * @return string|null
  718.      */
  719.     public function getXMLDecodedAsString(): ?string
  720.     {
  721.         if ($this->xmlNota) {
  722.             try {
  723.                 // No PHP 7.4.25 não estava gerando exceção, apenas warning e retornando vazio
  724.                 $decoded = @gzdecode(@base64_decode($this->xmlNota));
  725.                 return $decoded ?: $this->xmlNota;
  726.             } catch (Throwable $e) {
  727.                 // Caso não tenha conseguido decodificar...
  728.                 return $this->xmlNota;
  729.             }
  730.         } else {
  731.             return null;
  732.         }
  733.     }
  734.     /**
  735.      * @return null|string
  736.      */
  737.     public function getXmlNota(): ?string
  738.     {
  739.         return $this->xmlNota;
  740.     }
  741.     /**
  742.      * @param null|string $xmlNota
  743.      * @return NotaFiscal
  744.      * @noinspection PhpUndefinedFieldInspection
  745.      */
  746.     public function setXmlNota(?string $xmlNota): NotaFiscal
  747.     {
  748.         $this->xmlNota $xmlNota;
  749.         // força o reload nos transients.
  750.         $this->xmlDecoded null;
  751.         $this->xmlDecodedAsString null;
  752.         return $this;
  753.     }
  754.     /**
  755.      * Para aceitar tanto em string quanto em double.
  756.      * @Groups("notaFiscal")
  757.      * @SerializedName("totalDescontos")
  758.      * @return float
  759.      */
  760.     public function getTotalDescontosFormatted(): float
  761.     {
  762.         return (float)$this->totalDescontos;
  763.     }
  764.     /**
  765.      * Para aceitar tanto em string quanto em double.
  766.      * @Groups("notaFiscal")
  767.      * @SerializedName("totalDescontos")
  768.      * @param float $totalDescontos
  769.      */
  770.     public function setTotalDescontosFormatted(float $totalDescontos)
  771.     {
  772.         $this->totalDescontos $totalDescontos;
  773.     }
  774.     /**
  775.      * Para aceitar tanto em string quanto em double.
  776.      * @Groups("notaFiscal")
  777.      * @SerializedName("subtotal")
  778.      * @return float
  779.      */
  780.     public function getSubtotalFormatted(): float
  781.     {
  782.         return (float)$this->subtotal;
  783.     }
  784.     /**
  785.      * Para aceitar tanto em string quanto em double.
  786.      * @Groups("notaFiscal")
  787.      * @SerializedName("subtotal")
  788.      * @param float $subtotal
  789.      */
  790.     public function setSubtotalFormatted(float $subtotal)
  791.     {
  792.         $this->subtotal $subtotal;
  793.     }
  794.     /**
  795.      * Para aceitar tanto em string quanto em double.
  796.      * @Groups("notaFiscal")
  797.      * @SerializedName("valorTotal")
  798.      * @return float
  799.      */
  800.     public function getValorTotalFormatted(): float
  801.     {
  802.         return (float)$this->valorTotal;
  803.     }
  804.     /**
  805.      * Para aceitar tanto em string quanto em double.
  806.      * @Groups("notaFiscal")
  807.      * @SerializedName("valorTotal")
  808.      * @param float $valorTotal
  809.      */
  810.     public function setValorTotalFormatted(float $valorTotal)
  811.     {
  812.         $this->valorTotal $valorTotal;
  813.     }
  814.     /**
  815.      * Para aceitar tanto em string quanto em double.
  816.      * @Groups("notaFiscal")
  817.      * @SerializedName("transpPesoBruto")
  818.      * @return float
  819.      */
  820.     public function getTranspPesoBrutoFormatted(): float
  821.     {
  822.         return (float)$this->transpPesoBruto;
  823.     }
  824.     /**
  825.      * Para aceitar tanto em string quanto em double.
  826.      * @Groups("notaFiscal")
  827.      * @SerializedName("transpPesoBruto")
  828.      * @param float $transpPesoBruto
  829.      */
  830.     public function setTranspPesoBrutoFormatted(float $transpPesoBruto)
  831.     {
  832.         $this->transpPesoBruto $transpPesoBruto;
  833.     }
  834.     /**
  835.      * Para aceitar tanto em string quanto em double.
  836.      * @Groups("notaFiscal")
  837.      * @SerializedName("transpPesoLiquido")
  838.      * @return float
  839.      */
  840.     public function getTranspPesoLiquidoFormatted(): float
  841.     {
  842.         return (float)$this->transpPesoLiquido;
  843.     }
  844.     /**
  845.      * Para aceitar tanto em string quanto em double.
  846.      * @Groups("notaFiscal")
  847.      * @SerializedName("transpPesoLiquido")
  848.      * @param float $transpPesoLiquido
  849.      */
  850.     public function setTranspPesoLiquidoFormatted(float $transpPesoLiquido)
  851.     {
  852.         $this->transpPesoLiquido $transpPesoLiquido;
  853.     }
  854.     /**
  855.      * Para aceitar tanto em string quanto em double.
  856.      * @Groups("notaFiscal")
  857.      * @SerializedName("transpQtdeVolumes")
  858.      * @return float
  859.      */
  860.     public function getTranspQtdeVolumesFormatted(): float
  861.     {
  862.         return (float)$this->transpQtdeVolumes;
  863.     }
  864.     /**
  865.      * Para aceitar tanto em string quanto em double.
  866.      * @Groups("notaFiscal")
  867.      * @SerializedName("transpQtdeVolumes")
  868.      * @param float $transpQtdeVolumes
  869.      */
  870.     public function setTranspQtdeVolumesFormatted(float $transpQtdeVolumes)
  871.     {
  872.         $this->transpQtdeVolumes $transpQtdeVolumes;
  873.     }
  874.     /**
  875.      * Para aceitar tanto em string quanto em double.
  876.      * @Groups("notaFiscal")
  877.      * @SerializedName("transpValorTotalFrete")
  878.      * @return float
  879.      */
  880.     public function getTranspValorTotalFreteFormatted(): float
  881.     {
  882.         return (float)$this->transpValorTotalFrete;
  883.     }
  884.     /**
  885.      * Para aceitar tanto em string quanto em double.
  886.      * @Groups("notaFiscal")
  887.      * @SerializedName("transpValorTotalFrete")
  888.      * @param float $transpValorTotalFrete
  889.      */
  890.     public function setTranspValorTotalFreteFormatted(float $transpValorTotalFrete)
  891.     {
  892.         $this->transpValorTotalFrete $transpValorTotalFrete;
  893.     }
  894.     /**
  895.      * @Groups("notaFiscal")
  896.      */
  897.     public function getDadosDuplicatas(): array
  898.     {
  899.         if (
  900.             $this->getXMLDecoded() &&
  901.             $this->getXMLDecoded()->NFe &&
  902.             $this->getXMLDecoded()->NFe->infNFe &&
  903.             $this->getXMLDecoded()->NFe->infNFe->cobr &&
  904.             $this->getXMLDecoded()->NFe->infNFe->cobr->dup
  905.         ) {
  906.             $duplicatas = [];
  907.             foreach ($this->getXMLDecoded()->NFe->infNFe->cobr->dup as $dup) {
  908.                 $duplicatas[] = [
  909.                     'numero' => (string)$dup->nDup,
  910.                     'vencimento' => (string)$dup->dVenc,
  911.                     'valor' => (string)$dup->vDup,
  912.                 ];
  913.             }
  914.             return $duplicatas;
  915.         } else {
  916.             return [];
  917.         }
  918.     }
  919.     /**
  920.      * @Groups("notaFiscal")
  921.      */
  922.     public function getEmitenteCompleto(): string
  923.     {
  924.         return StringUtils::mascararCnpjCpf($this->documentoEmitente) . ' - ' $this->xNomeEmitente;
  925.     }
  926.     /**
  927.      * @Groups("notaFiscal")
  928.      */
  929.     public function isNossaEmissao(): bool
  930.     {
  931.         return in_array($this->documentoEmitenteexplode(','$_SERVER['FISCAL_EMITENTES']), true);
  932.     }
  933.     public function getIdDest(): ?int
  934.     {
  935.         $idDest $this->jsonData['idDest'] ?? null;
  936.         if (
  937.             !$idDest && (
  938.                 $this->getXMLDecoded() &&
  939.                 $this->getXMLDecoded()->NFe &&
  940.                 $this->getXMLDecoded()->NFe->infNFe &&
  941.                 $this->getXMLDecoded()->NFe->infNFe->ide &&
  942.                 $this->getXMLDecoded()->NFe->infNFe->ide->idDest)
  943.         ) {
  944.             $idDest $this->getXMLDecoded()->NFe->infNFe->ide->idDest->__toString();
  945.         }
  946.         $this->idDest = (int)$idDest;
  947.         return $this->idDest;
  948.     }
  949.     public function setIdDest(?int $idDest): ?int
  950.     {
  951.         $this->jsonData['idDest'] = $idDest;
  952.         $this->idDest $idDest;
  953.         return $this->idDest;
  954.     }
  955.     /**
  956.      * @Groups("notaFiscal")
  957.      */
  958.     public function isPermiteSalvar(): bool
  959.     {
  960.         $this->msgPermiteSalvar 'Sim';
  961.         if (!$this->getId()) {
  962.             return true;
  963.         }
  964.         if ($this->isNossaEmissao()) {
  965.             if (substr($this->cStat01) !== '1') {
  966.                 return true;
  967.             }
  968.         }
  969.         return false;
  970.     }
  971.     /**
  972.      * @Groups("notaFiscal")
  973.      */
  974.     public function getMsgPermiteSalvar(): string
  975.     {
  976.         if (!$this->getId()) {
  977.             return 'Sim';
  978.         }
  979.         if ($this->isNossaEmissao()) {
  980.             if (substr($this->cStat01) !== '1') {
  981.                 return 'Sim';
  982.             }
  983.         }
  984.         return 'Não';
  985.     }
  986.     /**
  987.      * @Groups("notaFiscal")
  988.      */
  989.     public function isPermiteReimpressao(): bool
  990.     {
  991.         if ($this->getId()) {
  992.             if (in_array((int)$this->cStat, [100204135], true)) {
  993.                 return true;
  994.             }
  995.             // else
  996.             if ($this->cStat == && strpos($this->xMotivo'DUPLICIDADE DE NF') !== FALSE) {
  997.                 return true;
  998.             }
  999.             // else
  1000.             if ($this->getXMLDecoded() && $this->getXMLDecoded()->getName() === 'nfeProc') {
  1001.                 return true;
  1002.             }
  1003.         }
  1004.         return false;
  1005.     }
  1006.     /**
  1007.      * @Groups("notaFiscal")
  1008.      */
  1009.     public function getMsgPermiteReimpressao(): string
  1010.     {
  1011.         if ($this->getId()) {
  1012.             if (in_array((int)$this->cStat, [100204135], true)) {
  1013.                 return 'Sim (cStat em 100, 204 ou 135)';
  1014.             }
  1015.             // else
  1016.             if ($this->cStat == && strpos($this->xMotivo'DUPLICIDADE DE NF') !== FALSE) {
  1017.                 return 'Sim (cStat em 0 e motivo "DUPLICIDADE DE NF")';
  1018.             }
  1019.             // else
  1020.             if ($this->getXMLDecoded() && $this->getXMLDecoded()->getName() === 'nfeProc') {
  1021.                 return 'Sim (com nfeProc)';
  1022.             }
  1023.         }
  1024.         return 'Não';
  1025.     }
  1026.     /**
  1027.      * @Groups("notaFiscal")
  1028.      */
  1029.     public function isPermiteReimpressaoCancelamento(): bool
  1030.     {
  1031.         return $this->isNossaEmissao() && ($this->getId() && $this->cStatLote == 101);
  1032.     }
  1033.     /**
  1034.      * @Groups("notaFiscal")
  1035.      */
  1036.     public function getMsgPermiteReimpressaoCancelamento(): string
  1037.     {
  1038.         if ($this->getId() && $this->cStatLote == 101) {
  1039.             return 'Sim (cStatLote em 101)';
  1040.         }
  1041.         return 'Não';
  1042.     }
  1043.     /**
  1044.      * @Groups("notaFiscal")
  1045.      */
  1046.     public function isPermiteCancelamento(): bool
  1047.     {
  1048.         return $this->isNossaEmissao() && ($this->getId() && (int)$this->cStat === 100);
  1049.     }
  1050.     /**
  1051.      * @Groups("notaFiscal")
  1052.      */
  1053.     public function getMsgPermiteCancelamento(): string
  1054.     {
  1055.         if ($this->getId() && (int)$this->cStat === 100) {
  1056.             return 'Sim (cStat em 100)';
  1057.         }
  1058.         return 'Não';
  1059.     }
  1060.     /**
  1061.      * @Groups("notaFiscal")
  1062.      */
  1063.     public function isPermiteCartaCorrecao(): bool
  1064.     {
  1065.         return $this->isNossaEmissao() && ($this->getId() && (int)$this->cStat === 100);
  1066.     }
  1067.     /**
  1068.      * @Groups("notaFiscal")
  1069.      */
  1070.     public function getMsgPermiteCartaCorrecao(): string
  1071.     {
  1072.         if ($this->getId() && (int)$this->cStat === 100) {
  1073.             return 'Sim (cStat em 100)';
  1074.         }
  1075.         return 'Não';
  1076.     }
  1077.     /**
  1078.      * @Groups("notaFiscal")
  1079.      * @var string
  1080.      */
  1081.     public function getMsgPermiteFaturamento(): string
  1082.     {
  1083.         return $this->jsonData['msgPermiteFaturamento'] ?? false;
  1084.     }
  1085.     /**
  1086.      * @Groups("notaFiscal")
  1087.      * @var bool
  1088.      */
  1089.     public function isPermiteFaturamento(): bool
  1090.     {
  1091.         // verificar o beforeSave() para entender o motivo
  1092.         // é lá também onde é setado o msgPermiteFaturamento
  1093.         return $this->isNossaEmissao() && ($this->jsonData['permiteFaturamento'] ?? false);
  1094.     }
  1095.     /**
  1096.      * @Groups("notaFiscal")
  1097.      */
  1098.     public function getVendaId(): ?int
  1099.     {
  1100.         return $this->jsonData['venda_id'] ?? null;
  1101.     }
  1102.     /**
  1103.      * @Groups("notaFiscal")
  1104.      */
  1105.     public function getFinFaturaId(): ?int
  1106.     {
  1107.         return $this->jsonData['fin_fatura_id'] ?? null;
  1108.     }
  1109.     
  1110.     /**
  1111.      * @Groups("notaFiscal")
  1112.      */
  1113.     public function getRetornoManifest(): ?string
  1114.     {
  1115.         return $this->jsonData['retorno_manifest'] ?? null;
  1116.     }
  1117. }