;** RO_0311 ********************************************************************
;** Imprime a Digitacao do Romaneio                        ** TORRA TUDO **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 26/04/2012 por Karina Andrade
;Motivo Alteracao: Copia RO_0022 
;Alterado      em:  /  /     por 
;Motivo Alteracao:

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
PARAM_NITENS=18

Proc Cabecalho()

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

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(20)+"Orcamento N§ "+Format("W06.3,AL",NOTAFISC)+"\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 "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(02)+"Item                                                                                           Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "---------------------------------------------------------------------------------------------------------------------------------------"+"\n"

EndProc ;(Cabecalho)

;********************* IMPRESSAO DOS ITENS ********************************
Proc Itens()

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]

TOT                 = 0
CONTADOR            = 0

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

  Checa_Linha(1)                

  Print File ARQIMP Spaces(02)+Format("W04,AL",[Item da OF])
  Print File ARQIMP Spaces(01)+Format("W12,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W62,AL",[Descricao do Item])
  Print File ARQIMP Spaces(15)+Format("W03,Al",[Unidade Fiscal])

  If [Quantidade]-Int([Quantidade])>0
     Then Print File ARQIMP Format("W011.3,EIC",[Quantidade])
     Else Print File ARQIMP Format("W011,EIC",[Quantidade])
  EndIf

  Print File ARQIMP Format("W10.2,EIC",[Preco Unitario])
  Print File ARQIMP Format("W13.2,EIC",[Preco Total])

  TOT   = TOT + [Preco Total]
  Skip
  
  If [Numero da OF]=[FaturaC->Numero da OF]
    Then Print File ARQIMP "\n"
  EndIf
    
  If EOT() Then QuitLoop EndIf
EndWhile

For ITEM From CONTADOR To PARAM_NITENS
    Print File ARQIMP "\n"
    QUEBRA_FOLHA = QUEBRA_FOLHA+1
EndFor

EndProc ;(Itens)

;********************* IMPRESSAO DOS TOTAIS **************************

Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

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

Moveto "FaturaC"

If QUEBRAFORM
   Then Print File ARQIMP Spaces(103)+"Total................ ********* "+"\n"
        Print File ARQIMP Spaces(103)+"Desconto   ***   %... ********* "+"\n"
        Print File ARQIMP Spaces(103)+"Total Liquido........ ********* "+"\n"
   Else Print File ARQIMP Spaces(102)+"Total................"+Format("W11.2,EIC",TOT)+"\n"        
        Print File ARQIMP "          *** FAVOR MANTER O ENDERECO E O TELEFONE ATUALIZADOS ***" 
        Print File ARQIMP Spaces(36)+"Desconto "+Format("W06.2,EIC",[Taxa de Desconto]) + "  %..."
        Print File ARQIMP Format("W11.2,EIC",[Valor Desconto])+"\n"
        Print File ARQIMP Spaces(102)+"Total Liquido........"+Format("W11.2,EIC",[Valor Mercadoria Liquido])+"\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"
Print File ARQIMP "OBS.: "
Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,73))+"\n\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

Print File ARQIMP "\027F"

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

If QUEBRAFORM
   Then Print File ARQIMP "\n\n\n" 
   Else Print File ARQIMP Spaces(38)+"   /   /     -                                   " + "\n"
        Print File ARQIMP Spaces(38)+"-------------------------------------------------" + "\n"
        Print File ARQIMP Spaces(38)+"              Data e Assinatura"+"\n"
EndIf        
Print File ARQIMP CI_6LPP
Print File ARQIMP CI_10CPP

If QUEBRA_FOLHA = (PARAM_NITENS*2)+1
   Then QUEBRA       = True
        QUEBRA_FOLHA = 1
EndIf                             
If QUEBRA
   Then QUEBRA = False
        Print File ARQIMP "\f"
   Else Print File ARQIMP "\n\n" 
EndIf

EndProc ;(Rodape)

;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(Nl)
private nl
QUEBRA = False

If QUEBRA_FOLHA <= (PARAM_NITENS*2)
   Then QUEBRA_FOLHA = QUEBRA_FOLHA+nl
EndIf

If (CONTADOR+nl)>(PARAM_NITENS)
   Then RodaPe(True)
        Cabecalho()
        CONTADOR=nl
        Moveto "FaturaI"
   Else CONTADOR=CONTADOR+nl
EndIf
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_0311.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

QUEBRA_FOLHA = 0

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)
;For Copias From 1 to 2
    Cabecalho()
    Itens()
    Rodape(False) 
;EndFor

;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

Release Vars   VALOR,DATA
Release Procs  IMPFAT,VENC
LIMPAGUARDE()


