From f422c8f2e205e18a264ce668d6bcb7c84f0dacee Mon Sep 17 00:00:00 2001 From: Luiz Kim Date: Fri, 3 Nov 2023 12:58:24 -0300 Subject: [PATCH 1/4] GNRE --- lib/Sped/Gnre/Helper/GnreHelper.php | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/Sped/Gnre/Helper/GnreHelper.php diff --git a/lib/Sped/Gnre/Helper/GnreHelper.php b/lib/Sped/Gnre/Helper/GnreHelper.php new file mode 100644 index 0000000..0ea7b67 --- /dev/null +++ b/lib/Sped/Gnre/Helper/GnreHelper.php @@ -0,0 +1,104 @@ + + * @license http://www.gnu.org/licenses/gpl-howto.html GPL + * @link http://en.wikipedia.org/wiki/Template_method_pattern Template Method Design Pattern + * @version 1.0.0 + */ +class GnreHelper +{ + + protected static $xmlNf; + + + public function __construct($xmlNf) + { + } + + /** + * Método utilizado para gerar os dados principais da GNRE utilizando os dados encontrados dentro do XML + * + * + * @param string $dadosArquivo

String contendo o xml da NF de venda + * utilizada no SEFAZ

+ * @since 1.0.0 + */ + public static function getGuiaGnre($xmlNf): Guia + { + $xml = self::parseNf($xmlNf); + + $guia = new Guia(); + + $guia->c04_docOrigem = $xml->NrNf; + $guia->c28_tipoDocOrigem = $xml->TipoDoc; + $guia->c21_cepEmitente = $xml->CEPEmpresa; + $guia->c16_razaoSocialEmitente = $xml->NmEmpresa; + $guia->c18_enderecoEmitente = $xml->EnderecoEmpresa; + $guia->c19_municipioEmitente = $xml->CdMunicipioEmpresa; + $guia->c20_ufEnderecoEmitente = $xml->UfEmpresa; + $guia->c17_inscricaoEstadualEmitente = $xml->NrIEEmpresa; + $guia->c22_telefoneEmitente = $xml->TelefoneEmpresa; + $guia->c01_UfFavorecida = $xml->IdUfCliente; + $guia->c36_inscricaoEstadualDestinatario = $xml->NrIECliente; + $guia->c37_razaoSocialDestinatario = $xml->NmCliente; + $guia->c38_municipioDestinatario = $xml->CdMunicipioCliente; + + + return $guia; + } + + + public static function parseNf($xmlNf): stdClass + { + $xml = simplexml_load_string($xmlNf); + $parsed = new stdClass(); + + + $parsed->CEPEmpresa = $xml->NFe->infNFe->emit->enderEmit->CEP; + $parsed->EnderecoEmpresa = $xml->NFe->infNFe->emit->enderEmit->xLgr; + $parsed->CdMunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->cMun; + $parsed->UfEmpresa = $xml->NFe->infNFe->emit->enderEmit->UF; + $parsed->TelefoneEmpresa = $xml->NFe->infNFe->emit->enderEmit->fone; + $parsed->NrIEEmpresa = $xml->NFe->infNFe->emit->IE; + $parsed->NmEmpresaCliente = $xml->NFe->infNFe->emit->xNome; + $parsed->NrDocumentoCliente = $xml->NFe->infNFe->dest->CNPJ ?: $xml->NFe->infNFe->dest->CPF; + $parsed->NrIECliente = $xml->NFe->infNFe->dest->IE; + $parsed->NmCliente = $xml->NFe->infNFe->dest->xNome; + $parsed->NmCidade = $xml->NFe->infNFe->dest->enderDest->xMun; + $parsed->IdUfCliente = $xml->NFe->infNFe->dest->enderDest->UF; + $parsed->CdMunicipioCliente = $xml->NFe->infNFe->dest->enderDest->cMun; + $parsed->ISUFCliente = $xml->NFe->infNFe->dest->ISUF; + $parsed->TipoDoc = $xml->NFe->infNFe->ide->tpDoc; + $parsed->NrChaveNFe = $xml->protNFe->infProt->chNFe; + $parsed->VlNf = $xml->NFe->infNFe->total->ICMSTot->vNF; + $parsed->NrNf = $xml->NFe->infNFe->ide->nNF; + + return $parsed; + } +} From d9bc5418589ccbe9676f23749d4e590162919c3d Mon Sep 17 00:00:00 2001 From: Luiz Kim Date: Fri, 3 Nov 2023 13:18:07 -0300 Subject: [PATCH 2/4] GNRE --- lib/Sped/Gnre/Helper/GnreHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sped/Gnre/Helper/GnreHelper.php b/lib/Sped/Gnre/Helper/GnreHelper.php index 0ea7b67..c7d98f5 100644 --- a/lib/Sped/Gnre/Helper/GnreHelper.php +++ b/lib/Sped/Gnre/Helper/GnreHelper.php @@ -86,7 +86,7 @@ public static function parseNf($xmlNf): stdClass $parsed->UfEmpresa = $xml->NFe->infNFe->emit->enderEmit->UF; $parsed->TelefoneEmpresa = $xml->NFe->infNFe->emit->enderEmit->fone; $parsed->NrIEEmpresa = $xml->NFe->infNFe->emit->IE; - $parsed->NmEmpresaCliente = $xml->NFe->infNFe->emit->xNome; + $parsed->NmEmpresa = $xml->NFe->infNFe->emit->xNome; $parsed->NrDocumentoCliente = $xml->NFe->infNFe->dest->CNPJ ?: $xml->NFe->infNFe->dest->CPF; $parsed->NrIECliente = $xml->NFe->infNFe->dest->IE; $parsed->NmCliente = $xml->NFe->infNFe->dest->xNome; From 570e3bb62be175b364b001c26da433247caf464e Mon Sep 17 00:00:00 2001 From: Luiz Kim Date: Fri, 3 Nov 2023 13:48:41 -0300 Subject: [PATCH 3/4] GNRE --- lib/Sped/Gnre/Helper/GnreHelper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Sped/Gnre/Helper/GnreHelper.php b/lib/Sped/Gnre/Helper/GnreHelper.php index c7d98f5..6f522b5 100644 --- a/lib/Sped/Gnre/Helper/GnreHelper.php +++ b/lib/Sped/Gnre/Helper/GnreHelper.php @@ -52,23 +52,20 @@ public function __construct($xmlNf) public static function getGuiaGnre($xmlNf): Guia { $xml = self::parseNf($xmlNf); - - $guia = new Guia(); - + $guia = new Guia(); $guia->c04_docOrigem = $xml->NrNf; $guia->c28_tipoDocOrigem = $xml->TipoDoc; $guia->c21_cepEmitente = $xml->CEPEmpresa; $guia->c16_razaoSocialEmitente = $xml->NmEmpresa; $guia->c18_enderecoEmitente = $xml->EnderecoEmpresa; - $guia->c19_municipioEmitente = $xml->CdMunicipioEmpresa; + $guia->c19_municipioEmitente = $xml->MunicipioEmpresa; $guia->c20_ufEnderecoEmitente = $xml->UfEmpresa; $guia->c17_inscricaoEstadualEmitente = $xml->NrIEEmpresa; $guia->c22_telefoneEmitente = $xml->TelefoneEmpresa; $guia->c01_UfFavorecida = $xml->IdUfCliente; $guia->c36_inscricaoEstadualDestinatario = $xml->NrIECliente; $guia->c37_razaoSocialDestinatario = $xml->NmCliente; - $guia->c38_municipioDestinatario = $xml->CdMunicipioCliente; - + $guia->c38_municipioDestinatario = $xml->MunicipioCliente; return $guia; } @@ -83,16 +80,19 @@ public static function parseNf($xmlNf): stdClass $parsed->CEPEmpresa = $xml->NFe->infNFe->emit->enderEmit->CEP; $parsed->EnderecoEmpresa = $xml->NFe->infNFe->emit->enderEmit->xLgr; $parsed->CdMunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->cMun; + $parsed->MunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->xMun; $parsed->UfEmpresa = $xml->NFe->infNFe->emit->enderEmit->UF; $parsed->TelefoneEmpresa = $xml->NFe->infNFe->emit->enderEmit->fone; $parsed->NrIEEmpresa = $xml->NFe->infNFe->emit->IE; $parsed->NmEmpresa = $xml->NFe->infNFe->emit->xNome; $parsed->NrDocumentoCliente = $xml->NFe->infNFe->dest->CNPJ ?: $xml->NFe->infNFe->dest->CPF; + $parsed->NrIECliente = $xml->NFe->infNFe->dest->IE; $parsed->NmCliente = $xml->NFe->infNFe->dest->xNome; $parsed->NmCidade = $xml->NFe->infNFe->dest->enderDest->xMun; $parsed->IdUfCliente = $xml->NFe->infNFe->dest->enderDest->UF; $parsed->CdMunicipioCliente = $xml->NFe->infNFe->dest->enderDest->cMun; + $parsed->MunicipioCliente = $xml->NFe->infNFe->dest->enderDest->xMun; $parsed->ISUFCliente = $xml->NFe->infNFe->dest->ISUF; $parsed->TipoDoc = $xml->NFe->infNFe->ide->tpDoc; $parsed->NrChaveNFe = $xml->protNFe->infProt->chNFe; From f676ad9931e35671e1f6be099c1a4b15975c4f41 Mon Sep 17 00:00:00 2001 From: Luiz Kim Date: Fri, 3 Nov 2023 14:34:19 -0300 Subject: [PATCH 4/4] GNRE --- lib/Sped/Gnre/Helper/GnreHelper.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Sped/Gnre/Helper/GnreHelper.php b/lib/Sped/Gnre/Helper/GnreHelper.php index 6f522b5..920301f 100644 --- a/lib/Sped/Gnre/Helper/GnreHelper.php +++ b/lib/Sped/Gnre/Helper/GnreHelper.php @@ -51,18 +51,21 @@ public function __construct($xmlNf) */ public static function getGuiaGnre($xmlNf): Guia { + $xml = self::parseNf($xmlNf); - $guia = new Guia(); + $guia = new Guia(); $guia->c04_docOrigem = $xml->NrNf; - $guia->c28_tipoDocOrigem = $xml->TipoDoc; + $guia->c28_tipoDocOrigem = $xml->TipoDoc; $guia->c21_cepEmitente = $xml->CEPEmpresa; $guia->c16_razaoSocialEmitente = $xml->NmEmpresa; + $guia->c03_idContribuinteEmitente = $xml->NrDocumentoEmpresa; $guia->c18_enderecoEmitente = $xml->EnderecoEmpresa; $guia->c19_municipioEmitente = $xml->MunicipioEmpresa; $guia->c20_ufEnderecoEmitente = $xml->UfEmpresa; $guia->c17_inscricaoEstadualEmitente = $xml->NrIEEmpresa; $guia->c22_telefoneEmitente = $xml->TelefoneEmpresa; $guia->c01_UfFavorecida = $xml->IdUfCliente; + $guia->c35_idContribuinteDestinatario = $xml->NrDocumentoCliente; $guia->c36_inscricaoEstadualDestinatario = $xml->NrIECliente; $guia->c37_razaoSocialDestinatario = $xml->NmCliente; $guia->c38_municipioDestinatario = $xml->MunicipioCliente; @@ -76,24 +79,26 @@ public static function parseNf($xmlNf): stdClass $xml = simplexml_load_string($xmlNf); $parsed = new stdClass(); - + $parsed->CEPEmpresa = $xml->NFe->infNFe->emit->enderEmit->CEP; $parsed->EnderecoEmpresa = $xml->NFe->infNFe->emit->enderEmit->xLgr; $parsed->CdMunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->cMun; - $parsed->MunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->xMun; + $parsed->MunicipioEmpresa = $xml->NFe->infNFe->emit->enderEmit->xMun; $parsed->UfEmpresa = $xml->NFe->infNFe->emit->enderEmit->UF; $parsed->TelefoneEmpresa = $xml->NFe->infNFe->emit->enderEmit->fone; - $parsed->NrIEEmpresa = $xml->NFe->infNFe->emit->IE; + $parsed->NrIEEmpresa = $xml->NFe->infNFe->emit->IE; $parsed->NmEmpresa = $xml->NFe->infNFe->emit->xNome; - $parsed->NrDocumentoCliente = $xml->NFe->infNFe->dest->CNPJ ?: $xml->NFe->infNFe->dest->CPF; + $parsed->NrDocumentoEmpresa = $xml->NFe->infNFe->emit->CNPJ; + + $parsed->NrDocumentoCliente = $xml->NFe->infNFe->dest->CNPJ ?: $xml->NFe->infNFe->dest->CPF; $parsed->NrIECliente = $xml->NFe->infNFe->dest->IE; $parsed->NmCliente = $xml->NFe->infNFe->dest->xNome; $parsed->NmCidade = $xml->NFe->infNFe->dest->enderDest->xMun; $parsed->IdUfCliente = $xml->NFe->infNFe->dest->enderDest->UF; $parsed->CdMunicipioCliente = $xml->NFe->infNFe->dest->enderDest->cMun; $parsed->MunicipioCliente = $xml->NFe->infNFe->dest->enderDest->xMun; - $parsed->ISUFCliente = $xml->NFe->infNFe->dest->ISUF; + $parsed->ISUFCliente = $xml->NFe->infNFe->dest->ISUF; $parsed->TipoDoc = $xml->NFe->infNFe->ide->tpDoc; $parsed->NrChaveNFe = $xml->protNFe->infProt->chNFe; $parsed->VlNf = $xml->NFe->infNFe->total->ICMSTot->vNF;