;** NE_0345  *******************************************************************
;** Imprime a Digitacao da Nota de Entrada                ** Vitoria Textil ** *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 27/04/2017 por Anivel Augusto Rodrigues
;Alterado em     : 28/04/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Vencimentos

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPNE()
private regitens, referencia, regtbprite, itempai

Cabecalho()

ANO = AlinhM(StrVal(Year(Today())),4)
MES = AlinhM(StrVal(Month(Today())),2)

TOT_QTD_CONVERTIDA = 0
TOT=0
PRECO=0

Moveto "NotaEI"    
CoeditKey
Scan   
   
   referencia="??"
   getrecord "\\sistemas\\estoque\\itens" [NotaEI->Codigo do Item] to regitens
   if retval
      then referencia=regitens["Referencia"]
   endif   

   PRECO=0
   itempai=substr([NotaEI->Codigo do Item],1,6)+"0000"
   getrecord "\\sistemas\\vendas\\tbprite" [NotaEI->Lookup_Tabela_Preco],itempai to regtbprite
   if retval
      then PRECO=regtbprite["Preco Unitario"]
   endif   
   
   Print File ARQIMP Format("W03,AR",StrVal([Sequencia do Lancamento]))+Spaces(1)
   Print File ARQIMP Format("W21,AL",referencia)
   Print File ARQIMP Format("W30,AL",[Descricao do Item])
   Print File ARQIMP Format("W8,EIC",[Quantidade])+Spaces(1)
   Print File ARQIMP Format("W04,AL",[Unidade Entrada])     
   Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])          
   Print File ARQIMP Format("W9,AR",[Fator de Conversao])
   Print File ARQIMP Format("W11,EIC",[Quantidade Convertida])+Spaces(1)
   Print File ARQIMP Format("W04,AL",[Unidade Interna])                  
   Print File ARQIMP Format("W12.5,EIC",[Custo Medio Unitario ])+Spaces(1)          
   Print File ARQIMP Format("W09.2,EIC",PRECO)
   Print File ARQIMP Format("W07.2,EIC",[Aliquota de ICMS])+"\n"

   TOT = TOT + PRECO
   TOT_QTD_CONVERTIDA = TOT_QTD_CONVERTIDA + [Quantidade Convertida]

   Limite = Limite + 1
   If Limite > 62
      Then Print File ARQIMP "\f"
           Cabecalho()
           Moveto "NotaEI"
   Endif
EndScan
Do_It!

Rodape()
EndProc

;************************************************************************************
;Impressao do Cabecalho                                                             *
;************************************************************************************
Proc Cabecalho()

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
       
Moveto "NotaEC"

Open Printer
Printer On

Print File ARQIMP CI_15CPP+"\n"
Print File ARQIMP FIll("=",134)+"\n"
Print File ARQIMP Format("W40,AL",NOMEMPRESA)+Spaces(64)+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n"
Print File ARQIMP FIll("=",134)+"\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"+Spaces(50)+"NE "+Format("W06,AL",[Numero do Lancamento])+"\027F"
Print File ARQIMP "\020"+ "\n"

Print File ARQIMP "Fornecedor: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(17)+Format("W20,AL",[CGC])+Format("W22,AL",[Cidade])
Print File ARQIMP Format("W05,AL",[UF])+"\n"

Print File ARQIMP Spaces(17)+"Docto: "+Format("W04,AL",[Tipo do Documento])+" "+Format("W13,AL",[Numero do Documento])
Print File ARQIMP "CFO: "+Format("W15,AL",[CFO])
Print File ARQIMP "OC: "+Format("W06,AL",[Numero da OC])+"\n\n"

Print File ARQIMP "Emissao...: "+Format("D13",[Data de Emissao])+Spaces(05)
Print File ARQIMP "Entrada: "+Format("D13",[Data de Entrada])+Spaces(05)
Print File ARQIMP "Operacao: "+Format("A20",[Descricao da Operacao])+"\n"

Print File ARQIMP "Represent.: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W34,AL",[Nome Fantasia Represent])
Print File ARQIMP "TabPreco: "+Format("W06,AL",[Codigo da Tabela])+"\n"

