;** NE_0344  *******************************************************************
;** Imprime a Digitacao da Nota de Entrada                 ** Casa Fonseca     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 16/02/2004 por Anivel Augusto Rodrigues
;Alterado em     : 22/11/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes 0344 
;Alterado em     : 23/11/2017 por Bruno Carvalho
;Motivo Alteracao: Ajustes ao imprimir a nota de entrada em forma de arquivo *Excel

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPNE()
private prvenda, regtbprite

AUX_NLANC = [NotaEc->Numero do Lancamento]

TABELA_TEMP=Cria_Tabela("","Empresa(A4),"+
                           "Lancamento(A6),"+
                           "Documento(A20),"+
                           "Emitente(A25),"+
                           "Dt Entrada(D),"+
                           "Seq Item(S),"+
                           "G_Item_NFe(A21),"+
                           "Codigo Item(A10),"+        
                           "Descr Item(A30),"+
                           "Quantidade(N),"+
                           "PrVenda($),"+
                           "UF(A3),"+
                           "PrUnitario($),"+
                           "PrTotal($)")

CoEdit TABELA_TEMP,"NotaEI"
Cabecalho()
Moveto "NotaEI"
Scan For [Numero do Lancamento]=AUX_NLANC

   prvenda=blanknum() 
   if not isblank(PARAM_TABELA_PRECO)
      then getrecord "\\sistemas\\vendas\\tbprite" PARAM_TABELA_PRECO,[Codigo do Item] to regtbprite
           if retval
              then prvenda=regtbprite["Preco Unitario"]
           endif
   endif                 

   Print File ARQIMP ASP1+Format("W03,AR",StrVal([Sequencia do Lancamento]))+Spaces(2)
   Print File ARQIMP Format("W21,AL",[Codigo_Fornecedor])
   Print File ARQIMP Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Format("W30,AL",[Descricao do Item])
   
   if ([Quantidade]-int([Quantidade]))>0
      then Print File ARQIMP Format("W11.3,EIC",[Quantidade])
      else Print File ARQIMP Format("W07,EIC",[Quantidade])+spaces(4)
   endif
      
   Print File ARQIMP Format("W04,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W10.2,EIC",prvenda)
   Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W11.2,EIC",[Preco Total])+ASP2+"\n"

   ;---- Adicionad Dados em tabela tempor ria ----------------------------------
   Moveto TABELA_TEMP
   End Down
   [Empresa    ] = [NotaEc->Codigo da Empresa      ]
   [Lancamento ] = [NotaEc->Numero do Lancamento   ]
   [Documento  ] = Ltrim(Format("W5",[NotaEc->Tipo do Documento]))+
                   Ltrim(Format("W11",[NotaEc->Numero do Documento]))+
                   Ltrim([NotaEc->Serie do Documento])
   [Emitente   ] = Ltrim(Format("W5",[NotaEc->Codigo]))+
                   Ltrim([NotaEc->Nome Fantasia EmitDest])
   [Dt Entrada ] = [NotaEc->Data de Entrada        ]
   [Seq Item   ] = [NotaEi->Sequencia do Lancamento]
   [G_Item_NFe ] = [NotaEi->Codigo_Fornecedor      ]
   [Codigo Item] = [NotaEi->Codigo do Item         ]
   [Descr Item ] = [NotaEi->Descricao do Item      ]
   [Quantidade ] = [NotaEi->Quantidade             ] 
   [PrVenda    ] = prvenda
   [UF         ] = [NotaEi->Unidade Fiscal         ]
   [PrUnitario ] = [NotaEi->Preco Unitario         ]
   [PrTotal    ] = [NotaEi->Preco Total            ]    
   ;----------------------------------------------------------------------------
   Moveto "NotaEI"
   
   Limite = Limite + 1
   If Limite > 62
      Then Print File ARQIMP ASP1+"\f"+ASP2+"\n"
           Cabecalho()
           Moveto "NotaEI"
   Endif
EndScan
Do_it!

Moveto "NotaEc"
FormKey

Rodape()
EndProc

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

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

Moveto "NotaEC"
Moveto [Numero do Lancamento]
Locate AUX_NLANC

Open Printer
Printer On

Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"
Print File ARQIMP ASP1+Format("W40,AL",NOMEMPRESA)+Spaces(04)+"Impressao: "+Format("D10",Today())+"-"+Time()+ASP2+ "\n\n"
If OK<>"I"
   Then Print File ARQIMP ASP1+Spaces(65)+"NE: "+Format("W06,AL",[Numero do Lancamento])+ASP2+ "\n"
   Else Print File ARQIMP ASP1+Spaces(46)+CI_INEG+CI_IEXP+"NE: "+Format("W06,AL",[Numero do Lancamento])+CI_FEXP+CI_FNEG+ASP2+ "\n"
EndIf
Print File ARQIMP ASP1+"Fornecedor: "+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+ASP2+"\n"

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

Print File ARQIMP ASP1+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])+ASP2+"\n\n"

Print File ARQIMP ASP1+"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])+ASP2+"\n"

Print File ARQIMP ASP1+"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])+ASP2+"\n"

Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+"Seq  G_Item/NFe           Item                                      Quantidade  Un  Pr.Venda  PrUnitar    PrTotal"+ASP2+"\n"
Print File ARQIMP ASP1+"---  -------------------- ---------------------------------------- -----------  -- --------- --------- ----------"+ASP2+"\n"

Limite=13
EndProc

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

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

Moveto "NotaEC"

Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"

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

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

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

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP ASP1+"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 ASP1+ASP2+"\n\n"

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

EndProc

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

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
Seta_FilePrint("NE_0000")

IMPNE()
If Ok="A"
   Then IMPRIREL(TABELA_TEMP,"R")
        Delete TABELA_TEMP
   Else Imprime_FilePrint("Imprimindo NE -> "+NE,"R")
EndIf
                                               
Release Vars VALOR,DATA
Release Procs IMPPED,VENC,Cabecalho,Rodape,
              Seta_FilePrint, Imprime_FilePrint
