;** RO_0034 ********************************************************************
;** Imprime a Digitacao do Romaneio                          ** Auto Molas **  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 10/12/2010 por Bruno Carvalho
;Ultima Alteracao: 13/04/2011 por Bruno Carvalho
;Motivo Alteracao: Ajustes           

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************

;************************** IMPRESSAO DO CABECALHO *****************************
Proc Cabecalho()

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

Moveto "Faturac"

Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP                                   
 
Print File ARQIMP "-------------------------------------------------------------------------"+"\n"
Print File ARQIMP "\027E"+"AUTO MOLAS SAO CRISTOVAO"+"\027F"+Spaces(12)+"Orcamento: "+Format("W06.3,AL",NOTAFISC)+"    Data: "+Format("D13",Today())+"\n"
Print File ARQIMP "========================================================================="+"\n"
Print File ARQIMP " Cliente: "+"\027E"+Format("W05,AL",[Codigo])+Format("W46,AL",[Razao Social])+"\027F"+Spaces(20)
Print File ARQIMP "Telefone: "+Format("W25,AL",[Telefone])+"\n"
Print File ARQIMP " Endereco: "+Ltrim(RTrim(Format("W30,AL",[Endereco])))+" - "+Ltrim(RTrim(Format("W20,AL",[Bairro])))
Print File ARQIMP Spaces(05)+Ltrim(RTrim(Format("W20,AL",[Cidade])))+"/"+Ltrim(RTrim(Format("W02,AL",[UF])))+"\n"
Print File ARQIMP "      CGC: "+Format("W18,AL",[CGC])+"\n"
Print File ARQIMP "\015" ;Imprime 17 Caracteres por polegada
Print File ARQIMP "============================================================================================================================="+"\n"
Print File ARQIMP " Item|Codigo     |Referencia|   Quantidade| Und|Descricao do Produto                            |VrUnitario|         Subtotal"+"\n"
Print File ARQIMP "-----+-----------+----------+-------------+----+------------------------------------------------+----------+-----------------"+"\n"

EndProc ;(Cabecalho)                           

;************************** IMPRESSAO DOS ITENS ********************************
Proc Itens()

Print File ARQIMP CI_6LPP

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT    = 0
TOT      = 0
CONTADOR = 0
AUX_REF  = ""

While [Numero da OF]=[FaturaC->Numero da OF]
  Checa_Linha(1) 
  Moveto [Codigo do Item]
                
  LINHA_ITEM = Spaces(01)+ Format("W04,AR",StrVal([Item da OF]))+"|"
  LINHA_ITEM = LINHA_ITEM + Format("W11,AL",[Codigo do Item])+"|"

  If Busca_Lookup("Codigo do Item",[Codigo do Item],"")
     Then AUX_REF=REG_BUSCA_LOOKUP["Referencia"]
  EndIf
  KeyPress "Esc"
  
  If AUX_REF<>""
     Then  LINHA_ITEM = LINHA_ITEM + Format("W10,AL",AUX_REF)+"|"
     Else  LINHA_ITEM = LINHA_ITEM + Spaces(10)+"|"
  EndIf
  
  LINHA_ITEM = LINHA_ITEM + Format("W13.3,EIC",[Quantidade])+"|"
  LINHA_ITEM = LINHA_ITEM + Format("W03,AR",[Unidade Fiscal])+Spaces(01)+"|"
  LINHA_ITEM = LINHA_ITEM + Format("W48,AL",[Descricao do Item])+"|"
  LINHA_ITEM = LINHA_ITEM + Format("W10.2,EIC",[Preco Unitario])+"|"
  LINHA_ITEM = LINHA_ITEM + Format("W17.2,EIC",[Preco Total])
  
  Print File ARQIMP LINHA_ITEM + "\n"
                                                   
  TOT   = TOT + [Preco Total]
  QUANT = QUANT + [Quantidade]
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

For ITEM From CONTADOR To PARAM_NITENS
    Print File ARQIMP "\n"
EndFor

Print File ARQIMP CI_8LPP  

EndProc ;(Itens)

;********************* IMPRESSAO DO RODAPE **************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

