**************************************************** * Desenvolvido com base no projeto criado por Daniel Denobie - denobie@hotmail.com * http://www.pctoledo.com.br/forum/viewtopic.php?f=4&t=16972 **************************************************** #include #include DECLARE WINDOW principal Procedure Main() Public cUrl := "http://www.nfe.fazenda.gov.br/portal/consulta.aspx?tipoConsulta=completa&tipoConteudo=XbSeqxE8pl8=" Public cUrl1:= "http://www.nfe.fazenda.gov.br/portal/consultaCompleta.aspx?tipoConteudo=XbSeqxE8pl8=" Public cUrl2:= 'http://www.nfe.fazenda.gov.br/portal/consultaCompleta.aspx?tipoConteudo=XbSeqxE8pl8%3d' Public cCaptcha, cCnpj, cStringCookie, cViewState, cEeventValidation, cHiddenToken, cCodigo, cViewStateGenerator Public cHiddenSom, cChave SET NAVIGATION EXTENDED SET LANGUAGE TO PORTUGUESE Load Window principal principal.Button_1.Enabled:=.F. AtualizaImagem() On Key escape Of principal Action Sair() Center Window principal Activate Window principal Return *************************************************** Function AtualizaImagem() Try oServer:= win_OleCreateObject( "MSXML2.ServerXMLHTTP.5.0") Catch MsgInfo('Erro na Criação do Serviço') Return .f. End Try oServer:Open( "GET", cUrl, .f. ) oServer:SetRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ) oServer:SetRequestHeader( "Connection", "keep-alive" ) oServer:Send() oServer:WaitForResponse( 10000 ) Catch MsgInfo('Erro na Conexão com o Site') Return .f. End cHtml:= oServer:ResponseBody cStringCookie:= oServer:getResponseHeader("Set-Cookie") nInie := At('id="ctl00_ContentPlaceHolder1_lblMensagemErro">', cHtml) + 47 If nInie > 47 cHtml1 := SubStr( cHtml, nInie) nFime := At('', cHtml1) - 1 cMsgErro:= SubStr(cHtml, nInie, nFime) If ! Empty(cMsgErro) MsgInfo(cMsgErro, 'Erro no Site ' + cUrl) Return .f. EndIf EndIf nIni := At('id="__VIEWSTATE" value=', cHtml) + 24 cHtml1:= SubStr( cHtml, nIni) nFim := At('" />', cHtml1) - 1 cViewState:= SubStr(cHtml, nIni, nFim) nIni1 := At('id="__EVENTVALIDATION" value="', cHtml) + 30 cHtml1:= SubStr( cHtml, nIni1) nFim1 := At('" />', cHtml1) - 1 cEeventValidation:= SubStr(cHtml, nIni1, nFim1) nIni2 := At('id="__VIEWSTATEGENERATOR" value="', cHtml) + 33 cHtml1:= SubStr( cHtml, nIni2) nFim2 := At('" />', cHtml1) - 1 cViewStateGenerator:= SubStr(cHtml, nIni2, nFim2) nIni3 := At('id="ctl00_ContentPlaceHolder1_token" value="', cHtml) + 44 cHtml1:= SubStr( cHtml, nIni3) nFim3 := At('" />', cHtml1) - 1 cHiddenToken:= SubStr(cHtml, nIni3, nFim3) nIni4 := At('id="ctl00_ContentPlaceHolder1_captchaSom" value="', cHtml) + 49 cHtml1:= SubStr( cHtml, nIni4) nFim4 := At('" />', cHtml1) - 1 cHiddenSom:= SubStr(cHtml, nIni4, nFim4) nIni := At('data:image/png;base64,', cHtml) + 22 cHtml1:= SubStr(cHtml, nIni) nFim := At('" style="border-width:0px;" />', cHtml1) - 2 cFile:= SubStr(cHtml, nIni, nFim) txt_file:=fcreate("captcha.png", 0) If (!(ferror() = 0)) MsgInfo("Erro de criacao do arquivo de imagem " + Str(ferror(), 3, 0)) Return .f. EndIf cCodigo:= SubStr(cHtml, nIni, nFim) If Empty(cCodigo) MsgInfo("Erro de criacao do arquivo de imagem") Return .f. EndIf cFile:= hb_base64Decode(cFile, cCodigo) FWrite(txt_file, cFile) FClose(txt_file) SetProperty ('principal', 'oImg_captcha', 'Picture', 'Captcha.png') principal.Button_1.Enabled:=.T. Return .t. *************************************************** Function Continuar() Local oInternet, cParm, cRet:= cHtml:= '', cCaptcha:=principal.oTxt_captcha.Value Private cChave:=principal.oChaveNFe.Value, cVersao:="", ctpAmb:="", cverAplic:="", cdhRecbto:="", cnProt:="", cdigVal:="", ccStat:="", cxMotivo:="" Private cinfCpl:="", cinfAdFisco:="", cDiscAdicional:="" Private aIde:={}, aEmit:={}, aDest:={}, aDet:={}, aICMS:={}, aIPI:={}, aPIS:={}, aCOFINS:={}, aTotais:={}, aTransp:={}, aCobr:={} Private aMedicamentos:= {}, aTrib:= {} * Conteudo elementos da Matriz = {VALOR_TAG,TAG,TAG_PAI,Elemento_Final_TAG_PAI,LABEL_HTML,TAM_LABEL} * TAM_LABEL se ZERO pega tudo, se MAIOR que ZERO pega o tamanho no início e se MENOR que ZERO exclui o tamanho no início e pega o restante AADD(aIde,{{"","cUF","ide",21,"Chave de Acesso",2},; //1- tratamento especial {"","cNF","",0,"Número",0},; //2- tratamento especial {"","natOp","",0,"Natureza da Operação",0},; //3- {"","indPag","",0,"Forma de Pagamento",1},; //4- {"","mod","",0,"Modelo",0},; //5- {"","serie","",0,"Série",0},; //6- {"","nNF","",0,"Número",0},; //7- {"","dhEmi","",0,"Data de Emissão",0},; //8- tratamento especial {"","dhSaiEnt","",0,"Entrada",0},; //9- tratamento especial {"","tpNF","",0,"Tipo da Operação",1},; //10- {"","idDest","",0,"Destino da operação",1},; //11- {"","cMunFG","",0,"Município da Ocorrência do Fato Gerador do ICMS",0},; //12- {"","tpImp","",0,"Formato de Impressão DANFE",1},; //13- tratamento especial {"","tpEmis","",0,"Tipo de Emissão",1},; //14- {"","cDV","",0,"Chave de Acesso",0},; //15- tratamento especial {"","tpAmb","",0,"Ambiente de autorização:",0},; //16- tratamento especial {"","finNFe","",0,"Finalidade",1},; //17- {"","indFinal","",0,"Consumidor final",1},; //18- {"","indPres","",0,"Presença do Comprador",1},; //19- {"","procEmi","",0,"Processo",1},; //20- {"","verProc","",0,"Versão do Processo",0}}) //21- AADD(aEmit,{{"","CNPJ","emit",20,"CNPJ",0},; //1- tratamento especial {"","CPF","",0,"CPF",0},; //2- {"","xNome","",0,"Nome / Razão Social",0},; //3- {"","xFant","",0,"Nome Fantasia",0},; //4- {"","xLgr","enderEmit",15,"Endereço",0},; //5- tratamento especial {"","nro","",0,"Endereço",0},; //6- tratamento especial {"","xCpl","",0,"Endereço",0},; //7- tratamento especial {"","xBairro","",0,"Bairro / Distrito",0},; //8- {"","cMun","",0,"Município",7},; //9- {"","xMun","",0,"Município",-10},; //10- {"","UF","",0,"UF",0},; //11- {"","CEP","",0,"CEP",0},; //12- tratamento especial {"","cPais","",0,"País",4},; //13- {"","xPais","",0,"País",-7},; //14- {"","fone","",0,"Telefone",0},; //15- tratamento especial {"","IE","",0,"Inscrição Estadual",0},; //16- {"","IEST","",0,"Inscrição Estadual do Substituto Tributário",0},; //17- {"","IM","",0,"Inscrição Municipal",0},; //18- {"","CNAE","",0,"CNAE Fiscal",0},; //19- {"","CRT","",0,"Código de Regime Tributário",1}}) //20- AADD(aDest,{{"","CNPJ","dest",20,"CNPJ",0},; //1- {"","CPF","",0,"CPF",0},; //2- {"","idEstrangeiro","",0,"",0},; //3- {"","xNome","",0,"Nome / Razão Social",0},; //4- {"","xLgr","enderDest",15,"Endereço",0},; //5- tratamento especial {"","nro","",0,"Endereço",0},; //6- tratamento especial {"","xCpl","",0,"Endereço",0},; //7- tratamento especial {"","xBairro","",0,"Bairro / Distrito",0},; //8- {"","cMun","",0,"Município",7},; //9- {"","xMun","",0,"Município",-10},; //10- {"","UF","",0,"UF",0},; //11- {"","CEP","",0,"CEP",0},; //12- tratamento especial {"","cPais","",0,"País",4},; //13- {"","xPais","",0,"País",-7},; //14- {"","fone","",0,"Telefone",0},; //15- tratamento especial {"","indIEDest","",0,"Indicador IE",2},; //16- tratamento especial {"","IE","",0,"Inscrição Estadual",0},; //17- {"","ISUF","",0,"Inscrição SUFRAMA",0},; //18- {"","IM","",0,"IM",0},; //19- {"","email","",0,"E-mail",0}}) //20- * Conteudo elementos da Matriz = {VALOR_TAG,TAG,LABEL_HTML} AADD(aTotais,{{"0.00","vBC","Base de Cálculo ICMS"},; //1- {"0.00","vICMS","Valor do ICMS"},; //2- {"0.00","vICMSDeson","Valor do ICMS Desonerado"},; //3- {"0.00","vFCPUFDest","Valor Total ICMS FCP"},; //4- {"0.00","vBCST","Base de Cálculo ICMS ST"},; //5- {"0.00","vST","Valor ICMS Substituição"},; //6- {"0.00","vProd","Valor Total dos Produtos"},; //7- {"0.00","vFrete","Valor do Frete"},; //8- {"0.00","vSeg","Valor do Seguro"},; //9- {"0.00","vDesc","Valor Total dos Descontos"},; //10- {"0.00","vII","Valor Total do II"},; //11- {"0.00","vIPI","Valor Total do IPI"},; //12- {"0.00","vPIS","Valor do PIS"},; //13- {"0.00","vCOFINS","Valor da COFINS"},; //14- {"0.00","vOutro","Outras Despesas Acessórias"},; //15- {"0.00","vNF","Valor Total da NFe"}}) //16- * Conteudo elementos da Matriz = {VALOR_TAG,TAG,TAG_PAI,Elemento_Final_TAG_PAI,LABEL_HTML,TAM_LABEL} AADD(aTransp,{{"","modFrete","transp",17,"Modalidade do Frete",1},; //1- {"","CNPJ","transporta",8,"CNPJ",0},; //2- {"","CPF","",0,"CPF",0},; //3- {"","xNome","",0,"Razão Social / Nome",0},; //4- {"","IE","",0,"Inscrição Estadual",0},; //5- {"","xEnder","",0,"Endereço Completo",0},; //6- {"","xMun","",0,"Município",0},; //7- {"","UF","",0,"UF",0},; //8- {"",'placa','veicTransp',11,'Placa',0},; //9- {"","UF","",0,"UF",0},; //10- {"","RNTC","",0,"RNTC",0},; //11- {"","qVol","vol",17,"Quantidade",0},; //12- {"","esp","",0,"Espécie",0},; //13- {"","marca","",0,"Marca dos Volumes",0},; //14- {"","nVol","",0,"Volume",0},; //15- {"","pesoL","",0,"Peso Líquido",0},; //16- {"","pesoB","",0,"Peso Bruto",0}}) //17- * Conteudo elementos da Matriz = {VALOR_TAG,TAG} AADD(aCobr,{{"","nDup"},; //1- {"","dVenc"},; //2- {"","vDup"},; //3- {"","nDup"},; //4- {"","dVenc"},; //5- {"","vDup"},; //6- {"","nDup"},; //7- {"","dVenc"},; //8- {"","vDup"},; //9- {"","nDup"},; //10- {"","dVenc"},; //11- {"","vDup"},; //12- {"","nDup"},; //13- {"","dVenc"},; //14- {"","vDup"},; //15- {"","nDup"},; //16- {"","dVenc"},; //17- {"","vDup"},; //18- {"","nDup"},; //19- {"","dVenc"},; //20- {"","vDup"},; //21- {"","nDup"},; //22- {"","dVenc"},; //23- {"","vDup"},; //24- {"","nDup"},; //25- {"","dVenc"},; //26- {"","vDup"},; //27- {"","nDup"},; //28- {"","dVenc"},; //29- {"","vDup"}}) //30- If ! DigitoChave(cChave) Return Nil EndIf cParm:= { { "__EVENTARGUMENT", "" },; { "__EVENTTARGET", "" },; { "__EVENTVALIDATION", cEeventValidation },; { "__VIEWSTATE", cviewState },; { "__VIEWSTATEGENERATOR", cViewStateGenerator },; { "ctl00$ContentPlaceHolder1$btnConsultar", "Continuar" },; { "ctl00$ContentPlaceHolder1$captchaSom", cHiddenSom},; { "ctl00$ContentPlaceHolder1$token", cHiddenToken },; { "ctl00$ContentPlaceHolder1$txtCaptcha", cCaptcha },; { "ctl00$ContentPlaceHolder1$txtChaveAcessoCompleta", cChave },; { "ctl00$txtPalavraChave", "" },; { "hiddenInputToUpdateATBuffer_CommonToolkitScripts", "1"}} Try oInternet:= TIPClientHTTP():New(cUrl, .f.) Catch MsgInfo('Erro na Criação do Serviço') Return .f. End oInternet:SetCookie(cStringCookie) If oInternet:Open() If oInternet:POST(cParm) cRet:= oInternet:ReadAll() Else msgInfo('Erro no Post ' + cUrl, 'Aviso do Sistema') Return .F. EndIf Else msgInfo('Erro na Conexão') Return .f. EndIf oInternet:Close() If At('id="ctl00_ContentPlaceHolder1_bltMensagensErro" class="listaErro">', cRet) > 0 cPart:= Substr(cRet, (At('id="ctl00_ContentPlaceHolder1_bltMensagensErro" class="listaErro">', cRet) + 66)) cPart:= Substr(cPart, (At('
  • ', cPart) + 4)) MsgInfo(Troca_Acento(SubStr(cPart, 1, (At('
  • ', cPart) - 1)))) Return .f. EndIf Try oInternet:= TIPClientHTTP():New(cUrl1, .f.) oInternet:nConnTimeout:= 10000 Catch MsgInfo('Erro na Criação do Serviço') Return .f. End oInternet:SetCookie(cStringCookie) If oInternet:Open() cHtml:= oInternet:ReadAll() cStringCookie:= oInternet:GetCookies() Else msgInfo('Erro na Conexão') Return .f. EndIf oInternet:Close() If At('id="ctl00_ContentPlaceHolder1_lblResultadoConsulta">', cHtml) > 0 cPart:= Substr(cHtml, (At('id="ctl00_ContentPlaceHolder1_lblResultadoConsulta">', cHtml) + 52)) MsgInfo(SubStr(cPart, 1, (At('', cPart) - 1))) Return .f. EndIf If ! Empty(cHtml) nIni := At('', cParte) cFile := SubStr(cParte, nFim) //memowrit('site.txt',cfile) nIni := RAt('fixo-prod-serv-numero',cFile) c_span := SubStr(cFile, nIni) nIni := AT('',c_span)+6 nTamTag:= AT('',c_span)-nIni nTotPro:= Val(AllTrim(SubStr(c_span,nIni,nTamTag))) // Conteudo elementos da Matriz = {VALOR_TAG,TAG,LABEL_HTML,TAM_LABEL} For p_=1 To nTotPro AADD(aDet,{{"","cProd","Código do Produto",0},; //1- {"","cEAN","Código EAN Comercial",0},; //2- {"","xProd","fixo-prod-serv-descricao",0},; //3- {"","NCM","Código NCM",0},; //4- {"","NVE","",0},; //5- {"","CEST","Código CEST",0},; //6- {"","EXTIPI","Código EX da TIPI",0},; //7- {"","CFOP","CFOP",0},; //8- {"","uCom","Unidade Comercial",0},; //9- {"","qCom","Quantidade Comercial",0},; //10- {"","vUnCom","Valor unitário de comercialização",0},; //11- {"","vProd","fixo-prod-serv-vb",0},; //12- {"","cEANTrib","Código EAN Tributável",0},; //13- {"","uTrib","Unidade Tributável",0},; //14- {"","qTrib","Quantidade Tributável",0},; //15- {"","vUnTrib","Valor unitário de tributação",0},; //16- {"","vFrete","Valor Total do Frete",0},; //17- {"","vSeg","Valor do Seguro",0},; //18- {"","vDesc","Valor do Desconto",0},; //19- {"","vOutro","Outras Despesas Acessórias",0},; //20- {"","indTot","Indicador de Composição do Valor Total da NF-e",1},; //21- {"","nItemPed","Item do pedido de compra",0},; //22- {"","xPed","Número do pedido de compra",0}}) //23- AADD(aTrib, {{"","vTotTrib","Valor Aproximado dos Tributos",0}}) //1- AADD(aMedicamentos, {{"","Lote",'Nro. do Lote', 0},; //1- {"","qLote",'Quantidade de produtos no lote', 0},; //2- {"","dFab",'Data de fabricaçã', 0},; //3- {"","dVal",'Data de validade', 0},; //4- {"","vPMC",'Preço Máximo Consumido', 0},; //5- {"","infAdProd",'Descrição', 0}}) //6- AADD(aICMS,{{"","orig","Origem da Mercadoria",1},; //1- ICMS Normal e ST {"","CST","Tributação do ICMS",2},; //2- {"","CSOSN","Código de Situação da Operação",3},; //3- {"","modBC","Modalidade Definição da",1},; //4- {"","pRedBC","Percentual Redução",0},; //5- {"","vBC","Base de Cálculo",0},; //6- {"","pICMS","Alíquota do",0},; //7- {"","vICMS","Valor do",0},; //8- {"","vICMSDeson","",0},; //9- {"","motDesICMS","",0},; //10- {"","modBCST","Modalidade de determinação da BC do ICMS ST",1},; //11- {"","pMVAST","Percentual Margem Valor Adicionado do ICMS ST",0},; //12- {"","pRedBCST","Percentual da Redução de BC do ICMS ST",0},; //13- {"","vBCST","Valor da BC do ICMS ST",0},; //14- {"","pICMSST","Alíquota do imposto do ICMS ST",0},; //15- {"","vICMSST","Valor do ICMS ST",0},; //16- {"","vBCSTRet","Valor da BC do ICMS ST retido",0},; //17- {"","vICMSSTRet","Valor do ICMS ST retido",0},; //18- {"","vICMSOp","",0},; //19- {"","pDif","",0},; //20- {"","vICMSDif","",0},; //21- {"","pCredSN","Alíquota aplicável de cálculo do crédito",0},; //22- {"","vCredICMSSN","Valor de crédito do ICMS",0}}) //23- AADD(aIPI,{{"","cEnq","Código de Enquadramento", 3},; {"","CST","CST", 2},; //1- {"","vBC","Base de Cálculo", 0},; //2- {"","pIPI","Alíquota", 0},; //3- {"","vIPI","Valor IPI", 0},; //4- {"","qBCProd","", 0},; //5- {"","vAliqProd","", 0}}) //6- AADD(aPIS,{{"","CST","CST", 2},; //1- {"","vBC","Base de Cálculo", 0},; //2- {"","pPIS","Alíquota", 0},; //3- {"","vPIS","Valor", 0},; //4- {"","qBCProd","", 0},; //5- {"","vAliqProd","", 0}}) //6- AADD(aCOFINS,{{"","CST","CST",2},; //1- {"","vBC","Base de Cálculo",0},; //2-vBC {"","pCOFINS","Alíquota",0},; //3- {"","vCOFINS","Valor",0},; //4- {"","qBCProd","",0},; //5- {"","vAliqProd","",0}}) //6- Next nIni := At('
    ',cParte) cParte:= SubStr(cParte, 1, nIni - 1) //emit GeraTag("emit",cParte) nIni := At('
    ',cParte) cParte:= SubStr(cParte, 1, nIni - 1) //dest GeraTag("dest",cParte) nIni := At('', cFile) cParte:= SubStr(cFile, nIni) nIni := At('', cParte) cParte:= SubStr(cParte, 1, nIni - 1) //det GeraTag("det", cParte) nIni := At('Totais',cFile) cParte:= SubStr(cFile, nIni+42) nIni := At('
    ',cFile) cParte:= SubStr(cFile, nIni+29) nIni := At('
    Duplicatas 0 cParte:= SubStr(cFile, nIni) nIni := At('', cParte) cParte:= SubStr(cParte, 1, nIni - 1) //cobr GeraTag("cobr", cParte) EndIf GravaXML() Else msgInfo('Erro ao ler retorno da Consulta') Return .f. EndIf Return Nil *************************************** Function DigitoChave(CodigoChave) Local indice:= '4329876543298765432987654329876543298765432' Local digito nSoma:= 0 For contador:= 1 To 43 nSoma+= (Val(SubStr(CodigoChave, contador, 1)) * Val(SubStr(indice, contador, 1))) Next digito:= (nSoma % 11) If digito == 0 .Or. digito == 1 digito:= 0 Else digito:= (11 - digito) EndIf If SubStr(CodigoChave, 44, 1) != LTrim(Str(digito, 1)) MsgStop('Código da Chave Errado....', 'Aviso do Sistema') principal.oChaveNFe.SetFocus Return .f. EndIf Return .t. ************************************** Function Troca_Acento(cTexto) cTexto := StrTran( cTexto, "ó", "ó" ) cTexto := StrTran( cTexto, "á", "á" ) Return cTexto *************************************************** Function Limpar() principal.oChaveNFe.Value:=SPACE(44) principal.oTxt_captcha.Value:=SPACE(6) principal.oChaveNFe.SetFocus Return Nil *************************************************** Function Sair() principal.release Return Nil *************************************************** Function GeraTag(_tag, cParte) If _tag == "ide" cPar_:= StrTran(cFile, Chr(13) + Chr(10), "") cPar_:= StrTran(cPar_, Chr(160), "") nIni := At('Informações Complementares de Interesse do Contribuinte', cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni + 70) nIni := At('
    ', c_span) c_span := SubStr(c_span, nIni + 35) nIni := At('
    ', c_span) cinfCpl:= AllTrim(SubStr(c_span, 1, nIni - 1)) EndIf cPar_ := StrTran(cParte, Chr(13) + Chr(10), "") cPar_ := StrTran(cPar_, Chr(160), "") nIni := At('Situação Atual:', cPar_) c_span := SubStr(cPar_, nIni + 15) nIni := At('(Ambiente de autorização:', c_span) cxMotivo:= AllTrim(SubStr(c_span, 1, nIni - 1)) If "AUTORIZADA" $ cxMotivo ccStat := "100" cxMotivo:= "Autorizado o uso da NF-e" EndIf If "CANCELADA" $ cxMotivo ccStat := "101" cxMotivo:="Cancelamento de NF-e homologado" EndIf nIni := At('Data Inclusão AN',cPar_) c_span := SubStr(cPar_, nIni + 50) nIni := At('', c_span) + 6 nTamTag := At('', c_span) + 6 c_span := SubStr(c_span, nIni) nTamTag := At('', c_span) - 1 //nIni cdhRecbto:= AllTrim(SubStr(c_span, 1, nTamTag)) cdhRecbto:= SubStr(cdhRecbto, 7, 4) + "-" + SubStr(cdhRecbto, 4, 2) + "-" + Left(cdhRecbto, 2) + "T" + Right(cdhRecbto, 14) nIni := At('Digest Value da NF-e', cPar_) c_span := SubStr(cPar_, nIni + 20) nIni := At('', c_span) + 6 nTamTag := At('', c_span) - nIni cdigVal := AllTrim(SubStr(c_span, nIni, nTamTag)) nIni := At('Versão XML', cParte) c_span := SubStr(cParte, nIni) nIni := At('', c_span) + 6 nTamTag := At('', c_span) - nIni cVersao := AllTrim(SubStr(c_span, nIni, nTamTag)) For i:= 1 To Len(aIde[1]) cPar_:= cParte If i == 12 cPar_:= cFile EndIf If i == 13 cPar_:= cFile EndIf nIni := AT(aIde[1,i,5],cPar_) c_span:= SubStr(cPar_, nIni) If i != 16 nIni :=AT('', c_span) + 6 nTamTag:= AT('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) Else nIni := AT('', c_span) c_tag:= AllTrim(SubStr(c_span, 1, nIni - 1)) If AT('produção', c_tag) > 0 c_tag:= "1" Else c_tag:= "2" EndIf ctpAmb:= c_tag EndIf If i == 2 c_tag:= SubStr(cChave, 36, 8) EndIf If i == 8 .or. i == 9 If !Empt(c_tag) c_tag:= SubStr(c_tag, 7, 4) + "-" + SubStr(c_tag, 4, 2) + "-" + Left(c_tag, 2) + "T" + SubStr(c_tag, 12) EndIf EndIf If i == 15 c_tag:= Right(c_tag, 1) EndIf If aIde[1, i, 6] != 0 If aIde[1, i, 6] > 0 c_tag:= Left(c_tag, aIde[1, i, 6]) Else c_tag:= SubStr(c_tag, Abs(aIde[1, i, 6]) + 1) EndIf EndIf aIde[1, i, 1]:= c_tag If i == 21 cverAplic:= c_tag EndIf Next EndIf If _tag == "emit" For i:= 1 To Len(aEmit[1]) cPar_:= StrTran(cParte, Chr(13) + Chr(10), "") cPar_:= StrTran(cPar_, Chr(160), "") nIni := AT(aEmit[1, i, 5], cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := AT('', c_span) + 6 nTamTag:= AT('', c_span) - nIni c_tag:=AllTrim(SubStr(c_span, nIni, nTamTag)) If i >= 1 .and. i <= 2 c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, "/", "") c_tag:= StrTran(c_tag, "-", "") EndIf If i >= 5 .and. i <= 7 nIni:= AT(",,", c_tag) If nIni == 0 nIni:= AT(",", c_tag) EndIf If i == 5 c_tag:= Left(c_tag, nIni - 1) //xlg ElseIf i == 6 c_tag:= AllTrim(SubStr(c_tag, nIni + 2)) nIni := AT(" ", c_tag) If nIni > 0 c_tag:= Left(c_tag, nIni - 1) //nro EndIf Else c_tag:= AllTrim(SubStr(c_tag, nIni + 2)) nIni := AT(" ", c_tag) If nIni>0 c_tag:= AllTrim(SubStr(c_tag, nIni + 1)) // xcpl Else c_tag:= "" EndIf EndIf EndIf If i == 12 c_tag:= StrTran(c_tag,"-","") EndIf If i==15 c_tag:= StrTran(c_tag,"(","") c_tag:= StrTran(c_tag,")","") c_tag:= StrTran(c_tag,"-","") EndIf If aEmit[1, i, 6] != 0 If aEmit[1, i, 6] > 0 c_tag:= left(c_tag,aEmit[1, i, 6]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aEmit[1, i, 6]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf aEmit[1, i, 1]:= c_tag EndIf Next EndIf If _tag == "dest" For i=1 To Len(aDest[1]) cPar_:= StrTran(cParte, Chr(13) + Chr(10), "") cPar_:= StrTran(cPar_, Chr(160), "") nIni := AT(aDest[1, i, 5], cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := AT('',c_span)+6 nTamTag:= AT('',c_span)-nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If i >= 1 .and. i <= 2 c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, "/", "") c_tag:= StrTran(c_tag, "-", "") EndIf If i >= 5 .and. i <= 7 nIni:= AT(",,", c_tag) If nIni == 0 nIni:= AT(",", c_tag) EndIf If i == 5 c_tag:= Left(c_tag, nIni - 1) ElseIf i == 6 c_tag:= AllTrim(SubStr(c_tag, nIni + 2)) nIni := AT(" ", c_tag) If nIni > 0 c_tag:= Left(c_tag, nIni - 1) EndIf Else c_tag:= AllTrim(SubStr(c_tag, nIni + 2)) nIni := AT(" ", c_tag) If nIni > 0 c_tag:= AllTrim(SubStr(c_tag, nIni + 1)) Else c_tag:= "" EndIf EndIf EndIf If i == 12 c_tag:= StrTran(c_tag, "-", "") EndIf If i == 15 c_tag:= StrTran(c_tag, "(", "") c_tag:= StrTran(c_tag, ")", "") c_tag:= StrTran(c_tag, "-", "") EndIf If i == 16 c_tag:= AllTrim(Str(Val(c_tag))) EndIf If aDest[1, i, 6] != 0 If aDest[1, i, 6] > 0 c_tag:= left(c_tag, aDest[1, i, 6]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aDest[1,i,6]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf aDest[1, i, 1]:= c_tag EndIf Next EndIf If _tag == "det" cPar_:= StrTran(cParte, Chr(13) + Chr(10), "") cParT_:= StrTran(cPar_, Chr(160), "") nIni := At('1', cParT_) nfim := At('2', cParT_) - nIni If nFim == 0 cPar_:= SubStr(cParT_, nIni) Else cPar_:= SubStr(cParT_, nIni, nFim) EndIf For p_:= 1 To Len(aDet) For i:= 1 To Len(aDet[p_]) nIni:= At(aDet[p_, i, 3], cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := At('',c_span)+6 nTamTag:= At('',c_span)-nIni c_tag := AllTrim(SubStr(c_span,nIni,nTamTag)) If aDet[p_, i, 4] != 0 If aDet[p_, i, 4] > 0 c_tag:= left(c_tag, aDet[p_, i, 4]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aDet[p_, i, 4]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf If i != 3 .And. i != 1 c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") EndIf aDet[p_, i, 1]:= c_tag EndIf Next For i:= 1 To Len(aTrib[p_]) nIni:= AT(aTrib[p_, i, 3], cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := AT('', c_span) + 6 nTamTag:= AT('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aTrib[p_, i, 4] != 0 If aTrib[p_, i, 4] > 0 c_tag:= Left(c_tag, aTrib[p_, i, 4]) Else c_tag:= Alltrim(SubStr(c_tag, Abs(aTrib[p_, i, 4]) + 1)) c_tag:= Alltrim(StrTran(c_tag, "-", "")) EndIf EndIf c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") aTrib[p_, i, 1]:= c_tag EndIf Next nIni:= AT('
    ICMS Normal e ST', cPar_) If nIni > 0 cPar1_:= SubStr(cPar_, nIni, At('PIS', cPar_)-nIni) For i:= 1 To Len(aICMS[p_]) nIni:= At(aICMS[p_, i, 3], cPar1_) If nIni > 0 c_span := SubStr(cPar1_, nIni) nIni := At('', c_span) + 6 nTamTag:= At('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aICMS[p_, i, 4] != 0 If aICMS[p_, i, 4] > 0 c_tag:= Left(c_tag, aICMS[p_, i, 4]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aICMS[p_, i, 4]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") aICMS[p_, i, 1]:= c_tag EndIf Next EndIf nIni:= AT('Imposto Sobre Produtos Industrializados', cPar_) If nIni > 0 cPar1_:= SubStr(cPar_, nIni, At('PIS', cPar_)-nIni) For i:= 1 To Len(aIPI[p_]) nIni:= AT(aIPI[p_, i, 3], cPar1_) If nIni > 0 c_span := SubStr(cPar1_, nIni) nIni := AT('', c_span) + 6 nTamTag:= AT('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aIPI[p_, i, 4] != 0 If aIPI[p_, i, 4] > 0 c_tag:= Left(c_tag, aIPI[p_, i, 4]) Else c_tag:= Alltrim(SubStr(c_tag, Abs(aIPI[p_, i, 4]) + 1)) c_tag:= Alltrim(StrTran(c_tag, "-", "")) EndIf EndIf c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") aIPI[p_, i, 1]:= c_tag EndIf Next EndIf nIni:= At('PIS', cPar_) If nIni > 0 cPar1_:= SubStr(cPar_, nIni, AT('COFINS', cPar_)-nIni) For i:= 1 To Len(aPIS[p_]) nIni:= AT(aPIS[p_, i, 3], cPar1_) If nIni > 0 c_span := SubStr(cPar1_, nIni) nIni := At('', c_span) + 6 nTamTag:= At('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aPIS[p_,i,4] != 0 If aPIS[p_,i,4] > 0 c_tag:= Left(c_tag,aPIS[p_,i,4]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aPIS[p_, i, 4]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") aPIS[p_, i, 1]:= c_tag EndIf Next EndIf nIni:= AT('COFINS', cPar_) If nIni > 0 cPar1_:= SubStr(cPar_, nIni) For i:= 1 To Len(aCOFINS[p_]) nIni := AT(aCOFINS[p_, i, 3], cPar1_) If nIni > 0 c_span := SubStr(cPar1_, nIni) nIni := AT('', c_span) + 6 nTamTag:= AT('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aCOFINS[p_, i, 4] != 0 If aCOFINS[p_, i, 4] > 0 c_tag:= left(c_tag, aCOFINS[p_, i, 4]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aCOFINS[p_, i, 4]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") aCOFINS[p_, i, 1]:= c_tag EndIf Next EndIf nIni:= At('Detalhamento específico dos medicamentos', cPar_) If nIni > 0 cPar1_:= SubStr(cPar_, nIni) For i:= 1 To Len(aMedicamentos[p_]) nIni:= AT(aMedicamentos[p_, i, 3], cPar1_) If nIni > 0 c_span := SubStr(cPar1_, nIni) nIni := At('', c_span) + 6 nTamTag:= At('', c_span) - nIni c_tag := AllTrim(SubStr(c_span, nIni, nTamTag)) If aMedicamentos[p_,i,4] != 0 If aMedicamentos[p_,i,4] > 0 c_tag:= Left(c_tag,aMedicamentos[p_,i,4]) Else c_tag:= AllTrim(SubStr(c_tag, Abs(aMedicamentos[p_, i, 4]) + 1)) c_tag:= AllTrim(StrTran(c_tag, "-", "")) EndIf EndIf If i != 6 c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, ",", ".") EndIf If StrZero(i, 2) $ "-03-04" c_tag:= SubStr(c_tag,7,4)+"-"+SubStr(c_tag,4,2)+"-"+left(c_tag,2) EndIf aMedicamentos[p_, i, 1]:= c_tag EndIf Next EndIf If p_ == (Len(aDet)-1) nIni := At(''+AllTrim(Str(p_+1)), cParT_) cPar_:= SubStr(cParT_, nIni) Else nIni:= At(''+AllTrim(Str(p_+1)), cParT_) nFim:= At(''+AllTrim(Str(p_+2)), cParT_) - nIni If nFim == 0 cPar_ := SubStr(cParT_, nIni) Else cPar_ := SubStr(cParT_, nIni, nFim) EndIf EndIf Next EndIf If _tag == "totais" For i:= 1 To Len(aTotais[1]) cPar_:= StrTran(cParte,Chr(13)+Chr(10),"") cPar_:= StrTran(cPar_,Chr(160),"") nIni := AT(aTotais[1,i,3],cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := AT('',c_span)+6 nTamTag:= AT('',c_span)-nIni c_tag := AllTrim(SubStr(c_span,nIni,nTamTag)) c_tag := StrTran(c_tag,".","") c_tag := StrTran(c_tag,",",".") aTotais[1,i,1]:=c_tag EndIf Next EndIf If _tag == "transp" For i:= 1 To Len(aTransp[1]) cPar_:= StrTran(cParte,Chr(13)+Chr(10),"") cPar_:= StrTran(cPar_,Chr(160),"") nIni := AT(aTransp[1,i,5],cPar_) If nIni > 0 c_span := SubStr(cPar_, nIni) nIni := AT('',c_span)+6 nTamTag:= AT('',c_span)-nIni c_tag := AllTrim(SubStr(c_span,nIni,nTamTag)) If i >= 2 .and. i <= 3 c_tag:= StrTran(c_tag, ".", "") c_tag:= StrTran(c_tag, "/", "") c_tag:= StrTran(c_tag, "-", "") EndIf If aTransp[1,i,6] != 0 If aTransp[1,i,6] > 0 c_tag:= left(c_tag,aTransp[1,i,6]) Else c_tag:= AllTrim(SubStr(c_tag,Abs(aTransp[1,i,6])+1)) c_tag:= AllTrim(StrTran(c_tag,"-","")) EndIf EndIf aTransp[1,i,1]:= c_tag EndIf Next EndIf If _tag == "cobr" cPar_:= StrTran(cParte,Chr(13)+Chr(10),"") cPar_:= StrTran(cPar_,Chr(160),"") For i:= 1 To Len(aCobr[1]) nIni:=AT('',cPar_) If nIni>0 cPar_:=SubStr(cPar_, nIni+6) nTamTag:=AT('',cPar_)-1 c_tag := AllTrim(SubStr(cPar_,1,nTamTag)) c_tag := StrTran(c_tag,".","") c_tag := StrTran(c_tag,",",".") If StrZero(i,2) $ "-02-05-08-11-14-17-20-23-26-29" c_tag:= SubStr(c_tag,7,4)+"-"+SubStr(c_tag,4,2)+"-"+left(c_tag,2) EndIf aCobr[1,i,1]:= c_tag Else Exit EndIf Next EndIf Return Nil *************************************************** Function GravaXML() Local cXML:='' cTagPai := "" nFimTagPai:= 0 For i:= 1 To Len(aIde[1]) If ! Empty(aIde[1,i,3]) nFimTagPai:=aIde[1,i,4] cTagPai+="|"+StrZero(nFimTagPai,2)+aIde[1,i,3] cXML+='<'+aIde[1,i,3]+'>' EndIf If ! Empty(aIde[1,i,1]) cXML+= '<'+aIde[1,i,2]+'>'+aIde[1,i,1]+'' EndIf If i == nFimTagPai nIni:=RAT("|",cTagPai) cTag:=Substr(cTagPai,nIni+1) cXML+='' cTagPai:=SubStr(cTagPai,1,nIni-1) If nIni>1 nIni:=RAT("|",cTagPai) nFimTagPai:=Val(Substr(cTagPai,nIni+1,2)) Else nFimTagPai:=0 EndIf EndIf Next For i:= 1 To Len(aEmit[1]) If ! Empty(aEmit[1,i,3]) nFimTagPai:= aEmit[1,i,4] cTagPai+="|"+StrZero(nFimTagPai,2)+aEmit[1,i,3] cXML +='<'+aEmit[1,i,3]+'>' EndIf If !Empty(aEmit[1,i,1]) cXML+= '<'+aEmit[1,i,2]+'>'+aEmit[1,i,1]+'' EndIf If i == nFimTagPai nIni:= RAT("|",cTagPai) cTag:= Substr(cTagPai,nIni+1) cXML+= '' cTagPai:= SubStr(cTagPai,1,nIni-1) If nIni > 1 nIni := RAT("|",cTagPai) nFimTagPai:= Val(Substr(cTagPai,nIni+1,2)) Else nFimTagPai:= 0 EndIf EndIf Next For i:= 1 To Len(aDest[1]) If !Empty(aDest[1,i,3]) nFimTagPai:=aDest[1,i,4] cTagPai+="|"+StrZero(nFimTagPai,2)+aDest[1,i,3] cXML+='<'+aDest[1,i,3]+'>' EndIf If !Empty(aDest[1,i,1]) cXML+='<'+aDest[1,i,2]+'>'+aDest[1,i,1]+'' EndIf If i == nFimTagPai nIni:= RAT("|",cTagPai) cTag:= Substr(cTagPai,nIni+1) cXML+= '' cTagPai:= SubStr(cTagPai,1,nIni-1) If nIni > 1 nIni:= RAT("|",cTagPai) nFimTagPai:= Val(Substr(cTagPai,nIni+1,2)) Else nFimTagPai:= 0 EndIf EndIf Next For p_:= 1 To Len(aDet) cXML+= '' For i:= 1 To Len(aDet[p_]) If !Empty(aDet[p_,i,1]) cXML+= '<'+aDet[p_,i,2]+'>'+aDet[p_,i,1]+'' EndIf Next lpoemTag:= .F. For i:= 1 To Len(aMedicamentos[p_]) If i == 1 If ! Empty(aMedicamentos[p_,i,1]) cXML+= '' + aMedicamentos[p_,i,1] + '' lpoemTag:=.T. EndIf Else If ! Empty(aMedicamentos[p_,i,1]) If i == 6 cDiscAdicional:= '<'+aMedicamentos[p_,i,2]+'>'+ aMedicamentos[p_,i,1] + '' Else cXML+='<'+aMedicamentos[p_,i,2]+'>'+ aMedicamentos[p_,i,1] + '' EndIf EndIf EndIf Next If lpoemTag cXML+='' EndIf cXML+= '' For i:= 1 To Len(aTrib[p_]) If ! Empty(aTrib[p_,i,1]) cXML+='<'+aTrib[p_,i,2]+'>'+ aTrib[p_,i,1] + '' EndIf Next cXML+= '' cTag_:='ICMS' For i:= 1 To Len(aICMS[p_]) If i == 1 If ! Empty(aICMS[p_, 2, 1]) cTag_+= aICMS[p_, 2, 1] Else cTag_+= 'SN' + aICMS[p_, 3, 1] EndIf cXML+= '<' + cTag_ + '>' EndIf If !Empty(aICMS[p_, i, 1]) If aICMS[p_, 2, 1] == '00' If StrZero(i, 2) $ "-01-02-04-06-07-08" cXML+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '10' If StrZero(i, 2) $ "-01-02-04-06-07-08-11-12-13-14-15-16" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '20' If StrZero(i, 2) $ "-01-02-04-05-06-07-08-09-10" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '30' If StrZero(i, 2) $ "-01-02-11-12-13-14-15-16-09-10" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '40' .Or. aICMS[p_, 2, 1] == '41' .Or. aICMS[p_, 2, 1] == '50' If StrZero(i, 2) $ "-01-02-09-10" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '51' If StrZero(i, 2) $ "-01-02-04-05-06-07-08-19-20-21" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '60' If StrZero(i, 2) $ "-01-02-17-18" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '70' If StrZero(i, 2) $ "-01-02-04-05-06-07-08-09-10-11-12-13-14-15-16" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf ElseIf aICMS[p_, 2, 1] == '90' If StrZero(i, 2) $ "-01-02-04-05-06-07-08-11-12-13-14-15-16" cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf Else cXml+= '<' + aICMS[p_, i, 2] + '>' + aICMS[p_, i, 1] + '' EndIf EndIf Next cXML+='' lpoemTag:= .F. For i:= 1 To Len(aIPI[p_]) If i == 1 If ! Empty(aIPI[p_,i,1]) cXML+= '' + aIPI[p_,i,1] + '' lpoemTag:=.T. EndIf Else If ! Empty(aIPI[p_,i,1]) cXML+='<'+aIPI[p_,i,2]+'>'+ aIPI[p_,i,1] + '' EndIf EndIf Next If lpoemTag cXML+='' EndIf lpoemTag:= .F. For i:= 1 To Len(aPIS[p_]) If i == 1 If ! Empty(aPIS[p_, i, 1]) If Val(aPIS[p_, i, 1]) >= 1 .And. Val(aPIS[p_, i, 1]) <= 2 cXML+= '' ElseIf Val(aPIS[p_, i, 1]) == 3 cXML+= '' ElseIf Val(aPIS[p_, i, 1]) >= 4 .And. Val(aPIS[p_, i, 1]) <= 9 cXML+= '' ElseIf Val(aPIS[p_, i, 1]) >= 49 .And. Val(aPIS[p_, i, 1]) <= 99 cXML+= '' EndIf lpoemTag:= .T. EndIf EndIf If ! Empty(aPIS[p_, i, 1]) cXML+= '<' + aPIS[p_,i,2] + '>' + aPIS[p_,i,1] + '' EndIf Next If lpoemTag If Val(aPIS[p_, 1, 1]) >= 1 .And. Val(aPIS[p_, 1, 1]) <= 2 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) == 3 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 4 .And. Val(aPIS[p_, 1, 1]) <= 9 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 49 .And. Val(aPIS[p_, 1, 1]) <= 99 cXML+= '' EndIf EndIf lpoemTag:=.F. For i:= 1 To Len(aCOFINS[p_]) If i == 1 If !Empty(aCOFINS[p_,i,1]) If Val(aPIS[p_, 1, 1]) >= 1 .And. Val(aPIS[p_, 1, 1]) <= 2 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) == 3 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 4 .And. Val(aPIS[p_, 1, 1]) <= 9 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 49 .And. Val(aPIS[p_, 1, 1]) <= 99 cXML+= '' EndIf lpoemTag:=.T. EndIf EndIf If !Empty(aCOFINS[p_,i,1]) cXML+= '<' + aCOFINS[p_, i, 2] + '>' + aCOFINS[p_, i, 1] + '' EndIf Next If lpoemTag If Val(aPIS[p_, 1, 1]) >= 1 .And. Val(aPIS[p_, 1, 1]) <= 2 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) == 3 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 4 .And. Val(aPIS[p_, 1, 1]) <= 9 cXML+= '' ElseIf Val(aPIS[p_, 1, 1]) >= 49 .And. Val(aPIS[p_, 1, 1]) <= 99 cXML+= '' EndIf EndIf cXML+= '' If ! Empty(cDiscAdicional) cXml+= cDiscAdicional EndIf cXML+= '' Next cXML+='' For i:= 1 To Len(aTotais[1]) If !Empty(aTotais[1,i,1]) cXML+= '<'+aTotais[1,i,2]+'>'+aTotais[1,i,1]+'' EndIf Next cXML+= '' For i:= 1 To Len(aTransp[1]) If !Empty(aTransp[1,i,3]) nFimTagPai:= aTransp[1,i,4] cTagPai+= "|"+StrZero(nFimTagPai,2)+aTransp[1,i,3] cXML+= '<'+aTransp[1,i,3]+'>' EndIf If ! Empty(aTransp[1,i,1]) cXML+= '<'+aTransp[1,i,2]+'>'+aTransp[1,i,1]+'' EndIf If i == nFimTagPai nIni:= RAT("|",cTagPai) cTag:= Substr(cTagPai,nIni+1) cXML+= '' cTagPai:= SubStr(cTagPai,1,nIni-1) If nIni > 1 nIni := RAT("|",cTagPai) nFimTagPai:= Val(Substr(cTagPai,nIni+1,2)) Else nFimTagPai:=0 EndIf If SubStr(cTag,3)=="vol" cXML+='' EndIf EndIf Next If ! Empty(aCobr[1,1,1]) cXML+= '' For i:= 1 To Len(aCobr[1]) If ! Empty(aCobr[1,i,1]) If StrZero(i,2) $ "-01-04-07-10-13-16-19-22-25-28" If i > 2 cXML+= '' EndIf cXML+= '' EndIf cXML+= '<'+aCobr[1,i,2]+'>'+aCobr[1,i,1]+'' EndIf Next cXML+= '' EndIf If ! Empty(cinfCpl) .or. !Empt(cinfAdFisco) cXML+= '' If ! Empty(cinfAdFisco) cXML+= '' + cinfAdFisco + '' EndIf If ! Empty(cinfCpl) cXML+= ''+cinfCpl+'' EndIf cXML+= '' EndIf cXML+= '' cXML+= '' cXML+= '' cXML+= '' cXML+= ''+cdigVal+'' cXML+= '' cXML+= ''+ctpAmb+''+cverAplic+''+cChave+''+cdhRecbto+'' cXML+= ''+cnProt+''+cdigVal+''+ccStat+''+cxMotivo+'' cXML+= '' cArqXml := cChave + "-nfe.xml" cIniFolder:=DiskName() + ":\"+CurDir()+"\" cArqXml :=PutFile ({{'Arquivos xML','*.xml'}} , "Gravar Arquivo xML" , cIniFolder ,, cArqXml ) nArqHandle:= FCREATE(cArqXml, 0 ) FWRITE(nArqHandle,cXML) FCLOSE(nArqHandle) MsgInfo("xML criado com sucesso!") Return Nil