;** RO_0013   *******************************************************************
;** Imprime a Digitacao do Romaneio                        ** Divilack **      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 23/03/1999 por Anivel Augusto Rodrigues
;Alterado em     : 13/04/2005 por Davi Pereira Carrano
;Motivo Alteracao: Retirando Atendente
;Alterado em     : 16/06/2006 por Antonio Marcelo Alves
;Alterado em     : 16/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Alterado em     : 18/12/2006 por Humberto F.Santos
;Motivo Alteracao: Aumento das casas do campo Codigo do Usuario
;Ultima Alteracao: 14/08/2007 por Antonio Marcelo Alves
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 20/10/2017 por Bruno Carvalho
;Motivo Alteracao: Removido [Composicao de Dias]
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico
;Ultima Alteracao: 07/11/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes formata‡Æo peso EIC com 3 casas decimais

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

Moveto "FaturaC"
;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

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

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

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

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

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

Print File ARQIMP Spaces(09)+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]
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP Spaces(08)+"Data de Emiss„o: "+Format("D13",[Data de Emissao])+"\n"

Print File ARQIMP "Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
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 "Usuario: "+Format("W05,AL",[Codigo_Usuario])
Print File ARQIMP Format("W13,AL",NOME_USUARIO)
Print File ARQIMP " OP: "+[Origem do Pedido]+"\n\n"

Print File ARQIMP CI_15CPP

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "Pedido  Sq Item                                        Qtde Un   PrUni   PrTab  %Des   C%   PrTotal Tb.Pr CP "+"\n"
Print File ARQIMP "------ --- ------------------------------------- ---------- -- ------- ------- ----- ---- --------- ----- ---"+"\n"
;;999999 12345678901234567890123456789099.999,999 XX 99.999,99 999.999,99 99/99/99
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
While [Numero da OF]=[FaturaC->Numero da OF]

   Print File ARQIMP Format("W07,AL",[Numero Pedido_Orcamento])
   Print File ARQIMP Format("W03,AR",StrVal([Item da OF]))+" "
   Print File ARQIMP Format("W05,AR",NumVal([Codigo do Item]))+" "
   Print File ARQIMP Format("W32,AL",[Descricao do Item])
   Print File ARQIMP Format("W10.2,EIC",[Quantidade])
   Print File ARQIMP Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W8.2,EIC",[Preco Unitario])
   Print File ARQIMP Format("W8.2,EIC",[Preco Unitario Tabela])
   Print File ARQIMP Format("W6.2,EIC",[Taxa Desconto Unitario])
   Print File ARQIMP Format("W5.2,EIC",[Comissao do Item])
   Print File ARQIMP Format("W10.2,EIC",[Preco Total])+" "
   Print File ARQIMP Format("W06",[Codigo da Tabela])
   Print File ARQIMP Format("W03",[Condicao de Pagamento])+"\n"
   Skip
   If EOT() Then QuitLoop EndIf

EndWhile
Print File ARQIMP CI_10CPP

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "FaturaC"
Print File ARQIMP "\n"
Print File ARQIMP Spaces(27)+"  Mecadorias         Desconto     Liquido       Total"+"\n"
                ;;9.999.999,99888.88%777.777,776.666.666,665.555.555,55

Print File ARQIMP Spaces(27)+Format("W12.2,EIC",[Valor Mercadoria])
Print File ARQIMP Format("W06.2,EIC",[Taxa de Desconto])+"%"
Print File ARQIMP Format("W10.2,EIC",[Valor Desconto])
Print File ARQIMP Format("W12.2,EIC",[Valor Mercadoria Liquido])
Print File ARQIMP Format("W12.2,EIC",[Valor Nota Fiscal])+"\n\n"

Print File ARQIMP "Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]+"   FP: "+[Forma de Pagamento]+"   FR:"+Format("W10.2,EIC",[Valor do Frete])+"\n"
;********************* IMPRESSAO DOS VENCIMENTOS **************************
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

Moveto"Faturac"
Print File ARQIMP "Transport..: "+Format("W41,AL",[Razao Social Transport])
Print File ARQIMP "Volumes:"+Format("W3,AL",[Numero de Volumes])
Print File ARQIMP "  Peso:"+Format("W09.3,EIC,AL",[Peso Liquido])+"\n"
Print File ARQIMP "Observacoes: "
Print File ARQIMP "\27E"
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
If Substr([Observacao na Nota Fiscal],121,180)<>""
   Then Print File ARQIMP Spaces(13)+Format("W60,AL",SubStr([Observacao na Nota Fiscal],121,180))+"\n"
EndIf
Print File ARQIMP "\27F"
Print File ARQIMP "\n"

;************************* IMPRESSAO DO RODAPE ********************************
Print File ARQIMP Spaces(12)+"            VENDA                                E N T R E G A"+"\n"
Print File ARQIMP Spaces(12)+"   /   /   -                          /   /   -"+"\n"
Print File ARQIMP Spaces(12)+"--------------------------------   --------------------------------"+"\n"
Print File ARQIMP Spaces(12)+"   Data e Assinatura do Emitente      Data e Assinatura do Cliente "+"\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
Print File ARQIMP "\f"
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_0013.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()


