@@ -181,6 +181,69 @@ protected override void AssinarConsultarLoteRps(RetornoConsultarLoteRps retornoW
181181 retornoWebservice . XmlEnvio = XmlSigning . AssinarXml ( retornoWebservice . XmlEnvio , "con:ConsultarLoteRpsEnvio" , "" , Certificado ) ;
182182 }
183183
184+ protected override void TratarRetornoConsultarLoteRps ( RetornoConsultarLoteRps retornoWebservice , NotaServicoCollection notas )
185+ {
186+ // Analisa mensagem de retorno
187+ var xmlRet = XDocument . Parse ( retornoWebservice . XmlRetorno ) ;
188+
189+ retornoWebservice . Lote = xmlRet . Root ? . ElementAnyNs ( "NumeroLote" ) ? . GetValue < int > ( ) ?? 0 ;
190+
191+ var retornoLote = xmlRet . ElementAnyNs ( "ConsultarLoteRpsResposta" ) ;
192+ var situacao = retornoLote ? . ElementAnyNs ( "Situacao" ) ;
193+ if ( situacao != null )
194+ retornoWebservice . Situacao = situacao . GetValue < string > ( ) ;
195+
196+ MensagemErro ( retornoWebservice , xmlRet , "ConsultarLoteRpsResposta" ) ;
197+ if ( retornoWebservice . Erros . Any ( ) ) return ;
198+
199+ retornoWebservice . Sucesso = true ;
200+
201+ if ( notas == null ) return ;
202+
203+ var listaNfse = retornoLote ? . ElementAnyNs ( "ListaNfse" ) ;
204+
205+ if ( listaNfse == null )
206+ {
207+ retornoWebservice . Erros . Add ( new Evento { Codigo = "0" , Descricao = "Lista de NFSe não encontrada! (ListaNfse)" } ) ;
208+ return ;
209+ }
210+
211+ var notasFiscais = new List < NotaServico > ( ) ;
212+
213+ foreach ( var compNfse in listaNfse . ElementsAnyNs ( "CompNfse" ) )
214+ {
215+ var nfse = compNfse . ElementAnyNs ( "Nfse" ) . ElementAnyNs ( "InfNfse" ) ;
216+ var numeroNFSe = nfse . ElementAnyNs ( "Numero" ) ? . GetValue < string > ( ) ?? string . Empty ;
217+ var chaveNFSe = nfse . ElementAnyNs ( "CodigoVerificacao" ) ? . GetValue < string > ( ) ?? string . Empty ;
218+ var dataNFSe = nfse . ElementAnyNs ( "DataEmissao" ) ? . GetValue < DateTime > ( ) ?? DateTime . Now ;
219+ var numeroRps = nfse . ElementAnyNs ( "DeclaracaoPrestacaoServico" ) ?
220+ . ElementAnyNs ( "InfDeclaracaoPrestacaoServico" ) ?
221+ . ElementAnyNs ( "Rps" ) ?
222+ . ElementAnyNs ( "IdentificacaoRps" ) ?
223+ . ElementAnyNs ( "Numero" ) . GetValue < string > ( ) ?? string . Empty ;
224+
225+ GravarNFSeEmDisco ( compNfse . AsString ( true ) , $ "NFSe-{ numeroNFSe } -{ chaveNFSe } -.xml", dataNFSe ) ;
226+
227+ var nota = notas . FirstOrDefault ( x => x . IdentificacaoRps . Numero == numeroRps ) ;
228+ if ( nota == null )
229+ {
230+ nota = notas . Load ( compNfse . ToString ( ) ) ;
231+ }
232+ else
233+ {
234+ nota . IdentificacaoNFSe . Numero = numeroNFSe ;
235+ nota . IdentificacaoNFSe . Chave = chaveNFSe ;
236+ nota . IdentificacaoNFSe . DataEmissao = dataNFSe ;
237+ nota . XmlOriginal = compNfse . ToString ( ) ;
238+ }
239+
240+ nota . Protocolo = retornoWebservice . Protocolo ;
241+ notasFiscais . Add ( nota ) ;
242+ }
243+
244+ retornoWebservice . Notas = notasFiscais . ToArray ( ) ;
245+ }
246+
184247 protected override void PrepararCancelarNFSe ( RetornoCancelar retornoWebservice )
185248 {
186249 if ( retornoWebservice . NumeroNFSe . IsEmpty ( ) || retornoWebservice . CodigoCancelamento . IsEmpty ( ) )
0 commit comments