;** RO_0053 *******************************************************************
;** Imprime a Digitacao do Romaneio       ** Curtume Sao Sebastiao **
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 20/08/98
;Alterado em     : 05/02/2004 por Karen Lauar Nery
;Motivo Alteracao: Ajustes
;Alterado em     : 16/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: 15/06/2016 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Pega_Endereco_Fatura() e ajustado dados do endere‡o
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP CI_12CPP

Moveto "FaturaC"
Pega_Endereco_Fatura([Numero da OF])

Print File ARQIMP "\n"
Print File ARQIMP  "  ---------------------------------------------------------------------------------------------" + "\n"
Print File ARQIMP Spaces(28)+"Emissao: "+Format("D13",Today())+"-"+Time()+ "\n"
Print File ARQIMP  "  ---------------------------------------------------------------------------------------------" + "\n\n"

Print File ARQIMP Spaces(02)+"Operacao: "+Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP Spaces(40)+"Romaneio No "+Format("W06.3,AL",NOTAFISC)+"\n\n"

Print File ARQIMP Spaces(02)+"Cliente.......: "
Print File ARQIMP Format("W50,AL",[Razao Social])+"\n"

Print File ARQIMP Spaces(02)+"Local Fatura..: "
Print File ARQIMP Format("W33,AL",[Endereco])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Bairro])+"\n"
Print File ARQIMP Spaces(18)+Format("W10,AL",[CEP])
Print File ARQIMP Spaces(02)+Format("W20,AL",[Cidade])+"\n"
Print File ARQIMP Spaces(18)+Format("W18,AL",[CGC])
Print File ARQIMP Spaces(02)+Format("W25,AL",[IE])+"\n\n"

Print File ARQIMP Spaces(02)+"Local Entrega.:"+Format("W25,AL",VSD_E_Endereco)
Print File ARQIMP Spaces(10)+Format("W20,AL",VSD_E_Bairro)+"\n"
Print File ARQIMP Spaces(18)+Format("W10,AL",VSD_E_CEP)
Print File ARQIMP Spaces(02)+Format("W20,AL",VSD_E_Cidade)+Spaces(02)+Format("W03,AL",VSD_E_UF)+"\n\n\n"

Print File ARQIMP Spaces(02)+"Dt Emissao Dt Saida Volumes Representante "+ "\n"
Print File ARQIMP Spaces(02)+"---------- -------- ------- ------------------------"+"\n"

Print File ARQIMP Spaces(02)+Format("D13",[Data de Emissao])
Print File ARQIMP Spaces(03)+Format("D13",[Data de Saida])
Print File ARQIMP Spaces(01)+Format("W07",[Numero de Volumes])
Print File ARQIMP Spaces(01)+Format("W25,AL",[Nome Fantasia Represent])+"\n\n\n"

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP Spaces(02)+"Item                                                 Un Quantidade Unitario             Total"+"\n"
Print File ARQIMP Spaces(02)+"---------------------------------------------------- -- ---------- -------- -----------------"+"\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("W02,AL",[Item da OF])
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Spaces(01)+Format("W20,AL",[Descricao do Item])
   Print File ARQIMP Spaces(01)+Format("W15,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Spaces(01)+Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
   Print File ARQIMP Spaces(07)+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(61)+"-------              -------------"+"\n"
Print File ARQIMP Spaces(56)+Format("W012.3,EIC",QUANT)
Print File ARQIMP Spaces(15)+Format("W012.2,EIC",TOT)+"\n"

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

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

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP Spaces(02)+"Condicao de Pagamento: "+[Descricao CondPagto]+"\n"

Print File ARQIMP Spaces(12)+"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("W11.2,AL,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 "\n\n"

Moveto"Faturac"
Print File ARQIMP Spaces(02)+"Transportador: "+Format("W28,AL",[Nome Fantasia Transport])+"\n"
Print File ARQIMP Spaces(02)+"Observacao: "+Format("W090,AL",[FaturaC->Observacao na Nota Fiscal])+"\n"
Print File ARQIMP Spaces(02)+Format("W112,AL",[FaturaC->Observacao na Nota Fiscal])+"\n\n"


;************************* IMPRESSAO DO RODAPE ********************************

Print File ARQIMP Spaces(02)+"            VENDA                                          E N T R E G A"+"\n"
Print File ARQIMP Spaces(02)+"   /   /   -                                    /   /   -"+"\n"
Print File ARQIMP Spaces(02)+"-----------------------------------          ----------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"   Data e Assinatura do Emitente                Data e Assinatura do Destinatario"
Print File ARQIMP "\f"


EndProc

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If KV>0
   Then Print File ARQIMP Spaces(20)
EndIf
For I From 1 to K
  Print File ARQIMP Spaces(03)+DATA[I]+Spaces(02)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(30)
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_0053.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()


