;** RO_0236A *******************************************************************
;** Imprime a Digitacao do Romaneio                        ** SUPER MARTINS**  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 16/01/2013 por Bruno Carvalho
;Alteracao:    em: 31/05/2013 por Bruno Carvalho 
;Motivo Alteracao: Add Observacao dos Vencimentos em cada parcela 

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

;************************** 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 "\n"
Print File ARQIMP Format("W48,AL","CONTROLE INTERNO")+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(18)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+"\n\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])+"\n"
Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(01)+"Item       Composicao                Var. Artigo                                             Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"

Moveto "FaturaI"                                                            
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT=0
TOT  =0
PARAM_TAMANHO_DESCR=73

While [Numero da OF]=[FaturaC->Numero da OF]


  desc=[Descricao do Item]
 ; ref =""
  Moveto [Codigo do Item]
  If BUSCA_LOOKUP("Codigo do Item",[FaturaI->Codigo do Item],"SM")
     Then desc=desc+Spaces(1)+REG_BUSCA_LOOKUP["Descricao Complementar"]
          ;ref =REG_BUSCA_LOOKUP["Referencia"]
  EndIf

  Numero_de_Linhas=Int(Len(Desc)/PARAM_TAMANHO_DESCR)
	If (Len(Desc)/PARAM_TAMANHO_DESCR)>Numero_de_Linhas
     Then Numero_de_Linhas=Numero_de_Linhas+1
  EndIf

	LINHA_ITEM = Spaces(01)+Format("W05,AL",[Item da OF])+Spaces(01)+Format("W04,AL",SubStr([Codigo do Item],3,4))+Spaces(01)

  pos_inicial=1
  For nl From 1 To Numero_de_Linhas
     LINHA_ITEM = LINHA_ITEM + Format("W79,AL",SubStr(Desc,pos_inicial,PARAM_TAMANHO_DESCR))
     If nl<Numero_de_Linhas
        Then Print File ARQIMP LINHA_ITEM + "\n"
             LINHA_ITEM = Spaces(18)
             pos_inicial=pos_inicial+PARAM_TAMANHO_DESCR
     EndIf
  EndFor

  LINHA_ITEM=LINHA_ITEM+Spaces(03)+Format("W03,AL",[Unidade Fiscal])
  LINHA_ITEM=LINHA_ITEM+Format("W11.3,EIC",[Quantidade])
  LINHA_ITEM=LINHA_ITEM+Format("W10.2,EIC",[Preco Unitario])
  LINHA_ITEM=LINHA_ITEM+Format("W13.2,EIC",[Preco Total])

	Print File ARQIMP LINHA_ITEM+"\n"
 ; Print File ARQIMP Fill("-",54)+"\n"

	QUANT=QUANT+[Quantidade]
	TOT=TOT+[Preco Total]
	Skip
	If EOT() Then QuitLoop EndIf
EndWhile

Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------"+"\n"

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

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

Print File ARQIMP "    ***FAVOR REVISAR OS TECIDOS,NAO ACEITAMOS RECLAMACAO,NEM DEVOLUCAO APOS O CORTE DOS MESMOS***"
Print File ARQIMP Spaces(4)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
Print File ARQIMP Format("W11.2,EIC",[Valor Desconto])+"\n"
Print File ARQIMP Spaces(101)+"Frete.............." +Format("W11.2,EIC",[Valor do Frete])+"\n"
Print File ARQIMP Spaces(101)+"Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido]+[Valor do Frete])+"\n\n"

Print File ARQIMP "Obs....: "+Format("W110,AL",SubStr([Observacao na Nota Fiscal],001,110))+"\n"
If Substr([Observacao na Nota Fiscal],111,110)<>""
   Then Print File ARQIMP Spaces(20)+Format("W110,AL",SubStr([Observacao na Nota Fiscal],111,110))+"\n"
   Else Print File ARQIMP "\n"
EndIf

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

;********************* IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP "\020"
Print File ARQIMP "\027E"
Print File ARQIMP "Vencimentos: "

Array DATA[12]
Array VALOR[12]
Array OBS[12]
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])
  OBS[K]   = Format("W10,AR",[Observacao]) 
  If K=11
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then VENC()  
EndIf

Print File ARQIMP "\n"
Print File ARQIMP "\027F"

;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP Format("W133,AC","   /   /     -                                   ")+"\n"
Print File ARQIMP Format("W133,AC","-------------------------------------------------")+"\n"
Print File ARQIMP Format("W133,AC","Data e Assinatura")+"\n"

Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP
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(01)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(01)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(13)
For I From 1 to K
  Print File ARQIMP OBS[I]+Spaces(01)
EndFor
Print File ARQIMP "\n\n"

KV=KV+1
EndProc
;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

ArqImp=PrivDir()+"Ro_0233.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()


