;** RO2v0334   *****************************************************************
;** Imprime a Digitacao do Romaneio 2a Via               **Casa Fonseca**      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 06/01/2013 por Kamila Gomes       
;Alterado em     :   /  /     por                         
;Motivo Alteracao:    

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc Checa_Linha(Nl)
private nl,tabela
tabela=table()

If (CONTADOR+nl)>40
   Then Print File ARQIMP "\n"
        Print File ARQIMP Format("W117,AC","   * * * *  CONTINUA NO PROXIMO FORMULARIO * * * *    ")+"\f"

        Cabecalho()     
        Moveto tabela
   Else CONTADOR=CONTADOR+nl
EndIf
EndProc ;Checa_Linha()

;*******************************************************************************
;* Rotina para Impressao do cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "Answer"
Print File ARQIMP CI_10CPP+CI_8LPP
Print File ARQIMP chr(27)+chr(67)+chr(44) ;Imprime 44 Linhas por pagina

Print File ARQIMP Format("W50,AL","CONTROLE INTERNO - Balcao 3")+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"

Print File ARQIMP CI_IEXP+CI_INEG+Spaces(20)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+CI_FEXP+CI_FNEG+"\n\n"

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

Print File ARQIMP Spaces(10)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+"\n"

Print File ARQIMP Spaces(10)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])+"\n"

Print File ARQIMP Spaces(10)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])+"\n"

Print File ARQIMP "Vendedor: "+        Format("W05,AL",[Codigo do Representante])+Format("W41,AL",[Nome Fantasia Represent])
Print File ARQIMP "Dt Emissao: "+Format("D13",[Data de Emissao])+"\n"
Print File ARQIMP "Operacao: "+CI_INEG+" "+Format("W04,AL",[Codigo da Destinacao   ])+Format("W41,AL",[Descricao da Destinacao])+CI_FNEG
Print File ARQIMP "Dt Saida  : "+Format("D13",[Data de Saida  ])+"\n"

Print File ARQIMP CI_15CPP
Print File ARQIMP "-----------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP "  Item                                                                     Pedido Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "-----------------------------------------------------------------------------------------------------------------------"+"\n"

CONTADOR=13
EndProc ;(Cabecalho)

;*******************************************************************************
;* Rotina para Impressao dos itens                                             *
;*******************************************************************************            
Proc Itens()

Moveto "NotaI"
Moveto [Codigo da Empresa]
Locate [Answer->Codigo da Empresa  ],
       [Answer->Numero do Documento],
       [Answer->Serie do Documento ]
       
While [Codigo da Empresa  ]=[Answer->Codigo da Empresa  ] And
      [Numero do Documento]=[Answer->Numero do Documento] And
      [Serie do Documento ]=[Answer->Serie do Documento ]
  
  Checa_Linha(1)
  
  Moveto [Codigo do Item]
  If Busca_Lookup("Codigo do Item",[NotaI->Codigo do Item],"SM")
     Then DescrItem=Reg_Busca_Lookup["Descricao Complementar"]
     Else DescrItem=[Descricao do Item]
  EndIf
  UnLockRecord
  
  Print File ARQIMP Spaces(02)+Format("W04,AL",[Item do Documento])
  Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W54,AL",DescrItem)
  Print File ARQIMP Spaces(01)+Format("W07,AL",[Numero Pedido_Orcamento])
  Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])

  If [Quantidade]-Int([Quantidade])>0
     Then Print File ARQIMP Format("W011.3,EIC",[Quantidade])
     Else Print File ARQIMP Format("W011,EIC",[Quantidade])
  EndIf

  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Release Vars DescrItem

While CONTADOR < 28
  Checa_Linha(1)
  Print File ARQIMP "\n"
EndWhile

EndProc ;(Itens)

;*******************************************************************************
;* Rotina para Impressao do rodape                                             *
;*******************************************************************************            
Proc Rodape()
Checa_Linha(11)

Moveto "Answer"
Print File ARQIMP "-----------------------------------------------------------------------------------------------------------------------"+"\n"

Print File ARQIMP "OBS.: "
Print File ARQIMP Format("W77,AL",SubStr([Observacao na Nota Fiscal],001,73))
Print File ARQIMP Spaces(06)+"Total............."+Format("W12.2,EIC",[Valor Mercadoria])+"\n"

Print File ARQIMP "      "
Print File ARQIMP Format("W77,AL",SubStr([Observacao na Nota Fiscal],074,73))
Print File ARQIMP Spaces(06)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%... "
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP "      "
Print File ARQIMP Format("W77,AC","*** FAVOR MANTER O ENDERECO E O TELEFONE ATUALIZADOS ***")
Print File ARQIMP Spaces(06)+"Frete............."
If [Frete Incluso na Nota]="+"
   Then Print File ARQIMP Format("W13.2,EIC",[Valor do Frete])+"\n"
   Else Print File ARQIMP "\n"
EndIf
Print File ARQIMP Spaces(89)+"Total Liquido....."+Format("W12.2,EIC",[Valor Nota Fiscal])+"\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]
Print File ARQIMP "   FP: "+[Forma de Pagamento]+"\n"
        
;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP CI_INEG           
Print File ARQIMP "Vencimentos: "

Array DATA[9]
Array VALOR[9]
K=0
KV=0
Moveto "NotaV"
Moveto [Codigo da Empresa]
Locate [Answer->Codigo da Empresa  ],
       [Answer->Numero do Documento],
       [Answer->Serie do Documento ]
While [Codigo da Empresa  ]=[Answer->Codigo da Empresa  ] And
      [Numero do Documento]=[Answer->Numero do Documento] And
      [Serie do Documento ]=[Answer->Serie do Documento ]
  K=K+1
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W10.2,AR,EIC",[Valor])
  If K=9
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()
EndIf
If KV=0
   Then Print File ARQIMP "\n"
EndIf
Print File ARQIMP CI_FNEG

Print File ARQIMP Spaces(70)+"     /   /     -                                 "+"\n"
Print File ARQIMP Spaces(70)+"-------------------------------------------------"+"\n"
Print File ARQIMP Spaces(70)+"                Data e Assinatura                "+"\f"
EndProc ;(Rodape)                   

;*******************************************************************************
;* 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\n"

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0334.Txt"

If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
      
AGUARDE("Imprimindo 2a Via Romaneio -> "+[Answer->Numero do Documento])

Cabecalho()
Itens()
Rodape()
 
ImpriArq(ARQIMP)

Release Vars VALOR, DATA, CONTADOR, DescrItem, K, KV, ArqImp
Release Procs Checa_Linha, Cabecalho, Itens, Rodape, VENC

LIMPAGUARDE()
