Jump to content
Fivewin Brasil

BuscaNfe na vr 4.0


jfaguiar

Recommended Posts

Verifique o caminho do PATH

 


METHOD BuscaNFe( cNFeAssinada, cNroRecibo, cTo, cBcc, cSubject, aFieldBody, cBody, lBodyHtml )
	// Busca autorizaçao NF e salva o xml protocolado
	METHOD BuscaNFe( cNFeAssinada, cNroRecibo, cTo, cBcc, cSubject, aFieldBody, cBody, lBodyHtml ) CLASS TVoNFeUtil2G
	   LOCAL nStat := 1
   LOCAL cMsgDados := "", cMsgRetWS := ""
   LOCAL cMsgResultado := ""
   LOCAL aAttach := {}
   LOCAL oXmlDoc, oXmlIter, aValor := {}
   LOCAL cChave, cFilePdf
	   DEFAULT cNFeAssinada := ""
	   ::Limpa()
	   cNFeAssinada := ::ReadXml( cNFeAssinada )
	   If ::CertificadoSelecionado()
      If ::ConsultaStatus()
         Try
            ::cXmlProtocolo := ::oNFEUtil:BuscaNFe2G( ::SiglaWS, ::Ambiente, cNFeAssinada, cNroRecibo, ::cCertificado, ;
               "4.00", cMsgDados, @cMsgRetWS, @nStat, @cMsgResultado, ;
               @::Protocolo, @::Recebimento, @::cMsgCodSefaz, @::cMsgSefaz, ::proxy, ::usuario, ::senha, ::licenca )
         CATCH
            ? "Tratar o erro"
            RETURN( .F. )
         End Try
         ::aUltStatus := { cMsgDados, cMsgRetWS }
         ::cStsNFe     := Alltrim( Str( nStat ) )
         ::cStsNFeMsg  := cMsgResultado
         ::lAutorizada := ( nStat == 100 )
	         IF !::lAutorizada
            ::GeraLog( ::cMsgSefaz + CRLF + cMsgRetWs )
            If ::lMensagem
            #ifdef __DOS__
               Alert( hb_ansitooem( cMsgResultado + "-" + Procname() ), , , 3 )
            #else
               MsgStop( cMsgResultado + CRLF + ProcName() , CAPTION_MSG )
            #endif
            ENDIF
         ELSE
            If ::lSalvaXmlAutomatico
               ::cChaveNfe := ::PegaChaveAcesso( ::cXmlProtocolo, 1 )
               IF !::SalvaXml( ::cChaveNfe + "-nfe.xml", ::cXmlProtocolo, 3 )
	                  ::Geralog( "Não foi possível salvar XML Protocolado:" + ::cChaveNfe + CRLF + ::cXml )
               #ifdef __DOS__
                  Alert( hb_ansitooem( "Não foi possível salvar XML Protocolado:" + ::cChaveNfe + "-" + Procname() ) )
               #else
                  MsgStop( "Não foi possível salvar XML Protocolado:" + ::cChaveNfe + "-" + CRLF + ProcName() , CAPTION_MSG )
               #endif
               ENDIF
            ENDIF
	            cFilePDF := CurDrive() + ":\" + CurDir() + "\remessa\protocolos\" + ::cChavenfe + "-nfe.xml"
            CriaPdfDanfe( cFilePDF, ::oNfeUtil, ::cChavenfe )
            cFilePdf := CurDrive() + ":\" + CurDir() + "\remessa\PDF\" + ::cChaveNFe + ".pdf"
	
            IF !Empty( ::cFromEmail ) .AND. !Empty( cTo )
               cBody := ::PreparaEmail( If( Empty(cBody ),::cEmailEmissao,cBody ), ::cXmlProtocolo, aFieldBody )
               ::EnviaEmail( cTo, cBcc, cSubject, cBody, { ::cPathNFe + ::cSubPastaProtocolos + ::cChaveNfe + "-nfe.xml", cFilePdf }, lBodyHtml, aFieldBody )
            ENDIF
	         ENDIF
      ELSE
         //Tratar erro para servidor fora
      ENDIF
	   ENDIF
	RETURN( ::lAutorizada )


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...