;** RO_0373 ********************************************************************
;** Imprime a Digitacao do Romaneio                  ** FLORENCA TECIDOS **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 03/09/2015 por Nikolas
;Alterado      em: 10/09/2015 por Nikolas
;Motivo Alteracao: Ajustes
;Alterado      em: 23/09/2015 por Andrey Fillipe
;Motivo Alteracao: Ajustes colocado Descricao complementar no lugar da Descricao do Item
;                  Colocado a OBS em negrito
;                  Diminuido a fonte das parcelas e aumentado caracteres da sequencia do item
;Alterado      em: 16/10/2015 por Andrey Fillipe
;Motivo Alteracao: Ajustes colocado para imprimir 67 Itens em folha grande
;Alterado      em: 12/07/2016 por Bruno Carvalho
;Motivo Alteracao: Removido "Data e Assinatura" do Romaneio por solicita‡Æo do cliente => Maria Luiza
;Alterado      em: 03/02/2020 por Nikolas
;Motivo Alteracao: Inclusao do Peso e Numero de volumes

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

If (CONTADOR+nl)>79
   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()

;************************** IMPRESSAO DO 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_6LPP

Print File ARQIMP Format("W50,AL","SEM VALOR FISCAL           ")+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(20)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+"\n"
Print File ARQIMP "\020"

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

Print File ARQIMP CI_8LPP
Print File ARQIMP "\027P"         ;Imprime 10 Caracteres por polegada

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 "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP ""+[Codigo da Destinacao]+" "+[Descricao da Destinacao]+"\n"
Print File ARQIMP Chr(27)+Chr(72)

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "  Volumes:"+Format("W3,AL",[Numero de Volumes])
Print File ARQIMP "  Peso:"+Format("W09.3,EIC,AL",[Peso Bruto])+"\n"
Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada

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

CONTADOR=12

EndProc ;(Cabecalho)

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

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]

TOT      = 0

While [Numero da OF]=[FaturaC->Numero da OF]
  Checa_Linha(1)
  
  Print File ARQIMP Spaces(01)+Format("W03,AL",[Item da OF])
  Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
  GetRecord"\\Sistemas\\Estoque\\Itens" [Codigo do Item] To DESCOMP
  If RetVal
     Then Print File ARQIMP Spaces(01)+Format("W62,AL",DESCOMP["Descricao Complementar"])
     Else Print File ARQIMP Spaces(01)+Format("W62,AL",[Descricao do Item])
  EndIf   
  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"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

While CONTADOR < 25   
  Checa_Linha(1)
  Print File ARQIMP "\n"
EndWhile
Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"

EndProc ;(Itens)

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

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

Print File ARQIMP Spaces(87)+"Total.............."+Format("W11.2,EIC",TOT)+"\n"

Print File ARQIMP " **FAVOR CONFERIR A MERCADORIA E OS VENCIMENTOS EM ATE 72 HORAS** "
Print File ARQIMP Spaces(21)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"

Print File ARQIMP Spaces(87)+"DespAces..........."+Format("W11.2,EIC",[Valor Despesas Acessorias])+"\n"
Print File ARQIMP Spaces(87)+"Total Liquido......"+Format("W11.2,EIC",([Valor Mercadoria Liquido]+[Valor Despesas Acessorias]))+"\n\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"\n"

Print File ARQIMP "\027E"                             
Print File ARQIMP "OBS.: "
Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,73))+"\n"
Print File ARQIMP "\027F"
        
;********************* IMPRESSAO DOS VENCIMENTOS **************************
Checa_Linha(7)
;Print File ARQIMP "\018"
Print File ARQIMP "\027E"
Print File ARQIMP "Vencimentos: "

Array DATA [9]
Array VALOR[9]
Array FPGT [9]
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
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W10.2,AR,EIC",[Valor])
  FPGT[K]  = Format("W10","FP: "+[Forma de Pagamento])
  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 "\027F"

;************************* IMPRESSAO DO RODAPE *********************************
;Print File ARQIMP Spaces(12)+"   /   /     -                                   " + "\n"
;Print File ARQIMP Spaces(12)+"-------------------------------------------------" + "\n"
;Print File ARQIMP Spaces(12)+"              Data e Assinatura"+"\n"
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 FPGT[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
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_0373.Txt"

If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf
      
AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
For wi From 1 to NumVal(N_COPIAS)
    Cabecalho()
    Itens()
    Rodape()
    
    NUMCOPIA=1 
    ImpriArq(ARQIMP)
EndFor

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

LIMPAGUARDE()
