;** RR_0266 ********************************************************************
;** Imprime a Producao                                    ** Cacharrel **      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 14/02/2013 por Kamila Gomes            
;Alterado em     :   /  /     por
;Motivo Alteracao:

;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

Print File ARQIMP ASP1+CI_6LPP+CI_15CPP+ASP2
Print File ARQIMP chr(27)+chr(67)+chr(33) ;Imprime 33 Linhas por pagina
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"

Nlin=12

Verifica_Grades()

;---- 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

Print File ARQIMP ASP1+"------------------------------------------------------------------"+
                       "-----------------------------------------------------------------"+ASP2+"\n"
                       
 For wc From 1 to DynArraySize(Array_Grade)
  If wc=DynArraySize(Array_Grade) 
     Then Print File ARQIMP ASP1+"SeqÝRef   ÝDescricao                     Ý"+Array_Grade[wc]+" TotalÝUNÝ  PrUnitÝ PrTotal"+ASP2+"\n"
     Else Print File ARQIMP ASP1+"                                         Ý"+Array_Grade[wc]+"                              "+ASP2+"\n"
  EndIf
  
EndFor

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

EndProc ;Cabecalho

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

Nlin =0
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

Cabecalho()

;********************* IMPRESSAO DOS ITENS ********************************

Moveto "RFACrig"
Moveto [Numero_Producao]
Locate [RFACC->Numero_Producao]

While [Numero_Producao]=[RFACC->Numero_Producao]
   If Nlin>26
      Then Rodape()
           Cabecalho()
   EndIf
   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("W01,AL",[Codigo da Grade])+"Ý"
   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"
   
   Nlin=nlin+1

   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(32)+"Ý"
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(06)+" "
Print File ARQIMP Format("W10.2,EIC",TOT)+ASP2+"\n"

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

If Nlin>25
  Then Rodape()
       Moveto "RFACC"
       Cabecalho()
EndIf 
;************************* IMPRESSAO DO RODAPE ********************************
Moveto "RFACC"

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

;*******************************************************************************
;* Verifica as Grades na Programacao                                                *
;*******************************************************************************
Proc Verifica_Grades()
Private wc,gok

View NoWindow "\\Sistemas\\Estoque\\TpGrade"
View "RFACrig"
CoEditKey

DynArray Array_Grade[]

Moveto "RFACrig"
Moveto [Numero_Producao]
Locate [RFACC->Numero_Producao]
While [Numero_Producao]=[RFACC->Numero_Producao]
  gok=False
  For wc From 1 to DynArraySize(Array_Grade)
    If Array_Grade[wc]=[Codigo da Grade]
       Then gok =True
    EndIf
  EndFor
  If Not gok
     Then Array_Grade[DynArraySize(Array_Grade)+1]=Completa([Codigo da Grade],1," ")
  EndIf

  Skip
  If EOT() Then QuitLoop EndIf
EndWhile

Array array_tittm[12]
Moveto "\\Sistemas\\Estoque\\TpGrade"
Moveto [Codigo da Grade]
For wc From 1 to DynArraySize(Array_Grade)
  Locate SubStr(Array_Grade[wc],1,1)
  If RetVal
     Then array_tittm[1] =[Titulo Grade1 ]
          array_tittm[2] =[Titulo Grade2 ]
          array_tittm[3] =[Titulo Grade3 ]
          array_tittm[4] =[Titulo Grade4 ]
          array_tittm[5] =[Titulo Grade5 ]
          array_tittm[6] =[Titulo Grade6 ]
          array_tittm[7] =[Titulo Grade7 ]
          array_tittm[8] =[Titulo Grade8 ]
          array_tittm[9] =[Titulo Grade9 ]
          array_tittm[10]=[Titulo Grade10]
          array_tittm[11]=[Titulo Grade11]
          array_tittm[12]=[Titulo Grade12]
     Else For i From 1 to 12
            array_tittm[i]=""
          EndFor
  EndIf

  Array_Grade[wc]=Array_Grade[wc]+"Ý"+
                  Format("W4,AR",array_tittm[01])+"Ý"+
                  Format("W4,AR",array_tittm[02])+"Ý"+
                  Format("W4,AR",array_tittm[03])+"Ý"+
                  Format("W4,AR",array_tittm[04])+"Ý"+
                  Format("W4,AR",array_tittm[05])+"Ý"+
                  Format("W4,AR",array_tittm[06])+"Ý"+
                  Format("W4,AR",array_tittm[07])+"Ý"+
                  Format("W4,AR",array_tittm[08])+"Ý"+
                  Format("W4,AR",array_tittm[09])+"Ý"+
                  Format("W4,AR",array_tittm[10])+"Ý"+
                  Format("W4,AR",array_tittm[11])+"Ý"+
                  Format("W4,AR",array_tittm[12])+"Ý"
EndFor

Do_It!
Moveto "RFACC"

Release Vars wc,wi,gok,array_tittm
EndProc


;*******************************************************************************
;* Rotina Rodade                                                               *
;*******************************************************************************
Proc Rodape()
Print File ARQIMP ASP1+"------------------------------------------------------------------"+
                       "-----------------------------------------------------------------"+ASP2+"\n"

Print File ARQIMP ASP1+"CONTINUA PROXIMA PAGINA -->"+"\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_0222")
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
