;** RO_0280 ********************************************************************
;** Imprime a Digitacao do Romaneio                                 ** UCATEC **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 27/10/2010 por Bruno Carvalho
;Ultima Alteracao: 06/01/2011 por Bruno Carvalho 
;Motivo Alteracao: Adicionado SERIEFISC
;Ultima Alteracao: 15/02/2011 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Nome da Empresa
;Ultima Alteracao: 07/11/2013 por Kamila Gomes
;Motivo Alteracao: Adicionado Valor da Entrega
;Ultima Alteracao: 15/06/2016 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Pega_Endereco_Fatura() e ajustado dados do endere‡o

;*******************************************************************************
;* 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(56)+"** Continua =>"+"\n"
Print File ARQIMP "------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "-----------------------------------------------------------------"+"\n"


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

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

Print File ARQIMP Spaces(35)+"Total Liquido......  ********  "+Spaces(02)
Print File ARQIMP Spaces(35)+"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()

;* Nao eh necessario mudar as configura‡”es para impressao de duas vias

Moveto "FaturaC"
Pega_Endereco_Fatura([Numero da OF])
                                
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 "UCATEC"+Spaces(29)+"Data: "+Format("D10",Today())+" - Hora: "+Time()+Spaces(3)
Print File ARQIMP "UCATEC"+Spaces(29)+"Data: "+Format("D10",Today())+" - Hora: "+Time()+"\n"
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+"/"+Format("W04,AL",SERIEFISC)+Spaces(47)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+"/"+Format("W04,AL",SERIEFISC)+"\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 VSD_E_Endereco = "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",VSD_E_Endereco)+Spaces(02) 
         Print File ARQIMP Format("W15,AL",VSD_E_Bairro)+Spaces(02)
         Print File ARQIMP "Entrega  : "
         Print File ARQIMP Format("W39,AL",VSD_E_Endereco)+Spaces(02) 
         Print File ARQIMP Format("W15,AL",VSD_E_Bairro)+"\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=11

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 09
    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 Produtos....."+Format("W12.2,EIC",TOT)+Spaces(02)
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 Produtos....."+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(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])+"\n"

Print File ARQIMP Spaces(35)+"Valor Entrega......"+Format("W12.2,EIC",[Valor do Frete])+Spaces(02)
Print File ARQIMP Spaces(35)+"Valor Entrega......"+Format("W12.2,EIC",[Valor do Frete])+Spaces(02)+"\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 Nota........."+Format("W12.2,EIC",[Valor Nota Fiscal])+Spaces(02)
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 Nota........."+Format("W12.2,EIC",[Valor Nota Fiscal])+"\n"
Print File ARQIMP Spaces(03)+"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_0280.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()
