;** RR_0185 ********************************************************************
;** Imprime a Producao                                    ** Territ.Nacional** *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 30/08/2007 por Anivel Augusto Rodrigues
;Alterado em     :   /  /     por
;Motivo Alteracao:

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

;************************* IMPRESSAO DO CABECALHO *****************************
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2
Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" + ASP2+"\n"
Print File ARQIMP ASP1+ Format("W40,AL",NOMEMPRESA)+Format("W62,AC","ROMANEIO DE ENTRADA DE PRODUCAO "+[RFACC->Destino_Producao])+
                        "Impressao: "+Format("D13",Today())+"-"+Time()+ ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" +ASP2+ "\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Executor: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W76,AL",[Razao Social])
Print File ARQIMP CI_INEG+CI_IEXP+"N§ Producao: "+Format("W06.3,AL",[Numero_Producao])+CI_FNEG+CI_FEXP+ASP2+"\n"

If [RFACC->Destino_Producao]<>"INTERNO"
   Then
 Print File ARQIMP ASP1+Spaces(17)+Format("W40,AL",Reg_Busca_Lookup["Endereco"])
 Print File ARQIMP Format("W25,AL",Reg_Busca_Lookup["CGC"])
 Print File ARQIMP Format("W25,AL",Reg_Busca_Lookup["Contato"])+ASP2+"\n"

 Print File ARQIMP ASP1+Spaces(17)+Format("W20,AL",Reg_Busca_Lookup["Bairro"])
 Print File ARQIMP Format("W20,AL",Reg_Busca_Lookup["CEP"])
 Print File ARQIMP Format("W25,AL",Reg_Busca_Lookup["IE"])
 Print File ARQIMP Format("W25,AL",Reg_Busca_Lookup["Telefone"])+ASP2+"\n"

 Print File ARQIMP ASP1+Spaces(17)+Format("W20,AL",Reg_Busca_Lookup["Cidade"])
 Print File ARQIMP Format("W20,AL",Reg_Busca_Lookup["UF"])+ASP2+"\n\n"
   Else
 Print File ARQIMP ASP1+ASP2+"\n"
EndIf

Print File ARQIMP ASP1+"Entrada: "
Print File ARQIMP Format("D13",[Data_Producao])+"   "
Print File ARQIMP "Programacao: "+[Numero_Programacao]+"   "
Print File ARQIMP "Tabela: "+[Codigo da Tabela]+"   "
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+ASP2+"\n"

;---- Imprime Observacoes ------------------------------------------------------
TamObs=132

nlobs=Len([RFACC->Observacoes])/tamobs
If nlobs-Int(nlobs)>0
   Then nlobs=Int(nlobs)+1
   Else nlobs=Int(nlobs)
EndIf

posobs=1
For i from 1 to nlobs
  Print File ARQIMP ASP1+CI_INEG+SubStr([Observacoes],posobs,tamobs)+CI_FNEG+ASP2+"\n"
  posobs=posobs+tamobs
EndFor
;********************* IMPRESSAO DOS ITENS ********************************
Print File ARQIMP ASP1+"ÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄ"+
                       "ÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÂÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ"+ASP2+"\n"
Print File ARQIMP ASP1+"Seq³Ref   ³Descricao                     ³  P ³  M ³  G ³  GG³    "+
                       "³    ³    ³    ³    ³    ³    ³    ³ Total³UN³  PrUnit³   PrTotal"+ASP2+"\n"
                                  ;999 999.9 123456789012345678901234567890 12345678901234567890 99.999 99.999 99.999 99.999 99.999 XX 9.999,99 999.999,99