Print File ARQIMP "============================================================================================================================="+"\n"
Moveto "FaturaC"

If QUEBRAFORM
   Then Print File ARQIMP Spaces(94)+"Total..............    ********  "+"\n"
        Print File ARQIMP Spaces(94)+"Desconto ***  "+ "%....    ********  "+"\n"
        Print File ARQIMP Spaces(94)+"Total Liquido......    ********  "+"\n"
   Else Print File ARQIMP Spaces(94)+"Total.............."+Format("W12.2,EIC",TOT)+"\n"
        Print File ARQIMP Spaces(94)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
        Print File ARQIMP Format("W13.2,EIC",[Valor Desconto])+"\n"
        Print File ARQIMP Spaces(94)+"Total Liquido......"+Format("W12.2,EIC",[Valor Mercadoria Liquido])+"\n"
EndIF

Print File ARQIMP "============================================================================================================================="+"\n"

Moveto [Forma de Pagamento]
  If busca_Lookup("Tipo do Pagamento",[Forma de Pagamento],"")
     Then DESC_PAGAMENTO = REG_BUSCA_LOOKUP["Descricao Tipo Pagamento"]
     Else DESC_PAGAMENTO = ""
  EndIf
  KeyPress "Esc"
Print File ARQIMP " Forma de Pagamento: "+Format("W03,AL",[Forma de Pagamento])+Format("W20,AL",DESC_PAGAMENTO)

Moveto [Tipo de Pagamento]
If [Tipo de Pagamento] = "V"
   Then TIPO_PAGAMENTO = "A VISTA"
   Else TIPO_PAGAMENTO = "A PRAZO"
EndIf                    
Print File ARQIMP "       Tipo: "+Format("W08,AL",TIPO_PAGAMENTO)+"      N§ de Parcelas: "+Format("W03,AL",[Numero de Parcelas])+"\n"

;************************ IMPRESSAO DOS VENCIMENTOS ****************************
Print File ARQIMP "\027E"
Print File ARQIMP " Vencimentos: "

Array DATA[10]
Array VALOR[10]
K     = 0
KV    = 0

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]
  K = K+1
  KK= K+1
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W11.2,AL,EIC",[Valor])
  If K=10
     Then PARCELAS = K
          VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then PARCELAS = K
        VENC()
EndIf
Print File ARQIMP "\027F"
Print File ARQIMP "============================================================================================================================="+"\n"

If QUEBRAFORM 
   Then Print File ARQIMP "\027E"+Spaces(11)+Format("W54,AR","   * * * *  CONTINUA NO PROXIMO FORMULARIO * * * *    ")+"\027F"
   Else Moveto "FaturaC"
        Print File ARQIMP " Placa do Ve¡culo: "+Format("W14,AL",[Placa do Veiculo])+"\n"
        LINHA_OBS1 = "      Observacoes: " + Format("W102,AL",SubStr([Observacao na Nota Fiscal],001,102))+"\n\n"
        
        If SubStr([Observacao na Nota Fiscal],001,102)<>""
           Then Print File ARQIMP LINHA_OBS1
           Else Print File ARQIMP "\n\n"
        EndIf
EndIf

;************************* IMPRESSAO DO RODAPE *********************************
If QUEBRAFORM
   Then Print File ARQIMP "\n\n\n" 
   Else Print File ARQIMP Spaces(41)+"   /   /     -                                   " + "\n"
        Print File ARQIMP Spaces(41)+"-------------------------------------------------" + "\n"
        Print File ARQIMP Spaces(41)+"              Data e Assinatura"+"\n" 
EndIf        
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\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(01)
EndFor
Print File ARQIMP "\n"

KV=KV+1

EndProc

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

If (CONTADOR+nl)>(PARAM_NITENS)
   Then RodaPe(True)
        Cabecalho()
        CONTADOR=nl
        Moveto "FaturaI"
   Else CONTADOR=CONTADOR+nl
EndIf
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0270a.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
Cabecalho()
Itens()
Rodape(False) 

;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

Release Vars VALOR,DATA
Release Procs IMPFAT,VENC
LIMPAGUARDE()