;** RO_0107 ********************************************************************
;** Imprime a Digitacao do Romaneio                        ** ATTUAL     **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 23/03/1999 por Anivel Augusto Rodrigues
;Alterado em     : 24/12/2003 por Karen Lauar Nery
;Motivo Alteracao: ITEM DA OF
;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

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

Proc IMPFAT()

;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

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

Moveto "FaturaC"
Print File ARQIMP "\n"
Print File ARQIMP Format("W40,AL",NOMEMPRESA)+Spaces(10)+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n\n"

;;Print File ARQIMP "\014"
Print File ARQIMP Spaces(21)+"Romaneio 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 CI_10CPP
Print File ARQIMP CI_8LPP

Print File ARQIMP Spaces(08)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+"\n"

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

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

Print File ARQIMP "Operacao: "
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP Format("W02,AL",[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])+"\n\n"
Print File ARQIMP CI_15CPP
;********************* IMPRESSAO DOS ITENS ********************************

Print File ARQIMP Spaces(02)+" Item                                              Modelo Cor                   Un  Quantidade  Unitario        Total "+"\n"
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT=0
TOT=0
While [Numero da OF]=[FaturaC->Numero da OF]
   Print File ARQIMP Spaces(02)+" "+Format("W03,AR",StrVal([Item da OF]))
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Spaces(01)+Format("W30,AL",[Descricao do Item])
   Print File ARQIMP Spaces(03)+" "+Format("W04,AR",Substr([Descricao do Item],31,3))
   Print File ARQIMP Spaces(01)+" "+Format("W20,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Spaces(01)+" "+Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP " "+Format("W11,EIC",[Quantidade])
   Print File ARQIMP " "+Format("W09.2,EIC",[Preco Unitario])
   Print File ARQIMP "  "+Format("W11.2,EIC",[Preco Total])+" "+"\n"
   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

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

Print File ARQIMP Spaces(02)+"                                                               Total Mercadorias:"
Print File ARQIMP Format("W012,EIC",QUANT)+Spaces(11)+Format("W012.2,EIC",TOT)+" "+"\n"
Print File ARQIMP "\n"

Print File ARQIMP Spaces(87)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto])+"%..."
Print File ARQIMP Format("W13.2,EIC",[Valor Desconto])+"\n"

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

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

Print File ARQIMP CI_10CPP
Print File ARQIMP "Vencimentos: "

Array DATA[9]
Array VALOR[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])
  If K=9
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()
EndIf

Print File ARQIMP CI_15CPP
Print File ARQIMP "\n"
Moveto"Faturac"
Print File ARQIMP "Observacoes: "
Print File ARQIMP Format("W60,AL",SubStr([Observacao na Nota Fiscal],001,60))+"\n"
If Substr([Observacao na Nota Fiscal],61,120)<>""
   Then Print File ARQIMP Spaces(13)+Format("W60,AL",SubStr([Observacao na Nota Fiscal],61,120))+"\n"
EndIf
;Print File ARQIMP "\n"

;************************* IMPRESSAO DO RODAPE *******************************************
Print File ARQIMP Spaces(12)+"                              /   /   -"+"\n"
Print File ARQIMP Spaces(12)+"                          ------------------------------------------"+"\n"
Print File ARQIMP Spaces(12)+"                              Data e Assinatura do Cliente "+"\n"
Print File ARQIMP CI_6LPP
If VIA<2
 Then Print File ARQIMP "\n\n"
 Else Print File ARQIMP "\f"
      VIA=0
EndIf
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
EndProc

;*******************************************************************************
;* 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(02)
EndFor
Print File ARQIMP "\n"

KV=KV+1
EndProc

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

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

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

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


