;** RO_0270   ******************************************************************
;** Imprime a Digitacao do Romaneio                        ** Comercial JB **  *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 16/08/2010 por Bruno Carvalho
;Ultima Alteracao: 15/06/2016 por Bruno Carvalho 
;Motivo Alteracao: Adicionado Pega_Endereco_Fatura() e ajustado dados do endere‡o
;Ultima Alteracao: 26/06/2018 por Anivel Augusto Rodrigues                           
;Motivo Alteracao: Ajustes itens mercadoria/servico

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

If (NLINHA+nl)>67
   Then Print File ARQIMP "\f"
        Cabecalho()
EndIf
NLINHA=NLINHA+nl
EndProc
;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()

Moveto "FaturaC"
Pega_Endereco_Fatura([Numero da OF])

Print File ARQIMP "\n"
Print File ARQIMP  "---------------------------------------------------------------------------------------------" + "\n"
Print File ARQIMP  "Comercial JB Equipamentos Eletroeletronicos LTDA"+Spaces(17)+"Emissao: "+Format("D13",Today())+"-"+Time()+ "\n"
Print File ARQIMP  "---------------------------------------------------------------------------------------------" + "\n\n"

Print File ARQIMP "Operacao: "+Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP Spaces(40)+"Ronameio N§ "+Format("W06.3,AL",NOTAFISC)+"\n\n"

Print File ARQIMP "Cliente.......: "+Format("W50,AL",[Razao Social])
If [Telefone] <> "" 
   Then Print File ARQIMP Spaces(01)+"Fone: "+Format("W20,AL",[Telefone])+"\n" 
   Else Print File ARQIMP "\n"   
EndIf 

Print File ARQIMP "Local Fatura..: "
Print File ARQIMP RTrim(Format("W33,AL",[Endereco]))+" - "
Print File ARQIMP RTrim(Format("W20,AL",[Bairro]))+"\n"
Print File ARQIMP Spaces(16)+RTrim(Format("W10,AL",[CEP])) 
Print File ARQIMP Spaces(02)+RTrim(Format("W20,AL",[Cidade]))+" / "+RTrim(Format("W03,AL",[UF]))+"\n"       
Print File ARQIMP Spaces(16)+Format("W18,AL",[CGC])
Print File ARQIMP Spaces(02)+Format("W25,AL",[IE])+"\n\n"                       

NLINHA=12

If VSD_E_Endereco<>"O MESMO" And  VSD_E_Endereco<>""
   Then Print File ARQIMP "Local Entrega.: "+RTrim(Format("W33,AL",VSD_E_Endereco))+" - "
        Print File ARQIMP RTrim(Format("W20,AL",VSD_E_Bairro))+"\n"
        Print File ARQIMP Spaces(16)+RTrim(Format("W10,AL",VSD_E_CEP))
        Print File ARQIMP Spaces(02)+RTrim(Format("W20,AL",VSD_E_Cidade))
        Print File ARQIMP " / "+RTrim(Format("W03,AL",VSD_E_UF))+"\n\n"
        NLINHA=NLINHA+3
   Else Print File ARQIMP "Local Entrega.: O MESMO"+"\n\n"
        NLINHA=NLINHA+2 
EndIf
                        
Print File ARQIMP "Representante : "+Format("W25,AL",[Nome Fantasia Represent])+"\n\n"

If NAO_IMPRIME=False
   Then Print File ARQIMP "Item                                                Un Quantidade Unitario             Total"+"\n"
        Print File ARQIMP "--------------------------------------------------- -- ---------- -------- -----------------"+"\n"
   Else Print File ARQIMP "--------------------------------------------------------------------------------------------"+"\n"     
EndIf

NLINHA=NLINHA+4 
Moveto "FaturaI"        

EndProc ;Cabecalho()

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

Print File ARQIMP CI_12CPP

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Moveto "FaturaC"

NAO_IMPRIME=False

Cabecalho()

Moveto "FaturaI"
Moveto [Numero da OF]
Locate [FaturaC->Numero da OF]        
QUANT=0
TOT=0
While [Numero da OF]=[FaturaC->Numero da OF]
   Checa_Linha(1)
   Print File ARQIMP Format("W03,AR",StrVal([Item da OF]))
   Print File ARQIMP Spaces(01)+Format("W11,AL",[Codigo do Item])
   Print File ARQIMP Spaces(01)+Format("W18,AL",[Descricao do Item])
   Print File ARQIMP Spaces(01)+Format("W15,AL",[Descricao da Cor_Tecido])
   Print File ARQIMP Spaces(01)+Format("W03,AR",[Unidade Fiscal])
   Print File ARQIMP Format("W11.3,EIC",[Quantidade])
   Print File ARQIMP Format("W09.2,EIC",[Preco Unitario])
   Print File ARQIMP Spaces(07)+Format("W11.2,EIC",[Preco Total])+"\n"
   QUANT=QUANT+[Quantidade]
   TOT=TOT+[Preco Total]
   Skip
   If EOT() Then QuitLoop Endif