Print File ARQIMP CI_15CPP+"\n"

Print File ARQIMP "Sq  Item                                                    Qtd UnC  PrCompra Ft.Conv  QtdConvert UnI     Pr Custo  PrTabela  %ICMS"+"\n"
Print File ARQIMP "--- -------------------------------------------------- -------- --- --------- -------- ---------- --- ------------ --------- ------"+"\n"
;                  999 12345678901234567890 123456789012345678901234567890                                     123456789123456789012123456789
Limite=13
EndProc

;*******************************************************************************
;* Impressao do RodaP‚                                                         *
;*******************************************************************************
Proc RodaPe()
private s1,s2,s3,k,kv

;********************* IMPRESSAO DOS TOTAIS **************************

Moveto "NotaEC"

Print File ARQIMP "\n"
                                   
Print File ARQIMP Spaces(01)+"  Mecadorias  Desconto     Liquido   Desp.Aces    Vr.Subst    Vr.Venda       Total  QtdConvertida      Vr ICMS"+"\n"
                                 ;;9.999.999,99777.777,776.666.666,665.555.555,555.555.555,559.999.999,995.555.555,55   5.555.555,55

Print File ARQIMP Spaces(01)+Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W10.2,EIC",[Valor Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W12.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Format("W12.2,EIC",[Valor Substituicao ICMS])
Print File ARQIMP Format("W12.2,EIC",TOT)
Print File ARQIMP Format("W12.2,EIC",[Valor Nota Fiscal])
Print File ARQIMP Spaces(3)+Format("W12,EIC",TOT_QTD_CONVERTIDA)
Print File ARQIMP Spaces(3)+Format("W10.2,EIC",[Valor ICMS])+CI_15CPP+"\n\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao Tipo Pagamento]+"   Frete:"+Format("W10.2,EIC",[Valor do Frete])+"\n"

;************************ IMPRESSAO DOS VENCIMENTOS ****************************
s1="Vencimentos: "
s2="             "
s3="             "
KV=0
for K from 1 to 24

 if isblank(DATA[k])
    then quitloop
 endif    
 
 if kv=10
    then Print File ARQIMP s1+"\n"
         Print File ARQIMP s2+"\n"
         Print File ARQIMP s3+"\n"

         kv=0
         s1="             "
         s2="             "
         s3="             "
 endif

 kv=kv+1
 s1=s1+spaces(08)+FPGT[K]          +Spaces(02)
 s2=s2+Format("D13",DATA[k])       +Spaces(02)
 s3=s3+Format("W10.2,EIC",VALOR[k])+Spaces(02)

endfor
if kv>0
  then Print File ARQIMP s1+"\n"
       Print File ARQIMP s2+"\n"
       Print File ARQIMP s3+"\n"

       kv=0
       s1=""
       s2=""
       s3=""
endif

Moveto "NotaEC"

Print File ARQIMP "\n\n"

Print File ARQIMP "Mercadoria recebida e conferida em ___/___/______  por _________________________"+"\n\n"
Print File ARQIMP "\f"
Print File ARQIMP CI_15CPP+"\n"
Print File ARQIMP CI_8LPP+"\n"
Printer Off
Close Printer

EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"NE_0345.Txt"
If IsFile(ARQIMP)
   Then Deleta_Arquivo(ARQIMP)
EndIf
AGUARDE("Imprimindo NE -> "+NE)

Array  DATA[24]
Array VALOR[24]
Array FPGT [24]

for K from 1 to 24
   DATA[k]=blankdate()
  VALOR[k]=blanknum()
   FPGT[K]=""
endfor

K=0
Moveto "NotaECP"
Scan
  K=K+1
  
   DATA[K]=[Data de Vencimento]
  VALOR[K]=[Valor do Documento]
   FPGT[K]=[Tipo do Pagamento ]
  
EndScan

IMPNE()                                      
ImpriArq(ARQIMP)

Release Vars VALOR,DATA,FPGT
Release Procs IMPNE,Cabecalho,Rodape,VENC

