;** RO_0164 ********************************************************************
;** Imprime a Digitacao do Romaneio                        ** SONIA MARIA **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 05/12/2006 por Humberto Felipe Santos
;Alterado em     : 19/09/2006 por Anivel Augusto Rodrigues
;Motivo Alteracao: Imprimir CODIGO DE BARRAS
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 27/08/2007 por Nikolas
;Motivo Alteracao: Ajustes layout
;Ultima Alteracao: 22/11/2010 por Bruno Carvalho
;Motivo Alteracao: Novos Ajustes 

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

If (NLINHA+nl)>20
   Then RodaPe()
        CONTADOR   = 0
        Cabecalho()
EndIf
NLINHA=NLINHA+nl
EndProc

;*******************************************************************************
;* Rotina para Impressao do Rodape                                             *
;*******************************************************************************
Proc Rodape()

Print File ARQIMP "** Continua =>"+Spaces(55)+"** Continua =>"+"\n"
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"


Print File ARQIMP Spaces(35)+"Total..............  ********  "+Spaces(02)
Print File ARQIMP Spaces(36)+"Total..............  ********  "+"\n"

Print File ARQIMP Spaces(35)+"Desconto  **  %....  ********  "+Spaces(02)
Print File ARQIMP Spaces(36)+"Desconto  **  %....  ********  "+"\n"

Print File ARQIMP Spaces(35)+"Total Liquido......  ********  "+Spaces(02)
Print File ARQIMP Spaces(36)+"Total Liquido......  ********  "+"\n\n\n\n"

Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"

Print File ARQIMP "\f"
EndProc

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

Moveto "Faturac"
cont = [Numero de Parcelas]

Print File ARQIMP CI_6LPP
Print File ARQIMP CI_15CPP
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina

Print File ARQIMP "\027E"+"SONIA"+"\027F"+Spaces(60)+"\027E"+"SONIA"+"\027F"+"\n"
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+Spaces(18)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+"\n"
Print File ARQIMP "Cliente  : "
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+Spaces(24)
Print File ARQIMP "Cliente  : "
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(11)+Format("W37,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(03)
Print File ARQIMP Spaces(11)+Format("W37,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+"\n"

Print File ARQIMP Spaces(11)+Format("W19,AL",[Bairro])
Print File ARQIMP Format("W18,AL",[CEP])
Print File ARQIMP Format("W18,AL",[IE])+Spaces(03)
Print File ARQIMP Spaces(11)+Format("W19,AL",[Bairro])
Print File ARQIMP Format("W18,AL",[CEP])
Print File ARQIMP Format("W18,AL",[IE])+"\n"

;Print File ARQIMP  Spaces(11)+Format("W17,AL",[Telefone])+Spaces(41)
;Print File ARQIMP  Spaces(11)+Format("W17,AL",[Telefone])+"\n"

;If [Endereco de Entrega] = "O MESMO"
;    Then Print File ARQIMP "Entrega  : "+"O MESMO"+Spaces(51)
;         Print File ARQIMP "Entrega  : "+"O MESMO"+"\n"
;    Else Print File ARQIMP "Entrega  : "
;         Print File ARQIMP Format("W39,AL",[Endereco de Entrega])+Spaces(02) 
;         Print File ARQIMP Format("W15,AL",[Bairro de Entrega])+Spaces(02)
;         Print File ARQIMP "Entrega  : "
;         Print File ARQIMP Format("W39,AL",[Endereco de Entrega])+Spaces(02) 
;         Print File ARQIMP Format("W15,AL",[Bairro de Entrega])+"\n"  
;EndIf

Print File ARQIMP "Vendedor : "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+Spaces(35)
Print File ARQIMP "Vendedor : "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+"\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+Spaces(03)
Print File ARQIMP "Item                               Un   Quant Unitario       Total"+"\n"
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"

NLINHA=9

EndProc

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc IMPFAT()

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

Cabecalho()

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

While ([Numero da OF]=[FaturaC->Numero da OF]) ;And (CONTADOR<>12)
  For CON From 1 to 3
     If CON=3
        Then Print File ARQIMP Spaces(02)
        Else If CON=1
                Then Checa_Linha(1)
             EndIf
     EndIf
     Moveto "FaturaI"
     Print File ARQIMP Format("W10,AL",[Codigo do Item])  
     Print File ARQIMP Spaces(01)+Format("W23,AL",[Descricao do Item])  
     Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal]) 
     Print File ARQIMP Format("W07.2,EIC",[Quantidade])
     QUANTOT=QUANTOT+[Quantidade]   
     Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])    
     Print File ARQIMP Format("W12.2,EIC",[Preco Total])+Spaces(01) 
     CON=CON+1
  EndFor
     TOT   = TOT + [Preco Total]
     CON=1
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
  Print File ARQIMP "\n"
EndWhile

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

Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"

Moveto "FaturaV"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
If RetVal
Then
dtVencto1 = 0
dtVencto2 = 0
dtVencto3 = 0
dtVencto4 = 0
ValorVen1 = 0
ValorVen2 = 0
ValorVen3 = 0
ValorVen4 = 0
    i=1
    While [Numero da OF] = [FaturaC->Numero da OF]
      Switch
      Case i = 1:
            dtvencto1 = [Data ]
            valorven1 = [Valor]
            i=i+1
      Case i = 2:
            dtvencto2 = [Data ]
            valorven2 = [Valor]
            i=i+1

      Case i = 3:
            dtvencto3 = [Data ]
            valorven3 = [Valor]
            i=i+1

      Case i = 4:
            dtvencto4 = [Data ]
            valorven4 = [Valor]
            i=i+1
      EndSwitch
      Skip
      If EOT() Then QuitLoop Endif

    EndWhile
Endif

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "FaturaC"

Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto1))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven1)
Print File ARQIMP Spaces(09)+"Total.............."+Format("W12.2,EIC",TOT)+Spaces(02)
Print File ARQIMP Spaces(04)+Format("W10,AL",Format("D13",dtvencto1))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven1)
Print File ARQIMP Spaces(09)+"Total.............."+Format("W12.2,EIC",TOT)+"\n"

Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto2))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven2)
Print File ARQIMP Spaces(09)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+Spaces(02)
Print File ARQIMP Spaces(04)+Format("W10,AL",Format("D13",dtvencto2))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven2)
Print File ARQIMP Spaces(09)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP Spaces(03)+Format("W10,AL",Format("D13",dtvencto3))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven3)
Print File ARQIMP Spaces(09)+"Total Liquido......"+Format("W12.2,EIC",[Valor Mercadoria Liquido])+Spaces(02)
Print File ARQIMP Spaces(04)+Format("W10,AL",Format("D13",dtvencto3))
Print File ARQIMP Spaces(03)+Format("W10.2,EIC,AR",valorven3)
Print File ARQIMP Spaces(09)+"Total Liquido......"+Format("W12.2,EIC",[Valor Mercadoria Liquido])+"\n"
Print File ARQIMP Spaces(04)+"Condicao de Pagamento: "+Format("W03",[Condicao de Pagamento])+" - "+Format("W35,AL",[Descricao CondPagto])+Spaces(04)
Print File ARQIMP "Condicao de Pagamento: "+Format("W03",[Condicao de Pagamento])+" - "+Format("W35,AL",[Descricao CondPagto])+"\n\n"

Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+Spaces(05)
Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+"\n"

Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"


;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"
;Print File ARQIMP chr(27)+chr(67)+chr(66) ;Imprime 66 Linhas por pagina
EndProc
;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0164.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPFAT()
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

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

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