EndWhile

Moveto "FaturaC"

Checa_Linha(4)
Print File ARQIMP Spaces(55)+"----------                -----------"+"\n"
Print File ARQIMP Spaces(54)+Format("W11.3,EIC",QUANT)+Spaces(16)+Format("W11.2,EIC",TOT)+"\n\n"
Print File ARQIMP "---------------------------------------------------------------------------------------------" + "\n"

NAO_IMPRIME=True

Checa_Linha(3)
Print File ARQIMP Spaces(62)+"Desconto"+Format("W06.2,EIC",[Taxa de Desconto])+"%...."+Format("W11.2,EIC",[Valor Desconto])+"\n"
Print File ARQIMP Spaces(62)+"Total Liquido......"+Format("W11.2,EIC",[Valor Mercadoria Liquido])+"\n\n"

If Substr([Observacao na Nota Fiscal],001,090)<>""
   Then If Substr([Observacao na Nota Fiscal],091,090)<>""
          Then Checa_Linha(4)
               Print File ARQIMP "- "+Format("W90,AL",SubStr([Observacao na Nota Fiscal],001,090))+"\n"
               Print File ARQIMP Spaces(02)+Format("W90,AL",SubStr([Observacao na Nota Fiscal],091,090))+"\n\n\n"
          Else Checa_Linha(2)
               Print File ARQIMP "- "+Format("W90,AL",SubStr([Observacao na Nota Fiscal],001,090))+"\n\n"
        EndIf     
EndIf                        

Checa_Linha(2)
Print File ARQIMP "\027E"
Print File ARQIMP "CONDI€åES DE PAGAMENTO: "
Print File ARQIMP "\027F"
Print File ARQIMP "· Vista com 5% de desconto"+"\n"
Print File ARQIMP Spaces(24)+"ou entrada +30/60 dias no cheque ou cartÆo Master"+"\n"

Checa_Linha(3)
Print File ARQIMP "\027E"
Print File ARQIMP "OBS: PARA PAGAMENTO · VISTA NAO INCLUE DESCONTO SOBRE MÇO DE OBRA"+"\n\n\n"
Print File ARQIMP "\027F"

Checa_Linha(2)
Print File ARQIMP "\027E"
Print File ARQIMP "GARANTIA: "
Print File ARQIMP "\027F"
Print File ARQIMP "12 (doze) meses … partir de 02 de Julho de 2010 contra defeito de fabrica‡Æo"+"\n"


Checa_Linha(5)
Print File ARQIMP "\027E"
Print File ARQIMP "Excetuam-se da garantia os defeitos ocorridos por:"+"\n"
Print File ARQIMP "\027F"
Print File ARQIMP "1 - instala‡Æo fora do padrÆo t‚cnico especificado"+"\n"
Print File ARQIMP "2 - uso inadequado, bem como utiliza‡Æo de acess¢rios instalados junto ao equipamento"+"\n"
Print File ARQIMP "3 - viola‡Æo do equipamento e ou utiliza‡Æo de pe‡as nÆo originais"+"\n"
Print File ARQIMP "4 - fen“menos atmosf‚ricos e acidentais"+"\n\n\n"

Checa_Linha(5)
;************************ 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
  KK= K+1
  DATA[K]  = Format("D13",[Data])
  VALOR[K] = Format("W11.2,AL,EIC",[Valor])
  If K=4
     Then PARCELAS = K
          VENC()
          K=0
  EndIf
  Skip
  If EOT() Then QuitLoop EndIf
EndWhile
If K>0
   Then PARCELAS = K
        VENC()
EndIf
Print File ARQIMP "\n\n"
Print File ARQIMP "\027F"

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

Checa_Linha(4)
Print File ARQIMP "\027F"
Print File ARQIMP Spaces(02)+"            VENDA                                           E N T R E G A"+"\n"
Print File ARQIMP Spaces(02)+"   /   /   -                                     /   /   -"+"\n"
Print File ARQIMP Spaces(02)+"-----------------------------------           ----------------------------------------"+"\n"
Print File ARQIMP Spaces(02)+"   Data e Assinatura do Emitente                 Data e Assinatura do Destinatario"
Print File ARQIMP CI_10CPP
Print File ARQIMP CI_6LPP
Print File ARQIMP "\f"

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(12)
For I From 1 to K
  Print File ARQIMP VALOR[I]+Spaces(01)
EndFor
Print File ARQIMP "\n"

KV=KV+1

EndProc

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


