;** NE_0000  *******************************************************************
;** Imprime a Digitacao da Nota de Entrada                 ** Padrao           *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 16/02/2004 por Anivel Augusto Rodrigues
;Alterado em     : 21/06/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Alterado em     : 04/04/2014 por Bruno Carvalho
;Motivo Alteracao: Ajustes IMPNE(), erro de sintaxe 
;Alterado em     : 20/08/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes vencimentos e outros

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

Moveto "NotaEI"
Scan
   Checa_Linha(1)

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

EndScan

Rodape()
EndProc

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

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

Moveto "NotaEC"

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"

nlin=13
EndProc

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

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

Moveto "NotaEC"

Checa_Linha(5)

Print File ARQIMP ""+"\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"

Imprime_Vencimentos()

Moveto "NotaEC"

Checa_Linha(7)

Print File ARQIMP "\n\n"

Print File ARQIMP "Mercadoria recebida e conferida em ___/___/______  por _________________________"+"\n\n"
Print File ARQIMP "\f"+"\n"
Print File ARQIMP CI_10CPP+"\n"
Print File ARQIMP CI_6LPP+"\n"

EndProc

;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(nl)
private nl,ntab

ntab=table()

If (nlin+nl)>62
   Then Print File ARQIMP "** CONTINUA PROXIMA FOLHA ***\f"+"\n"
        Cabecalho()
EndIf
nlin=nlin+nl

moveto ntab
EndProc

;*******************************************************************************
;* Verifica Vencimentos da Fatura                                              *
;*******************************************************************************
Proc Verifica_Vencimentos()
Private wc

DynArray array_dtvencto[]
DynArray array_vrvencto[]
wc=0

If Not IsEmpty("NotaECP")
   Then Moveto "NotaECP"
        scan
          wc=wc+1
          array_dtvencto[wc]=Format("D13"      ,[Data de Vencimento])
          array_vrvencto[wc]=Format("W10.2,EIC",[Valor do Documento])
        endscan
EndIf

Release Vars wc
EndProc

;*******************************************************************************
;* Imprime Vencimentos                                                         *
;*******************************************************************************
Proc Imprime_Vencimentos()
Private tit_vencto,linha_dtvencto,linha_vrvencto,wi,wc

tit_vencto    ="Vencimentos: "
linha_dtvencto=""
linha_vrvencto=""
wi=0
For wc From 1 to DynArraySize(Array_dtvencto)
  wi=wi+1

  linha_dtvencto=linha_dtvencto+array_dtvencto[wc]+Spaces(02)
  linha_vrvencto=linha_vrvencto+array_vrvencto[wc]+Spaces(02)

  If wi=5
     Then Checa_Linha(2)
          Print File ARQIMP tit_vencto+linha_dtvencto+"\n"
          Print File ARQIMP Spaces(13)+linha_vrvencto+"\n"

          wi            =0
          tit_vencto    =Spaces(13)
          linha_dtvencto=""
          linha_vrvencto=""
  EndIf
EndFor
If wi>0
   Then Checa_Linha(2)
        Print File ARQIMP tit_vencto+linha_dtvencto+"\n"
        Print File ARQIMP Spaces(13)+linha_vrvencto+"\n"
EndIf

Release Vars tit_vencto,linha_dtvencto,linha_vrvencto,wi,wc
EndProc
            


;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

AGUARDE("Imprimindo NE -> "+NE)

Seta_FilePrint("NE_0000")

Verifica_Vencimentos()

IMPNE()

ImpriArq(ARQIMP)

Release Vars nlin
Release Procs IMPNE,Cabecalho,Rodape,Checa_Linha,
              Verifica_Vencimentos,Imprime_Vencimentos

