;** RO_0224t********************************************************************
;** Imprime a Digitacao do Romaneio                        ** SEN NOCAO  ** *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 23/04/2009 por HUMBERTO FELIPE SANTOS.
;Ultima Alteracao: 05/08/2017 por Bruno Carvalho
;Motivo Alteracao: Substituido [Valor IR] -> [Valor DebitoCredito]

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

;************************** 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

Moveto "FaturaC"
Print File ARQIMP "\n"
Print File ARQIMP Format("W50,AL","CONTROLE INTERNO")+"Impressao: "+Format("D10",Today())+"-"+Time()+ "\n\n"

Print File ARQIMP "\020"
Print File ARQIMP Format("W59,AL","SEN NOCAO - 37-3214-4965")+"ORCAMENTO N§ "+Format("W06.3,AL",NOTAFISC)+"\n\n"

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

Print File ARQIMP CI_10CPP
Print File ARQIMP CI_8LPP

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]
;;; Print File ARQIMP Chr(27)+Chr(72)

Print File ARQIMP Spaces(04)+"Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP CI_15CPP

;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"Item                                                                           Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------"+"\n"
CONTADOR = 0
If IsAssigned(FATURA_TROCA)
   Then Moveto "FaturaId"
        Moveto [Numero da OF]
        Locate [FaturaC->Numero da OF]
        TOTDEV     = 0
        Print File ARQIMP "* Entradas\n"
        CONTADOR = CONTADOR + 1

        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("W62,AL",[Descricao do Item])
          Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])
          Print File ARQIMP Format("W11.2,EIC",[Quantidade])
          Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
          Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"
          TOTDEV= TOTDEV + [Preco Total]
          Skip
          If EOT() Then QuitLoop EndIf
          CONTADOR = CONTADOR + 1
        EndWhile
        Print File ARQIMP Spaces(88)+"Total Devolucoes..."+Format("W11.2,EIC",TOTDEV)+"\n\n"
        CONTADOR = CONTADOR + 2
EndIf

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

Print File ARQIMP "* Saidas\n"
CONTADOR = CONTADOR + 1
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("W62,AL",[Descricao do Item])
  Print File ARQIMP Spaces(01)+Format("W03,Al",[Unidade Fiscal])
  Print File ARQIMP Format("W11.2,EIC",[Quantidade])
  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])+"\n"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile
Print File ARQIMP Spaces(87)+"Total Vendas......."+Format("W11.2,EIC",TOT)+"\n"
CONTADOR = CONTADOR + 1

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

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

Print File ARQIMP "Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%"
Print File ARQIMP Format("W7.2,EIC",[Valor Desconto])

If [Frete Incluso na Nota]="+"
   Then Print File ARQIMP Spaces(02)+"Total do Frete.."+Format("W7.2,EIC",[Valor do Frete])
   Else Print File ARQIMP Spaces(02)+"Total do Frete.."+Format("W7.2,EIC",0)
EndIf

;Print File ARQIMP Spaces(05)+"Total Liquido.."+Format("W11.2,EIC",[Valor Nota Fiscal])

If [Valor DebitoCredito]>0
   Then DIF="Credito"
   Else If [Valor DebitoCredito]<0
           Then DIF="Debito"
           Else DIF="Zero"
        EndIf
EndIf
If IsAssigned(FATURA_TROCA)
   Then
       Print File ARQIMP Spaces(05)+"Diferenca.."+Format("W11.2,EIC",[Valor DebitoCredito])+"\n"
       Print File ARQIMP Spaces(95) + "(" + DIF + ")"+"\n"
EndIf

Print File ARQIMP "   Cond. Pagto: "+[Descricao CondPagto]
Print File ARQIMP "   NP: "+StrVal([Numero de Parcelas])
Print File ARQIMP "   CD: "+[Composicao de Dias]
Print File ARQIMP " "+"Total Liquido.."+Format("W11.2,EIC",[Valor Nota Fiscal])+"\n"

;********************* IMPRESSAO DOS VENCIMENTOS **************************

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
Moveto "FaturaC"
Print File ARQIMP "Observacoes: "
Print File ARQIMP Format("W067,AL",SubStr([Observacao na Nota Fiscal],001,067))+"\n\n"
Print File ARQIMP "\027F"

Moveto "Numeronf"
 Locate [FaturaC->Codigo da Empresa],"ROM"
   If Retval
      Then Moveto [Mensagem]
           MENS=[]
      Else MENS=""
   EndIf
;************************* IMPRESSAO DO RODAPE *********************************
Print File ARQIMP "* "+Format("W58,AL",SubStr(MENS,1,58))+"   "+"   /   /     -                                   " +"\n"
Print File ARQIMP "* "+Format("W58,AL",SubStr(MENS,59,58))+"   "+"---------------------------------------------------------------------" +"\n"
Print File ARQIMP "* "+Format("W58,AL",SubStr(MENS,117,58))+"   "+"                          Data e Assinatura"+"\n"
Print File ARQIMP "\f"
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\n"

KV=KV+1
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0109.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()


