;** RO_0197B********************************************************************
;** Imprime a Digitacao do Romaneio                         ** COLLORTEX **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em:
;Alterado      em:
;Motivo Alteracao: Ajustes

;*******************************************************************************
;* 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\n"
Print File ARQIMP Spaces(62)+Format("W12,AL",[Numero Nota Gerada])
Print File ARQIMP "\n\n\n"

Print File ARQIMP Spaces(53)+Format("W12,AL",[Nome Fantasia Represent])+Spaces(02)+Format("D13",[Data de Emissao])+"\n\n"
Print File ARQIMP CI_8LPP
Print File ARQIMP "\027P"         ;Imprime 10 Caracteres por polegada
Print File ARQIMP "\015"
Print File ARQIMP Spaces(24)+Format("W38,AL",[Razao Social])+Spaces(24)+Format("W04,AL",[Codigo])+Spaces(17)+Format("W18,AL",[CGC])+"\n"
Print File ARQIMP Spaces(26)+Format("W36,AL",[Endereco])+Spaces(18)+Format("W20,AL",[Bairro])+Spaces(22)+Format("W10,AL",[CEP])+"\n"
Print File ARQIMP Spaces(24)+Format("W17,AL",[Cidade])+Spaces(20)+Format("W10,AL",[UF])+Spaces(16)+Format("W15,AL",[Telefone])+"\n\n\n\n"






;********************* IMPRESSAO DOS ITENS ********************************
;Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"
;Print File ARQIMP Spaces(02)+"Item                                                                          Un  Quantidade  Unitario        Total"+"\n"
;Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"
Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
QUANT    = 0
TOT      = 0
CONTADOR = 0

While [Numero da OF]=[FaturaC->Numero da OF]
 For CON From 1 to 3
     If CON=3
        Then Print File ARQIMP Spaces(00)
     EndIf

     COD_FOR=""
     Moveto [Codigo do Item]
     KeyPress "F1"
     Moveto [Codigo do Item]
     Locate [FaturaI->Codigo do Item]
     If RetVal
        Then COD_FOR=[Codigo Fornecedor]
     EndIf
     KeyPress "Esc"
     CON=CON+1
  EndFor

 ;Print File ARQIMP Format("W13,AL",COD_FOR)
 ;Print File ARQIMP Spaces(8)+Format("W02,AL",[Item da OF])
  Print File ARQIMP Spaces(11)+Format("W11,AL",COD_FOR)
  Print File ARQIMP Spaces(01)+Format("W58,AL",[Descricao do Item])
  Print File ARQIMP Spaces(01)+Format("W04,Al",[Unidade Fiscal])
  Print File ARQIMP Format("W16,EIC",[Quantidade])
  Print File ARQIMP Spaces(04)+Format("W14.2,EIC",[Preco Unitario])
  Print File ARQIMP Spaces(02)+Format("W13.2,EIC",[Preco Total])+"\n"
   
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 17
    Print File ARQIMP "\n"
EndFor
;Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------"+"\n"

;********************* IMPRESSAO DOS TOTAIS **************************
Moveto "FaturaC"
Print File ARQIMP "             *** FAVOR MANTER OS DADOS ATUALIZADOS ***"
Print File ARQIMP Spaces(4)+Format("W11.2,EIC",TOT)
Print File ARQIMP Spaces(3)+Format("W12.2,EIC",[Valor Desconto])
Print File ARQIMP Spaces(2)+Format("W08.2,EIC",[Valor Despesas Acessorias])
Print File ARQIMP Spaces(3)+Format("W12.2,EIC",[Valor do Frete])
;Print File ARQIMP Spaces(2)+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
Print File ARQIMP Spaces(8)+Format("W11.2,EIC",[Valor Nota Fiscal])+"\n\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"

;********************* IMPRESSAO DOS VENCIMENTOS **************************
;Print File ARQIMP "\018"
;Print File ARQIMP "\027E"
;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 "\n"
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

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
cont = 0
;If KV>0
   Print File ARQIMP Spaces(18)
;EndIf
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(6)
  Print File ARQIMP DATA[I]+Spaces(9)
  cont = cont+1
  If cont = 2
     Then Print File ARQIMP "\n"
          Print File ARQIMP Spaces(18)
          cont = 0  
  EndIf
EndFor
;Print File ARQIMP "\n"
;Print File ARQIMP Spaces(13)
;For I From 1 to K
  ;Print File ARQIMP VALOR[I]+Spaces(02)
  ;Print File ARQIMP DATA[I]+Spaces(02)
;EndFor
;Print File ARQIMP "\n\n"

;KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

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


