@@ -34,45 +34,6 @@ public ProviderGISS(ConfigNFSe config, OpenMunicipioNFSe municipio) : base(confi
3434
3535 #region RPS
3636
37- /*protected override XElement WriteRps(NotaServico nota)
38- {
39- var rootRps = new XElement("Rps");
40-
41- var infServico = new XElement("InfDeclaracaoPrestacaoServico", new XAttribute("Id", $"Rps{nota.IdentificacaoRps.Numero.OnlyNumbers()}"));
42- rootRps.Add(infServico);
43-
44- infServico.Add(WriteRpsRps(nota));
45-
46- infServico.AddChild(AdicionarTag(TipoCampo.Dat, "", "Competencia", 10, 10, Ocorrencia.Obrigatoria, nota.Competencia));
47-
48- infServico.AddChild(WriteServicosRps(nota));
49- infServico.AddChild(WritePrestadorRps(nota));
50- infServico.AddChild(WriteTomadorRps(nota));
51- infServico.AddChild(WriteIntermediarioRps(nota));
52- infServico.AddChild(WriteConstrucaoCivilRps(nota));
53-
54- string regimeEspecialTributacao;
55- string optanteSimplesNacional;
56- if (nota.RegimeEspecialTributacao == RegimeEspecialTributacao.SimplesNacional)
57- {
58- regimeEspecialTributacao = "6";
59- optanteSimplesNacional = "1";
60- }
61- else
62- {
63- regimeEspecialTributacao = ((int)nota.RegimeEspecialTributacao).ToString();
64- optanteSimplesNacional = "2";
65- }
66-
67- if (nota.RegimeEspecialTributacao != RegimeEspecialTributacao.Nenhum)
68- infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "RegimeEspecialTributacao", 1, 1, Ocorrencia.NaoObrigatoria, regimeEspecialTributacao));
69-
70- infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "OptanteSimplesNacional", 1, 1, Ocorrencia.Obrigatoria, optanteSimplesNacional));
71- infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "IncentivoFiscal", 1, 1, Ocorrencia.Obrigatoria, nota.IncentivadorCultural == NFSeSimNao.Sim ? 1 : 2));
72-
73- return rootRps;
74- }*/
75-
7637 protected override XElement WriteValoresRps ( NotaServico nota )
7738 {
7839 var valores = new XElement ( "Valores" ) ;
@@ -278,93 +239,19 @@ protected override void AssinarCancelarNFSe(RetornoCancelar retornoWebservice)
278239 }
279240
280241 /// <inheritdoc />
281- protected override void TratarRetornoEnviarSincrono ( RetornoEnviar retornoWebservice ,
282- NotaServicoCollection notas )
283- {
284- // Analisa mensagem de retorno
285- var xmlDocument = XElement . Parse ( retornoWebservice . XmlRetorno ) ;
286- var reader = xmlDocument . ElementAnyNs ( "gerarNfseResponse" ) . CreateReader ( ) ;
287- reader . MoveToContent ( ) ;
288- var xml = reader . ReadInnerXml ( ) . Replace ( "ns2:" , string . Empty ) ;
289-
290- XmlDocument XmlRetorno = new XmlDocument ( ) ;
291- XmlRetorno . LoadXml ( xml ) ;
292-
293- XmlDocument xmlMensagem = new XmlDocument ( ) ;
294- var xmlRet = XDocument . Parse ( XmlRetorno . LastChild . InnerText ) ;
295-
296- MensagemErro ( retornoWebservice , xmlRet , "GerarNfseResposta" ) ;
297- if ( retornoWebservice . Erros . Any ( ) ) return ;
298-
299- retornoWebservice . Sucesso = xmlRet . Root . ElementAnyNs ( "ListaNfse" ) != null ;
300-
301- if ( ! retornoWebservice . Sucesso ) return ;
302-
303- retornoWebservice . Data =
304- xmlRet . Root . ElementAnyNs ( "ListaNfse" ) . ElementAnyNs ( "CompNfse" ) . ElementAnyNs ( "Nfse" )
305- . ElementAnyNs ( "InfNfse" ) . ElementAnyNs ( "DataEmissao" ) ? . GetValue < DateTime > ( ) ?? DateTime . MinValue ;
306- retornoWebservice . Protocolo = xmlRet . Root . ElementAnyNs ( "ListaNfse" ) . ElementAnyNs ( "CompNfse" )
307- . ElementAnyNs ( "Nfse" ) . ElementAnyNs ( "InfNfse" )
308- . ElementAnyNs ( "CodigoVerificacao" ) ? . GetValue < string > ( ) ??
309- "" ;
310-
311- var listaNfse = xmlRet . Root . ElementAnyNs ( "ListaNfse" ) ;
312-
313- if ( listaNfse == null )
314- {
315- retornoWebservice . Erros . Add ( new Evento
316- { Codigo = "0" , Descricao = "Lista de NFSe não encontrada! (ListaNfse)" } ) ;
317- return ;
318- }
319-
320- foreach ( var compNfse in listaNfse . ElementsAnyNs ( "CompNfse" ) )
321- {
322- var nfse = compNfse . ElementAnyNs ( "Nfse" ) . ElementAnyNs ( "InfNfse" ) ;
323- var numeroNFSe = nfse . ElementAnyNs ( "Numero" ) ? . GetValue < string > ( ) ?? string . Empty ;
324- var chaveNFSe = nfse . ElementAnyNs ( "CodigoVerificacao" ) ? . GetValue < string > ( ) ?? string . Empty ;
325- var dataNFSe = nfse . ElementAnyNs ( "DataEmissao" ) ? . GetValue < DateTime > ( ) ?? DateTime . Now ;
326- var numeroRps = nfse . ElementAnyNs ( "DeclaracaoPrestacaoServico" ) ?
327- . ElementAnyNs ( "InfDeclaracaoPrestacaoServico" ) ?
328- . ElementAnyNs ( "Rps" ) ?
329- . ElementAnyNs ( "IdentificacaoRps" ) ?
330- . ElementAnyNs ( "Numero" ) . GetValue < string > ( ) ?? string . Empty ;
331-
332- GravarNFSeEmDisco ( compNfse . AsString ( true ) , $ "NFSe-{ numeroNFSe } -{ chaveNFSe } -.xml", dataNFSe ) ;
333-
334- var nota = notas . FirstOrDefault ( x => x . IdentificacaoRps . Numero == numeroRps ) ;
335- if ( nota == null )
336- {
337- nota = notas . Load ( compNfse . ToString ( ) ) ;
338- }
339- else
340- {
341- nota . IdentificacaoNFSe . Numero = numeroNFSe ;
342- nota . IdentificacaoNFSe . Chave = chaveNFSe ;
343- }
344-
345- nota . Protocolo = retornoWebservice . Protocolo ;
346- }
347- }
348-
349- protected override void PrepararConsultarNFSeRps ( RetornoConsultarNFSeRps retornoWebservice ,
350- NotaServicoCollection notas )
242+ protected override void PrepararConsultarNFSeRps ( RetornoConsultarNFSeRps retornoWebservice , NotaServicoCollection notas )
351243 {
352244 if ( retornoWebservice . NumeroRps < 1 )
353245 {
354- retornoWebservice . Erros . Add ( new Evento
355- { Codigo = "0" , Descricao = "Número da RPS não informado para a consulta." } ) ;
246+ retornoWebservice . Erros . Add ( new Evento { Codigo = "0" , Descricao = "Número da RPS não informado para a consulta." } ) ;
356247 return ;
357248 }
358249
359250 var loteBuilder = new StringBuilder ( ) ;
360251 loteBuilder . Append ( $ "<ConsultarNfseRpsEnvio { GetNamespace ( ) } >") ;
361- loteBuilder . Append ( $ "<credenciais>") ;
362- loteBuilder . Append ( $ "<usuario>{ Configuracoes . WebServices . Usuario } </usuario>") ;
363- loteBuilder . Append ( $ "<senha>{ Configuracoes . WebServices . Senha } </senha>") ;
364- loteBuilder . Append ( $ "<chavePrivada>{ Configuracoes . WebServices . ChavePrivada } </chavePrivada>") ;
365- loteBuilder . Append ( $ "</credenciais>") ;
366252 loteBuilder . Append ( "<IdentificacaoRps>" ) ;
367253 loteBuilder . Append ( $ "<Numero>{ retornoWebservice . NumeroRps } </Numero>") ;
254+ loteBuilder . Append ( $ "<Serie>{ retornoWebservice . Serie } </Serie>") ;
368255 loteBuilder . Append ( $ "<Tipo>{ ( int ) retornoWebservice . Tipo + 1 } </Tipo>") ;
369256 loteBuilder . Append ( "</IdentificacaoRps>" ) ;
370257 loteBuilder . Append ( "<Prestador>" ) ;
@@ -373,12 +260,40 @@ protected override void PrepararConsultarNFSeRps(RetornoConsultarNFSeRps retorno
373260 ? $ "<Cnpj>{ Configuracoes . PrestadorPadrao . CpfCnpj . ZeroFill ( 14 ) } </Cnpj>"
374261 : $ "<Cpf>{ Configuracoes . PrestadorPadrao . CpfCnpj . ZeroFill ( 11 ) } </Cpf>") ;
375262 loteBuilder . Append ( "</CpfCnpj>" ) ;
376- if ( ! Configuracoes . PrestadorPadrao . InscricaoMunicipal . IsEmpty ( ) )
377- loteBuilder . Append (
378- $ "<InscricaoMunicipal>{ Configuracoes . PrestadorPadrao . InscricaoMunicipal } </InscricaoMunicipal>") ;
263+ if ( ! Configuracoes . PrestadorPadrao . InscricaoMunicipal . IsEmpty ( ) ) loteBuilder . Append ( $ "<InscricaoMunicipal>{ Configuracoes . PrestadorPadrao . InscricaoMunicipal } </InscricaoMunicipal>") ;
379264 loteBuilder . Append ( "</Prestador>" ) ;
380265 loteBuilder . Append ( "</ConsultarNfseRpsEnvio>" ) ;
381- retornoWebservice . XmlEnvio = loteBuilder . ToString ( ) ;
266+
267+ var xmlstring = loteBuilder . ToString ( ) . Replace ( "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?>" , "" ) ;
268+ XDocument doc = XDocument . Parse ( xmlstring ) ;
269+
270+ XNamespace nsRoot = "http://www.giss.com.br/consultar-nfse-rps-envio-v2_04.xsd" ;
271+ XNamespace nsChild = "http://www.giss.com.br/tipos-v2_04.xsd" ;
272+
273+ doc . Root . Name = nsRoot + doc . Root . Name . LocalName ;
274+
275+ doc . Root . SetAttributeValue ( XNamespace . Xmlns + "con" , nsRoot ) ;
276+ doc . Root . SetAttributeValue ( XNamespace . Xmlns + "tip" , nsChild ) ;
277+
278+ foreach ( var element in doc . Descendants ( ) . ToList ( ) )
279+ element . Name = nsChild + element . Name . LocalName ;
280+
281+ var identificador = doc . Descendants ( ) . First ( x=> x . Name . LocalName == "IdentificacaoRps" ) ;
282+ identificador . Name = nsRoot + identificador . Name . LocalName ;
283+
284+ var prestador = doc . Descendants ( ) . First ( x=> x . Name . LocalName == "Prestador" ) ;
285+ prestador . Name = nsRoot + prestador . Name . LocalName ;
286+
287+ doc . Root . Name = nsRoot + doc . Root . Name . LocalName ;
288+
289+ var xml = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" + doc ;
290+ retornoWebservice . XmlEnvio = xml ;
291+ }
292+
293+ /// <inheritdoc />
294+ protected override void AssinarConsultarNFSeRps ( RetornoConsultarNFSeRps retornoWebservice )
295+ {
296+ retornoWebservice . XmlEnvio = XmlSigning . AssinarXml ( retornoWebservice . XmlEnvio , "con:ConsultarNfseRpsEnvio" , "" , Certificado ) ;
382297 }
383298
384299 protected override void MensagemErro ( RetornoWebservice retornoWs , XContainer xmlRet , string xmlTag )
@@ -411,13 +326,19 @@ protected override void TratarRetornoConsultarNFSeRps(RetornoConsultarNFSeRps re
411326 {
412327 // Analisa mensagem de retorno
413328 var xmlRet = XDocument . Parse ( retornoWebservice . XmlRetorno ) ;
329+ retornoWebservice . Sucesso = true ;
414330 MensagemErro ( retornoWebservice , xmlRet , "ConsultarNfseRpsResposta" ) ;
415- if ( retornoWebservice . Erros . Any ( ) ) return ;
331+ if ( retornoWebservice . Erros . Any ( ) )
332+ {
333+ retornoWebservice . Sucesso = false ;
334+ return ;
335+ }
416336
417337 var compNfse = xmlRet . ElementAnyNs ( "ConsultarNfseRpsResposta" ) ? . ElementAnyNs ( "CompNfse" ) ;
418338
419339 if ( compNfse == null )
420340 {
341+ retornoWebservice . Sucesso = false ;
421342 retornoWebservice . Erros . Add ( new Evento
422343 { Codigo = "0" , Descricao = "Nota Fiscal não encontrada! (CompNfse)" } ) ;
423344 return ;
@@ -428,6 +349,8 @@ protected override void TratarRetornoConsultarNFSeRps(RetornoConsultarNFSeRps re
428349 var chaveNFSe = nfse . ElementAnyNs ( "CodigoVerificacao" ) ? . GetValue < string > ( ) ?? string . Empty ;
429350 var dataNFSe = nfse . ElementAnyNs ( "DataEmissao" ) ? . GetValue < DateTime > ( ) ?? DateTime . Now ;
430351 var numeroRps = nfse . ElementAnyNs ( "DeclaracaoPrestacaoServico" ) ?
352+ . ElementAnyNs ( "InfDeclaracaoPrestacaoServico" ) ?
353+ . ElementAnyNs ( "Rps" ) ?
431354 . ElementAnyNs ( "IdentificacaoRps" ) ?
432355 . ElementAnyNs ( "Numero" ) . GetValue < string > ( ) ?? string . Empty ;
433356
0 commit comments