Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Construtor de relatórios (NF) no próprio sistema
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00685410
Message ID:
00685521
Views:
14
This message has been marked as a message which has helped to the initial question of the thread.
[Mensagem muuiiiittooo longa] :D

Nos temos uma classe que pode ajuda você, segue fonte:

Ps: Daqui há 2 semanas estarei indo a Ribeirão a negócios, gostaria de falar com vc em pvt.
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 to
Assim 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):

->Parametro
31
->Cadastro
002127 padl(numnf.numnf,6,"0")
002093 "X"
006001 m.lcCfopNome
000049 m.lcCfop
003001 alltrim(upper(substr(cliente.nome,at(")",cliente.nome)+1,40)))
000093 cliente.identidade
000126 dtoc(date())
002001 alltrim(cliente.endereço)
000075 alltrim(cliente.bairro)
000108 cliente.cep
000126 " "
002001 alltrim(cliente.cidade)
000051 transform(cliente.tel1,"@R (xxx) xxx-xxxx")
000087 cliente.uf
000095 cliente.cpf
000126 " "
->Fatura
003000 " "
->Produto
001001 padl(entradas.código,8,"0")
000011 substr(entradas.nome,1,38)
000077 entradas.cst+" und"
000088 str(entradas.quantidade,4)
000095 transform(entradas.valor,"999,999.99")
000117 transform(entradas.valor*entradas.quantidade,"9,999,999.99")
000133 transform(entradas.icms,"99")
000000 %m.lyTotal=m.lyTotal+(entradas.valor*entradas.quantidade)
000000 %m.lyTotalpg=m.lyTotalpg+(entradas.valor*entradas.quantidade)
->Final
003008 transform(m.lyBaseICMS,"9999999.99")
000040 transform(m.lyValorICMS,"999999.99")
Blablabla....

Note que nesta nota eu usei o % para calcular o total, sem necessitar que a aplicação faça isso.

Acho que é por esse caminho que você esta querendo ir...

Obs: Este fonte já esta desatualizado, temos outros em processo que são mais eficientes, isso é coisa de 4 anos atras :P
Cordialmente,

Fabiano Costa
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform