;** RO_0314 ********************************************************************
;** Imprime a Digitacao do Romaneio                      ** JUNIOR PECAS **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 10/10/2012 por Kamila Gomes
;Ultima Altera‡Æo: 25/07/2013 por Bruno Carvalho   
;Motivo Altera‡Æo: Add rotina para quebrar linha e add numero de paginas
;Ultima Altera‡Æo: 01/08/2013 por Karina Andrade   
;Motivo Altera‡Æo: Ajuste impressÆo Vencimento
;Ultima Altera‡Æo: 12/11/2013 por Andrey Fillipe   
;Motivo Altera‡Æo: Ajuste impressÆo juros apos vencimento
;Ultima Altera‡Æo: 30/06/2014 por Kamila Gomes   
;Motivo Altera‡Æo: Ajuste impressÆo 17 itens por pagina

;*******************************************************************************
;* Rotina para informar o numero de linhas a ser impresso por romaneio         *
;*******************************************************************************
PARAM_NLINHA=31

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

If (NLINHA+nl) > PARAM_NLINHA
   Then RodaPe(True)
        CONTADOR = 0
        Cabecalho()
        Moveto "FaturaI"
EndIf
NLINHA=NLINHA+nl

EndProc ;Checa_Linha()

;*******************************************************************************
;* Rotina para Impressao do Relatorio - Cabe‡alho                              *
;*******************************************************************************
Proc Cabecalho()

Moveto "Faturac"
Print File ARQIMP chr(27)+chr(67)+chr(33)                                       ;Imprime 33 Linhas por P gina
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP

Print File ARQIMP Spaces(1)+Format("W50,AL","CONTROLE INTERNO - Balcao 3")+"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 Spaces(01)+"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(11)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+"\n"

Print File ARQIMP Spaces(11)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])+"\n"

Print File ARQIMP Spaces(11)+Format("W20,AL",[Cidade])
Print File ARQIMP Format("W20,AL",[UF])
Print File ARQIMP Format("W25,AL",[Telefone])+"\n"

Print File ARQIMP Spaces(01)+"Operacao: "
Print File ARQIMP Chr(27)+Chr(71)+[Codigo da Destinacao]+" "+[Descricao da Destinacao]+"\n"
Print File ARQIMP Chr(27)+Chr(72)

Print File ARQIMP Spaces(01)+"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

Print File ARQIMP "  ----------------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"Item                                                                                       Un  Quantidade  Unitario        Total"+"\n"
Print File ARQIMP "  ----------------------------------------------------------------------------------------------------------------------------------"+"\n"

NLINHA=12
If SubStr([Observacao na Nota Fiscal],001,126)<>"" Then NLINHA = NLINHA + 1 EndIf 
If SubStr([Observacao na Nota Fiscal],127,126)<>"" Then NLINHA = NLINHA + 1 EndIf

EndProc ;Cabecalho()

;*******************************************************************************
;* Rotina para Impressao do Relatorio - Itens                                  *
;*******************************************************************************
Proc Itens()

QUANT    = 0
TOT      = 0
CONTADOR = 0

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]
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("W11,AL",[Codigo do Item])
  Print File ARQIMP Spaces(01)+Format("W73,AL",[Descricao do Item])
  Print File ARQIMP Spaces(01)+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])+"\n"
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
  CONTADOR = CONTADOR + 1
EndWhile

For ITEM From CONTADOR To 16
    Print File ARQIMP "\n"
EndFor

EndProc ;Itens()

;*******************************************************************************
;* Rotina para Impressao do Relatorio - Rodap‚                                 *
;*******************************************************************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

;NLINHA = NLINHA + 12 ;Total de Linhas do Rodap‚

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

Moveto "FaturaC"
If QUEBRAFORM
   Then Print File ARQIMP Spaces(100)+"Total.............."+Format("W11,AC","*********")+"\n"
   Else Print File ARQIMP Spaces(100)+"Total.............."+Format("W11.2,EIC",TOT)+"\n"
EndIf

If QUEBRAFORM
   Then Print File ARQIMP Spaces(100)+"Desconto"+Format("W7,AC","***") + "%..."
        Print File ARQIMP Format("W11,AC","*********")+"\n" 
   Else Print File ARQIMP Spaces(100)+"Desconto"+Format("W7.2,EIC",[Taxa de Desconto]) + "%..."
        Print File ARQIMP Format("W11.2,EIC",[Valor Desconto])+"\n"
EndIf        

If QUEBRAFORM
   Then Print File ARQIMP Spaces(100)+"Total Liquido......"+Format("W11.2,AC","*********")+"\n\n"
   Else Print File ARQIMP Spaces(100)+"Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido])+"\n\n"
EndIf   

Print File ARQIMP "\014"
Print File ARQIMP Spaces(05)+"\27E"+Format("AC","*** APOS VENCIMENTO SERA COBRADO JUROS DE 0.3% AO DIA ***")+"\27F"+"\n\n"
Print File ARQIMP "\020"

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

If SubStr([Observacao na Nota Fiscal],001,126)<>""
   Then Print File ARQIMP "  OBS.: "+Format("W126,AL",SubStr([Observacao na Nota Fiscal],001,126))+"\n"
EndIf

If SubStr([Observacao na Nota Fiscal],127,126)<>""
   Then Print File ARQIMP Spaces(08)+Format("W126,AL",SubStr([Observacao na Nota Fiscal],127,126))+"\n"
EndIf
        
;************************** IMPRESSAO DOS VENCIMENTOS **************************
Print File ARQIMP "\020"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(2)
Print File ARQIMP "Vencimentos: "

Array DATA[12]
Array VALOR[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])
  If K=10
     Then VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

If K>0
   Then VENC()
EndIf
;Print File ARQIMP "\n\n"
Print File ARQIMP "\027F"

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

EndProc ;Rodape()

;*******************************************************************************
;* Rotina de Impressao dos Vencimentos                                         *
;*******************************************************************************
Proc VENC()
If KV>0
   Then Print File ARQIMP Spaces(11)
EndIf
For I From 1 to K
  Print File ARQIMP DATA[I]+Spaces(01)
EndFor
Print File ARQIMP "\n"
Print File ARQIMP Spaces(15)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(01)
EndFor
Print File ARQIMP "\n\n"

KV=KV+1
EndProc
   
;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="" EndIf

ArqImp=PrivDir()+"RO_0341A.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)

Cabecalho()
Itens()
Rodape(False) 

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

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