;** RO_0059B *******************************************************************
;** Imprime a Digitacao do Romaneio                        ** VOLKS BENS       *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 29/12/2003 por Karen Lauar Nery
;Alterado em     : 13/04/2005 por Davi Pereira Carrano
;Motivo Alteracao: Retirando Atendente
;Alterado em     : 19/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 21/09/2007 por Humberto F.Santos.
;Motivo Alteracao: Retirado o Usuario e ajustes.
;Ultima Alteracao: 21/10/2008 por Humberto F.Santos.
;Motivo Alteracao: Retirado Descricao da Destinacao.
;Ultima Alteracao: 31/08/2016 por Humberto F.Santos.
;Motivo Alteracao: Acrescentado o campo NUmero da OF.
;Ultima Alteracao: 21/05/2020 por Bruno Carvalho
;Motivo Alteracao: Ajustes na quebra de linha, contagem de itens que antecede este ajuste estava errada, onde era impresso apenas 12 itens 

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

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

;************************** IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="" EndIf
Moveto "Faturac"
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_15CPP
;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 "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time()+Spaces(02) +"- OF: "+Format("W06,AL",[Numero da OF])+Spaces(03)
Print File ARQIMP "Orcamento: "+Format("W06.3,AL",NOTAFISC)+" - Data: "+Format("D10",Today())+" - Hora: "+Time() +" - OF: "+Format("W06,AL",[Numero da OF])+"\n"

Print File ARQIMP "Cliente  : "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+Spaces(24)
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP "Cliente  : "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP Format("W05,AL",[Codigo])+Format("W29,AL",[Razao Social])+"\n"
Print File ARQIMP Chr(27)+Chr(72)

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

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

Print File ARQIMP Spaces(09)+Format("W19,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W17,AL",[Telefone])+Spaces(04)
Print File ARQIMP Spaces(09)+Format("W19,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W17,AL",[Telefone])+"\n"

Print File ARQIMP "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP ""+[Codigo da Destinacao]+Spaces(57)
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP ""+[Codigo da Destinacao]+Spaces(31)+"\n"
Print File ARQIMP Chr(27)+Chr(72)

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

NOME_USUARIO=""
Moveto [Codigo_Usuario]
Ativa_Lookup()
Moveto [Chapa]
Locate [FaturaC->Codigo_Usuario]
If RetVal
   Then NOME_USUARIO=[Nome]
EndIf
KeyPress "Esc"

;Print File ARQIMP "Cortador: "+Format("W05,AL",[Codigo_Usuario])
;Print File ARQIMP Format("W14,AL",NOME_USUARIO)+Spaces(03)
Print File ARQIMP Spaces(33)+ "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W18,AL",[Nome Fantasia Represent])+Spaces(04)+"\n"
;Print File ARQIMP "Cortador: "+Format("W05,AL",[Codigo_Usuario])
;Print File ARQIMP Format("W14,AL",NOME_USUARIO)+"\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"

Moveto "FaturaI"

EndProc ;Cabecalho()

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

Cabecalho()

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT    = 0
TOT      = 0
CONTADOR = 0
While ([Numero da OF]=[FaturaC->Numero da OF])
  If CONTADOR>50
      Then CONTADOR=0
           Rodapte("") 
           Cabecalho()
  EndIf
  CONTADOR = CONTADOR + 1
          
  For CON From 1 to 2
    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])    
    Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
    Print File ARQIMP Format("W12.2,EIC",[Preco Total])+Spaces(03)
  EndFor
  Print File ARQIMP "\n"
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

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

Rodapte("Fim")

EndProc

;*******************************************************************************
;* Rotina para Impressao do Relatorio: Rodap‚                                  *
;*******************************************************************************
Proc Rodapte(PARAM)

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

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

If PARAM=""
   Then TOT = "   ******   "
        MSG = Format("W35,AC","** CONTINUA NA PROXIMA FOLHA **") 
   Else TOT = Format("W12.2,EIC",[Valor Mercadoria])
        MSG=Spaces(35)  
EndIf
Print File ARQIMP MSG+"Total.............."+TOT+Spaces(02)
Print File ARQIMP MSG+"Total.............."+TOT+"\n"

If PARAM=""
   Then TX_DESCTO = " **** " 
        VR_DESCTO = "   ******   "
   Else TX_DESCTO = Format("W06.2,EIC",[Taxa de Desconto]) 
        VR_DESCTO = Format("W12.2,EIC",[Valor Desconto])   
EndIf   
Print File ARQIMP Spaces(35)+"Desconto"+TX_DESCTO+ "%...."+VR_DESCTO+Spaces(02)
Print File ARQIMP Spaces(35)+"Desconto"+TX_DESCTO+ "%...."+VR_DESCTO+"\n"

If PARAM=""
   Then TOT_LIQ = "   ******   "
   Else TOT_LIQ = Format("W12.2,EIC",[Valor Mercadoria Liquido])
EndIf   
Print File ARQIMP Spaces(35)+"Total Liquido......"+TOT_LIQ+Spaces(02)
Print File ARQIMP Spaces(35)+"Total Liquido......"+TOT_LIQ+"\n\n"

If PARAM<>""
   Then Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+Spaces(05)
        Print File ARQIMP Spaces(15)+"Ass: --------------------------------------------"+"\n"
EnDIf
Print File ARQIMP "-------------------------------------------------------------------"+Spaces(03)
Print File ARQIMP "------------------------------------------------------------------"+"\n"

Print File ARQIMP "\f"

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

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
IMPFAT()
ImpriArq(ARQIMP)

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