;** RP_0369 ********************************************************************
;** Imprime a Programacao                              ** MORANGO E MEL **     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 26/10/2015 por Andrey Fillipe
;Alterado em     :   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Cabecalho()

If VIA=2
  Then Print File ARQIMP ASP1+"\f"+ASP2+"\n"
EndIf
  
If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Npag=Npag+1

Moveto "PFACC"
Print File ARQIMP ASP1+CI_8LPP+CI_15CPP
Print File ARQIMP chr(27)+chr(67)+chr(44) ;Imprime 44 Linhas por pagina
Print File ARQIMP ASP2+"\n"
If VIA=2
   Then Print File ARQIMP ASP1+ CI_INEG+CI_IEXP+ "2§ Via" +CI_FNEG+CI_FEXP+ASP2+ "\n"
EndIf   
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" + ASP2+"\n"
;Print File ARQIMP ASP1+ Format("W40,AL",NOMEMPRESA)
Print File ARQIMP ASP1+ Format("W52,AL","ROMANEIO DE SAIDA PARA PRODUCAO "+[PFACC->Destino_Producao])+Spaces(40)+
                        "Impressao: "+Format("D13",Today())+"-"+Time()+ "  Pag: "+Strval(NPAG)+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("W75,AL",[Razao Social])
Print File ARQIMP "N§ Programacao: "+CI_INEG+CI_IEXP+Format("W06.3,AL",[Numero_Programacao])+CI_FNEG+CI_FEXP+ASP2+"\n"

If [PFACC->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+"Programado: "
Print File ARQIMP Format("D13",[Data_Programacao])+"   "
Print File ARQIMP "Corte: "+[Numero_Corte]+"   "
Print File ARQIMP "Tabela: "+[Codigo da Tabela]+"   "
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"   "  
Print File ARQIMP CI_INEG
Print File ARQIMP "Data de Entrega: "
Print File ARQIMP Format("D13",([Data_Programacao]+7))
Print File ARQIMP CI_FNEG+ASP2+"\n"

Nlin=14
;---- Imprime Observacoes ------------------------------------------------------
TamObs=132

nlobs=Len([PFACC->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
  Nlin=Nlin+1
EndFor

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

Print File ARQIMP ASP1+"   Ý      Ý                              Ý PP Ý  P Ý  M Ý  G Ý GG "+
                       "Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý      Ý  Ý        Ý          "+ASP2+"\n"
Print File ARQIMP ASP1+"SeqÝRef   ÝDescricao                     Ý 02 Ý 04 Ý 06 Ý 08 Ý 10 "+
                       "Ý 12 Ý 14 Ý 16 Ý    Ý    Ý    Ý    Ý TotalÝUNÝ  PrUnitÝ   PrTotal"+ASP2+"\n"
Print File ARQIMP ASP1+"---+------+------------------------------Ý----Ý----Ý----Ý----Ý----"+
                       "Ý----Ý----Ý----Ý----Ý----Ý----Ý----Ý------Ý--+--------+----------"+ASP2+"\n"


Moveto "PFACRIG"
EndProc

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

Print File ARQIMP ASP1+"CONTINUA PROXIMA PAGINA -->"+"\f"+ASP2+"\n"
EndProc

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

Npag =0
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()

Moveto "Pfacrig"
Moveto [Numero_Programacao]
Locate [PFACC->Numero_Programacao]
While [Numero_Programacao]=[PFACC->Numero_Programacao]

   If Nlin>84
      Then Rodape()
           Cabecalho()
   EndIf

   SeqItPed=SeqItPed+1

   If [PFACC->Destino_Producao]="INTERNO"
      Then vrunit=BlankNum()
           vrtot =BlankNum()
      Else vrunit=[Preco Unitario]
           vrtot =[Preco Total   ]
   EndIf

   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"

   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(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\n"
If Nlin<50
  Then Ficha_Faccao()
  Else Rodape()
       Cabecalho()
       Ficha_Faccao()
EndIf       
;************************* IMPRESSAO DO RODAPE ********************************
Moveto "PFACC"

Print File ARQIMP ASP1+"                                                   RECIBO DE ROMANEIO: "+Format("W06.3,AL",[Numero_Programacao])+ASP2+"\n"
Print File ARQIMP ASP1+"                     Recebi as mercadorias acima discriminadas, responsabilizando-me por toda devolucao das pecas"+ASP2+"\n"
Print File ARQIMP ASP1+"                     (prontas ou a fazer), obrigando-me a ideniza-la caso haja alguma falta."+ASP2+"\n\n\n"

Print File ARQIMP ASP1+"  ___/___/_____  _______________________________"+ASP2+"\n"
Print File ARQIMP ASP1+"  Responsavel execucao"+ASP2+"\n\n\n\n\n"
Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"

VIA=2
              
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho                                          *
;*******************************************************************************
Proc Ficha_Faccao()

;Print File ARQIMP ASP1+"                                                         Itens do Corte                                                           "+ASP2+"\n"
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý            Ý Etiqueta de Composicao     Ý            ÝEtiqueta de Tamanho        Ý            ÝTapa Gola                        Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý            Ý Golas                      Ý            ÝPunhos                     Ý            ÝEntretelas                       Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý            ÝEtiqueta de Barra ou Bolso  Ý            Ý                           Ý            Ý                                 Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý            Ý                            Ý            Ý                           Ý            Ý                                 Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n\n"

;Print File ARQIMP ASP1+"                                                       Combinacoes de Cores                                                       "+ASP2+"\n"
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý      Cores       Ý  Combinacoes          Ý      Cores       Ý  Combinacoes          Ý      Cores       Ý  Combinacoes           Ý"+ASP2+"\n"
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý                  Ý                       Ý                  Ý                       Ý                  Ý                        Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
;Print File ARQIMP ASP1+"Ý                  Ý                       Ý                  Ý                       Ý                  Ý                        Ý"+ASP2+"\n" 
;Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n\n"

Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+"Ý                                                         Ficha Faccao                                                            Ý"+ASP2+"\n"
Print File ARQIMP ASP1+" ---------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+"Ý Pecas Prontas   Ý Data          Ý Assinatura                  Ý Ý Pecas Prontas    Ý Data          Ý Assinatura                 Ý"+ASP2+"\n"
Print File ARQIMP ASP1+" ---------------------------------------------------------------   ---------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+"Ý                 Ý               Ý                             Ý Ý                  Ý               Ý                            Ý"+ASP2+"\n" 
Print File ARQIMP ASP1+" ---------------------------------------------------------------   ---------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+"Ý                 Ý               Ý                             Ý Ý                  Ý               Ý                            Ý"+ASP2+"\n" 
Print File ARQIMP ASP1+" ---------------------------------------------------------------   ---------------------------------------------------------------"+ASP2+"\n"
Print File ARQIMP ASP1+"Ý                 Ý               Ý                             Ý Ý                  Ý               Ý                            Ý"+ASP2+"\n"
Print File ARQIMP ASP1+" ----------------------------------------------------------------  ---------------------------------------------------------------"+ASP2+"\n\n"

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

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

Seta_FilePrint("RP_0204")
VIA=1
IMPPROG()
IMPPROG()
ClearAll
Imprime_FilePrint("Imprimindo Programacao -> "+NPROG,"1")

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

Release Procs IMPPROG, Cabecalho, Cabecalho_Itens, Rodape,
              Seta_FilePrint, Imprime_FilePrint,Ficha_Faccao
