;** NE_0319  *******************************************************************
;** Imprime a Digitacao da Nota de Entrada                        **  0319 **  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 16/07/2012 por Bruno Carvalho
;Alterado em     : 20/09/2012 por Nikolas
;Motivo Alteracao: colocada a quantidade convertida e custo  referente
;Alterado      em: 29/10/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes p/ impressao layout  
;Alterado      em: 18/05/2016 por Heverton Amaral
;Motivo Alteracao: Ajustes p/ impressao Limite alterado para 300               
;Alterado      em: 27/07/2016 por Bruno Carvalho
;Motivo Alteracao: Removido ASP1 e ASP2 e adaptado processo para imprimir com o ImpriArq()

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPNE()
Cabecalho()

Moveto "NotaEI"    
CoeditKey
Scan   
   Moveto "Notaei"
   MoveTo [Codigo do Item]            
   Ativa_Lookup()
   Moveto [Codigo do Item]
   Locate [Notaei->Codigo do Item]
   If Retval 
      Then COD_FORNECEDOR=[Codigo Fornecedor]
      Else COD_FORNECEDOR=""
   EndIf   
   KeyPress "ESC"  

   Print File ARQIMP Format("W03,AR",StrVal([Sequencia do Lancamento]))+Spaces(1)
   Print File ARQIMP Format("W10,AL",SubStr(COD_FORNECEDOR,1,10))+Spaces(1)
   Print File ARQIMP Format("W30,AL",[Descricao do Item])
   Print File ARQIMP Format("W10.1,EIC",[Quantidade convertida])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+"\n"

   Limite = Limite + 1
   If Limite > 300
      Then Print "\f"+"\n"
           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_10CPP+"\n"
Print File ARQIMP Format("W40,AL",NOMEMPRESA)+Spaces(04)+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"
If OK<>"I"
   Then Print File ARQIMP Spaces(65)+"NE: "+Format("W06,AL",[Numero do Lancamento])+ "\n"
   Else Print File ARQIMP Spaces(46)+CI_INEG+CI_IEXP+"NE: "+Format("W06,AL",[Numero do Lancamento])+CI_FEXP+CI_FNEG+ "\n"
EndIf
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_10CPP+"\n"
Print File ARQIMP "Sq  Item                                     Quantidade Un PrUnitar    PrTotal"+"\n"
Print File ARQIMP "--- ---------------------------------------- ---------- -- -------- ----------"+"\n"

Limite=13
EndProc

;*******************************************************************************
;* Impressao do RodaP‚                                                         *
;*******************************************************************************
Proc RodaPe()

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

Moveto "NotaEC"

Print File ARQIMP CI_10CPP+"\n"

Print File ARQIMP Spaces(05)+"  Mecadorias  Desconto     Liquido   Desp.Aces    Vr.Subst       Total"+"\n"
                                 ;;9.999.999,99777.777,776.666.666,665.555.555,555.555.555,555.555.555,55

Print File ARQIMP Spaces(05)+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",[Valor Nota Fiscal])+CI_10CPP+"\n\n"

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

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP "Vencimentos: "

Array DATA[9]
Array VALOR[9]
K=0
KV=0
Moveto "NotaECP"
Scan
  K=K+1
  DATA[K]  = Format("D13",[Data de Vencimento])
  VALOR[K] = Format("W10.2,AR,EIC",[Valor do Documento])
  If K=9
     Then VENC()
          K=0
  EndIf
EndScan
If K>0
   Then VENC()
EndIf


Moveto "NotaEC"

Print File ARQIMP "\n\n"

Print File ARQIMP "Mercadoria recebida e conferida em ___/___/______  por _________________________"+"\n\n"
Print File ARQIMP "Obs.: "+Format("W100,AL",[Observacao])
Print File ARQIMP "\f"+"\n"
Print File ARQIMP CI_10CPP+"\n"
Print File ARQIMP CI_6LPP+"\n"
Printer Off
Close Printer

EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If KV>0
   Then Print File ARQIMP Spaces(13)
EndIf
For I From 1 to K
  Print File ARQIMP DATA[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Aguarde("Imprimindo a Nota de Entrada")

ARQIMP = PrivDir()+"NE_0319.Txt"
If IsFile(ARQIMP)
   Then Deleta_Arquivo(ARQIMP)
EndIf

IMPNE()

ImpriArq(ARQIMP)
Deleta_Arquivo(ARQIMP)

Release Vars VALOR,DATA
Release Procs IMPPED,VENC,Cabecalho,Rodape
