;** RO_0254 ********************************************************************
;** Imprime a Digitacao do Romaneio                               ** HAS **    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 29/04/2010 por Cleber Alves            
;Alterado      em: 06/05/2010 por Cleber Alves         
;Motivo Alteracao: Ajustes

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************

;************************** IMPRESSAO DO CABECALHO *****************************
Proc 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_8LPP

;Print File ARQIMP "\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Format("W58,AL","H A S  GESSO LTDA")+"\n"
Print File ARQIMP "\020"
Print File ARQIMP "\027F"

Print File ARQIMP "TEL.: 37-3213-6880 "+" - "+Format("D10",Today())+"-"+Time()+ "\n"

Print File ARQIMP "\014"
Print File ARQIMP "\027E"
Print File ARQIMP Spaces(20)+"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 "Destinatario: "+Format("W40,AL",[Nome Fantasia EmitDest])+"\n"
Print File ARQIMP "\027F"

Print File ARQIMP CI_10CPP
Print File ARQIMP "\015"

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 "  Vendedor: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])+"\n"
Print File ARQIMP Chr(27)+Chr(71)
Print File ARQIMP "SR CLIENTE FAVOR CONFERIR A MERCADORIA NO ATO DA COMPRA,"+"\n"
Print File ARQIMP "POIS NAO ACEITAREMOS DEVOLUCOES OU TROCAS DE PECAS USADAS OU DANIFICADAS."+"\n"
Print File ARQIMP Chr(27)+Chr(72)
Print File ARQIMP "\015"         ;Imprime 17 Caracteres por polegada
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP "Item ÝCodigo     ÝDescricao                                                Ý Un  Ý   QuantidadeÝ Unitario Ý     Total"+"\n"
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------"+"\n"
EndProc ;(Cabecalho)

;********************* IMPRESSAO DOS ITENS ********************************
Proc Itens()
Print File ARQIMP CI_6LPP
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]
  Checa_Linha(1)
  LINHA_ITEM = Spaces(02)+Format("W03,AR",StrVal([Item da OF]))+"Ý"
  LINHA_ITEM = LINHA_ITEM +Format("W11,AL",[Codigo do Item])+"Ý"
  LINHA_ITEM = LINHA_ITEM + Format("W57,AL",[Descricao do Item])+"Ý"
  LINHA_ITEM = LINHA_ITEM + Spaces(01)+Format("W04,Al",[Unidade Fiscal])+"Ý"
  LINHA_ITEM = LINHA_ITEM + Format("W13.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"
  
  TOT   = TOT + [Preco Total]
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

For ITEM From CONTADOR To PARAM_NITENS
    Print File ARQIMP "\n"
EndFor
Print File ARQIMP CI_8LPP
EndProc ;(Itens)

;********************* IMPRESSAO DOS TOTAIS **************************
Proc Rodape(QUEBRAFORM)
Private QUEBRAFORM

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

Print File ARQIMP Spaces(02)+"OBS.: "
Print File ARQIMP Format("W75,AL",SubStr([Observacao na Nota Fiscal],001,73))
If QUEBRAFORM
   Then Print File ARQIMP Spaces(05)+"Total.............."+Format("W11.2,EIC","*****")+"\n"
        Print File ARQIMP Spaces(88)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%...."
        Print File ARQIMP Format("W12.2,EIC","*****")+"\n"
   Else Print File ARQIMP Spaces(05)+"Total.............."+Format("W11.2,EIC",TOT)+"\n"
        Print File ARQIMP Spaces(88)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto]) + "%..."
        Print File ARQIMP Format("W12.2,EIC",[Valor Desconto])+"\n"
EndIf    

Print File ARQIMP "          *** FAVOR MANTER O ENDERECO E O TELEFONE ATUALIZADOS ***"
If QUEBRAFORM
   Then Print File ARQIMP Spaces(22)+"Total Liquido......"+Format("W11.2,EIC","*****")+"\n\n"
        Print File ARQIMP "\018"
        Print File ARQIMP "\027E"
        Print File ARQIMP Spaces(17)+Format("W48,AR","   * * * *  CONTINUA NO PROXIMO FORMULARIO * * * *    ")
        Print File ARQIMP "\027F"   
   Else Print File ARQIMP Spaces(22)+"Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido]+[Valor Servico])+"\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 "\027F"
EndIf




;************************* IMPRESSAO DO RODAPE *********************************
If QUEBRAFORM
   Then Print File ARQIMP "\n\n\n" 
   Else Print File ARQIMP Spaces(12)+"   /   /     -                                   " + "\n"
        Print File ARQIMP Spaces(12)+"-------------------------------------------------" + "\n"
        Print File ARQIMP Spaces(12)+"              Data e Assinatura"+"\n" 
EndIf        
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(13)
EndIf

If IMPRIMINDO_PARCELAS
   Then Print File ARQIMP DATA[NP]+Spaces(02)+"\n"
        Print File ARQIMP Spaces(13)+VALOR[NP]+Spaces(02)+"\n\n"
        return
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

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

If (CONTADOR+nl)>(PARAM_NITENS)
   Then RodaPe(True)
        Cabecalho()
        CONTADOR=nl
        Moveto "FaturaI"
   Else CONTADOR=CONTADOR+nl
EndIf
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"Ro_0254.Txt"
If IsFile(ArqImp)
   Then Deleta_Arquivo(ARQIMP)
EndIf

AGUARDE("Imprimindo Romaneio -> "+NOTAFISC)

IMPRIMINDO_PARCELAS=FALSE
 NParc=[FaturaC->Numero de Parcelas]
 For NP From 1 to NParc
  If [FaturaV->Forma de Pagamento]="NP"
     Then IMPRIMINDO_PARCELAS=TRUE
  EndIf
    Cabecalho()
    Itens()
    Rodape(False) 
  If IMPRIMINDO_PARCELAS=False Then QuitLoop EndIf
EndFor
Print File ARQIMP "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
;---- Imprime Arquivo Impressao ------------------------------------------------
ImpriArq(ARQIMP)

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

