select nfconfig m.lcComandoAtual="" m.lyTotal=$0 m.lyTotalpg=$0 m.llImprimeNotas=.t. m.llPular=.f. m.llContinuação=.f. ??? chr(27)+chr(48)+chr(15) scan all if left(nfconfig.dados,2)="->" m.lcComandoAtual=upper(alltrim(substr(nfconfig.dados,3,50))) m.lnComandoTotal=0 loop endif m.lnComandoTotal=m.lnComandoTotal+1 do case case m.lcComandoAtual="PARAMETRO" m.laParametro(m.lnComandoTotal)=alltrim(nfconfig.dados) case m.lcComandoAtual="CADASTRO" m.laCadastro(m.lnComandoTotal)=alltrim(nfconfig.dados) case m.lcComandoAtual="FATURA" m.laFatura(m.lnComandoTotal)=alltrim(nfconfig.dados) case m.lcComandoAtual="PRODUTO" m.laProduto(m.lnComandoTotal)=alltrim(nfconfig.dados) case m.lcComandoAtual="FINAL" m.laFinal(m.lnComandoTotal)=alltrim(nfconfig.dados) endcase endscan m.lnImprime=val(m.laParametro(1)) store 0 to m.lnTotalImpresso m.lnDocumento=1 && prepara CFOP m.lcCfopNome="" m.lcCfop="" select cst from entradas group by cst into array alCST select cfop,nome from cfop!cfop where ascan(m.alcst,cfop.cst)#0 and tiponf=3 into array alCFOP if _tally#0 m.lcCFOPNOME=m.alCFOP(1,2) for loop1=1 to _tally m.lcCfop=m.lcCfop+alltrim(m.alCFOP(m.loop1,1))+"/" endfor m.lcCfop=left(m.lcCfop,len(m.lcCfop)-1) endif && Imprime os produtos select entradas set order to tag cst in entradas go top in entradas m.lcCST=entradas.cst store $0 to m.lyCSTTotal,m.lyBaseICMS,m.lyValorICMS,m.lyTotalIcmsCst m.lnTotalProdutos=reccount("entradas") sum all entradas.valor*entradas.quantidade to m.lyTotalcupom && Valor da nota sem desconto m.llImprimiFinalNf= .t. scan all if m.lnTotalImpresso=0 && Imprime o cabecalho m.llImprimiFinalNf=.t. go top in numnf replace numnf with numnf+1 in numnf delete from espelhonf where nf=numnf.numnf m.lnPaginas=m.lnPaginas+1 for m.loop1=1 to 100 && Imprime o cabecalho if empty(m.laCadastro(m.loop1)) && Sai se acabou comandos exit endif m.lnY=replicate(chr(10),val(substr(m.laCadastro(m.loop1),1,3)))+chr(13) m.lnX=space(val(substr(m.laCadastro(m.loop1),4,3))) m.lcComando=substr(m.laCadastro(m.loop1),8,200) if left(m.lcComando,1)="%" && Executa um comando m.lcComando=stuff(m.lcComando,1,1,"") &lcComando loop endif ??? m.lnY+m.lnX+&lcComando m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+&lcComando endfor for m.loop1=1 to 100 && Imprime as faturas if empty(m.laFatura(m.loop1)) && Sai se acabou comandos exit endif m.lnY=replicate(chr(10),val(substr(m.laFatura(m.loop1),1,3)))+chr(13) m.lnX=space(val(substr(m.laFatura(m.loop1),4,3))) m.lcComando=substr(m.laFatura(m.loop1),8,200) if left(m.lcComando,1)="%" && Executa um comando m.lcComando=stuff(m.lcComando,1,1,"") &lcComando loop endif ??? m.lnY+m.lnX+&lcComando m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+&lcComando endfor if m.llContinuação ??? chr(13)+chr(10)+" CONTINUACAO DA NOTA N.: "+padl(numnf.numnf-1,6,"0") m.lcEspelho=m.lcEspelho+chr(13)+" CONTINUACAO DA NOTA N.: "+padl(numnf.numnf-1,6,"0") m.lnTotalImpresso=m.lnTotalImpresso+1 endif endif && Verifica se mudou o CST if m.lcCST#entradas.CST ??? chr(13)+chr(10)+space(30)+"SubTotal CST "+m.lcCST+space(20)+transform(m.lyCstTotal,"999999.99") m.lcEspelho=m.lcEspelho+chr(13)+space(30)+"SubTotal CST "+m.lcCST+space(20)+transform(m.lyCstTotal,"999999.99") select cfop locate for at(alltrim(m.lcCST),cfop.cst)#0 and tiponf=3 and calcula if !eof() m.lyBaseICMS=m.lyBaseICMS+lyCstTotal m.lyValorICMS=m.lyValorICMS+m.lyTotalIcmsCst endif select entradas m.lcCST=entradas.cst m.lnTotalImpresso=m.lnTotalImpresso+1 m.lycstTotal=$0 m.lyTotalIcmsCst=$0 endif && Imprime os produtos da nota for m.loop1=1 to 100 && Imprime os produtos if empty(m.laProduto(m.loop1)) && Sai se acabou comandos exit endif m.lnY=replicate(chr(10),val(substr(m.laProduto(m.loop1),1,3)))+chr(13) m.lnX=space(val(substr(m.laProduto(m.loop1),4,3))) m.lcComando=substr(m.laProduto(m.loop1),8,200) if left(m.lcComando,1)="%" && Executa um comando m.lcComando=stuff(m.lcComando,1,1,"") &lcComando loop endif ??? m.lnY+m.lnX+&lcComando m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+&lcComando endfor m.lyTotalIcmsCst=m.lyTotalIcmsCst+((entradas.valor*entradas.quantidade)*(entradas.icms/100)) m.lyCstTotal=m.lyCstTotal+(entradas.valor*entradas.quantidade) m.lnTotalImpresso=m.lnTotalImpresso+1 && Verifica se chegou ao final da nota if m.lnTotalImpresso>=m.lnImprime .or. m.llpular m.llImprimiFinalNf= .t. if m.lnTotalProdutos#recno("entradas") ??? " CONTINUA NA NOTA N.: "+padl(numnf.numnf+1,6,"0") m.lcEspelho=m.lcEspelho+chr(13)+" CONTINUA NA NOTA N.: "+padl(numnf.numnf+1,6,"0") m.llContinuação=.t. endif m.llPular=.f. ??? replicate(chr(10),m.lnImprime-m.lnTotalImpresso+1)+chr(13) && Imprime final da nota for m.loop1=1 to 100 && Imprime o final if empty(m.laFinal(m.loop1)) && Sai se acabou comandos exit endif m.lnY=replicate(chr(10),val(substr(m.laFinal(m.loop1),1,3)))+chr(13) m.lnX=space(val(substr(m.laFinal(m.loop1),4,3))) m.lcComando=substr(m.laFinal(m.loop1),8,200) if left(m.lcComando,1)="%" && Executa um comando m.lcComando=stuff(m.lcComando,1,1,"") &lcComando loop endif if at("TOTAL",upper(lcComando))#0 and m.lnTotalProdutos#recno("entradas") ??? m.lnY+m.lnX+replicate("*",len(&lcComando)) m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+replicate("*",len(&lcComando)) else ??? m.lnY+m.lnX+&lcComando m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+&lcComando endif endfor eject m.lnTotalImpresso=0 insert into espelhonf (nf,corponf) values (numnf.numnf,m.lcEspelho) m.lcEspelho="" endif endscan if m.llImprimiFinalNf ??? chr(13)+chr(10)+space(30)+"SubTotal CST "+m.lcCST+space(20)+transform(m.lyCstTotal,"999999.99") m.lcEspelho=m.lcEspelho+chr(13)+space(30)+"SubTotal CST "+m.lcCST+space(20)+transform(m.lyCstTotal,"999999.99") select cfop locate for at(alltrim(m.lcCST),cfop.cst)#0 and tiponf=3 and calcula if !eof() m.lyBaseICMS=m.lyBaseICMS+lyCstTotal m.lyValorICMS=m.lyValorICMS+m.lyTotalIcmsCst endif select entradas m.lnTotalImpresso=m.lnTotalImpresso+1 ??? replicate(chr(10),m.lnImprime-m.lnTotalImpresso+2)+chr(13) && Imprime final da nota for m.loop1=1 to 100 && Imorime as faturas if empty(m.laFinal(m.loop1)) && Sai se acabou comandos exit endif m.lnY=replicate(chr(10),val(substr(m.laFinal(m.loop1),1,3)))+chr(13) m.lnX=space(val(substr(m.laFinal(m.loop1),4,3))) m.lcComando=substr(m.laFinal(m.loop1),8,200) if left(m.lcComando,1)="%" && Executa um comando m.lcComando=stuff(m.lcComando,1,1,"") &lcComando loop endif ??? m.lnY+m.lnX+&lcComando m.lcEspelho=m.lcEspelho+replicate(chr(13),len(m.lnY)-1)+m.lnX+&lcComando endfor eject insert into espelhonf (nf,corponf) values (numnf.numnf,m.lcEspelho) m.lcEspelho="" endif set print toAssim conseguimos um alto grau de customização, e se em algum local tiver o sinal iniciado por % e um comando específico que deve ser processado. Fica assim o layout da NF (dentro do nfconfig.dbf):