Moveto "RFACrig"
Moveto [Numero_Producao]
Locate [RFACC->Numero_Producao]
QUANT=0
QUANT1=0
QUANT2=0
QUANT3=0
QUANT4=0
QUANT5=0
QUANT6=0
QUANT7=0
QUANT8=0
QUANT9=0
QUANT10=0
QUANT11=0
QUANT12=0
TOT=0
SeqItPed=0
While [Numero_Producao]=[RFACC->Numero_Producao]
   SeqItPed=SeqItPed+1

   vrunit=BlankNum()
   vrtot =BlankNum()

   Print File ARQIMP ASP1+Format("W03,AR",StrVal(SeqItPed))+"³"
   Print File ARQIMP Format("W06,AL",[Referencia])+"³"
   Print File ARQIMP Format("W30,AL",[Descricao do Item])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd1])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd2])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd3])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd4])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd5])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd6])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd7])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd8])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd9])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd10])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd11])+"³"
   Print File ARQIMP Format("W04,EIC",[Qtd12])+"³"
   Print File ARQIMP Format("W06,EIC",[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                                      [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                                      [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])+"³"
   Print File ARQIMP Format("W02,AL",[Unidade Interna])+"³"
   Print File ARQIMP Format("W08.2,EIC",vrunit)+"³"
   Print File ARQIMP Format("W10.2,EIC",vrtot)+ASP2+"\n"

   QUANT  =QUANT  +[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                   [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                   [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12]
   QUANT1   =QUANT1   +[Qtd1 ]
   QUANT2   =QUANT2   +[Qtd2 ]
   QUANT3   =QUANT3   +[Qtd3 ]
   QUANT4   =QUANT4   +[Qtd4 ]
   QUANT5   =QUANT5   +[Qtd5 ]
   QUANT6   =QUANT6   +[Qtd6 ]
   QUANT7   =QUANT7   +[Qtd7 ]
   QUANT8   =QUANT8   +[Qtd8 ]
   QUANT9   =QUANT9   +[Qtd9 ]
   QUANT10  =QUANT10  +[Qtd10]
   QUANT11  =QUANT11  +[Qtd11]
   QUANT12  =QUANT12  +[Qtd12]
   TOT=TOT+vrtot
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

If QUANT1 =0 Then QUANT1 =BlankNum() EndIf
If QUANT2 =0 Then QUANT2 =BlankNum() EndIf
If QUANT3 =0 Then QUANT3 =BlankNum() EndIf
If QUANT4 =0 Then QUANT4 =BlankNum() EndIf
If QUANT5 =0 Then QUANT5 =BlankNum() EndIf
If QUANT6 =0 Then QUANT6 =BlankNum() EndIf
If QUANT7 =0 Then QUANT7 =BlankNum() EndIf
If QUANT8 =0 Then QUANT8 =BlankNum() EndIf
If QUANT9 =0 Then QUANT9 =BlankNum() EndIf
If QUANT10=0 Then QUANT10=BlankNum() EndIf
If QUANT11=0 Then QUANT11=BlankNum() EndIf
If QUANT12=0 Then QUANT12=BlankNum() EndIf

Print File ARQIMP ASP1+"ÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ"+
                       "³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄ³ÄÄÄÄÄÄ³ÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄ"+ASP2+"\n"

Print File ARQIMP ASP1+"Totais =>  "+Spaces(30)+"³"
Print File ARQIMP Format("W04,EIC",QUANT1 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT2 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT3 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT4 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT5 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT6 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT7 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT8 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT9 )+"³"
Print File ARQIMP Format("W04,EIC",QUANT10)+"³"
Print File ARQIMP Format("W04,EIC",QUANT11)+"³"
Print File ARQIMP Format("W04,EIC",QUANT12)+"³"
Print File ARQIMP Format("W06,EIC",QUANT)+"³"
Print File ARQIMP Spaces(02)+" "
Print File ARQIMP Spaces(08)+" "
Print File ARQIMP Format("W10.2,EIC",TOT)+ASP2+"\n"

Print File ARQIMP ASP1+"ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄ"+
                       "ÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"+ASP2+"\n"

;************************* IMPRESSAO DO RODAPE ********************************
Moveto "RFACC"

Print File ARQIMP ASP1+CI_10CPP+"\f"+ASP2+"\n"
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

Moveto "RFACC"
FormKey
CoEditKey
Moveto [Codigo]
If Not Busca_Lookup("Codigo",[Codigo],"SM")
   Then Reg_Busca_Lookup=""
EndIf
UnLockRecord
Do_It!

Seta_FilePrint("RR_0185")
IMPPROD()
ClearAll
Imprime_FilePrint("Imprimindo Producao -> "+NPROD,"1")

Release Vars QUANT, QUANT1, QUANT2, QUANT3, QUANT4, QUANT5, QUANT6,
             QUANT7, QUANT8, QUANT9, QUANT10, QUANT11, QUANT12,
             TOT, SeqItPed, Vrunit, vrtot

Release Procs IMPPROG,
              Seta_FilePrint, Imprime_FilePrint
