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

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

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf
Npag=Npag+1

Moveto "PFACC"
Print File ARQIMP ASP1+CI_8LPP+CI_15CPP+ASP2
Print File ARQIMP chr(27)+chr(67)+chr(44) ;Imprime 44 Linhas por pagina
Print File ARQIMP ASP2

Print File ARQIMP ASP1+ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" + ASP2+"\n"
Print File ARQIMP ASP1+ Format("W40,AL",NOMEMPRESA)+Format("W52,AC","ROMANEIO DE SAIDA PARA PRODUCAO "+[PFACC->Destino_Producao])+
                        "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("W70,AL",[Razao Social])
Print File ARQIMP CI_INEG+CI_IEXP+"N§ Programacao: "+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",RegClie["Endereco"])
 Print File ARQIMP Format("W25,AL",RegClie["CGC"])
 Print File ARQIMP Format("W25,AL",RegClie["Contato"])+ASP2+"\n"

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

 Print File ARQIMP ASP1+Spaces(17)+Format("W20,AL",RegClie["Cidade"])
 Print File ARQIMP Format("W20,AL",RegClie["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])+ASP2+"\n"

Nlin=10
;---- 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

Moveto "Answer"
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho/Itens                                    *
;*******************************************************************************
Proc Cabecalho_Itens()

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

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

Print File ARQIMP ASP1+"SeqÝRef   ÝDescricao                     Ý"+
      TIT_TM[01]+"Ý"+
      TIT_TM[02]+"Ý"+
      TIT_TM[03]+"Ý"+
      TIT_TM[04]+"Ý"+
      TIT_TM[05]+"Ý"+
      TIT_TM[06]+"Ý"+
      TIT_TM[07]+"Ý"+
      TIT_TM[08]+"Ý"+
      TIT_TM[09]+"Ý"+
      TIT_TM[10]+"Ý"+
      TIT_TM[11]+"Ý"+
      TIT_TM[12]+"Ý"+
      " TotalÝUNÝ  PrUnitÝ   PrTotal"+ASP2+"\n"

Nlin=nlin+2
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

Moveto "Answer"
cdgrade="***"
Cabecalho()
Scan

   If [Codigo da Grade]<>cdgrade
      Then cdgrade=[Codigo da grade]
           Play "Montitgr"
           Cabecalho_Itens()
   EndIf

   If Nlin>84
      Then Rodape()
           Cabecalho()
           Cabecalho_Itens()
   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 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)+"\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

EndScan

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 "PFACC"

Print File ARQIMP ASP1+" DECLARO PARA OS DEVIDOS FINS QUE RECEBI A(S) MERCADORIA(S) ACIMA RELACIONADA(S)."
Print File ARQIMP      " POR SER VERDADE, SUBSCREVO-ME"+ASP2+"\n\n"
Print File ARQIMP ASP1+"  ___/___/_____  _______________________________"+ASP2+"\n"
Print File ARQIMP ASP1+" Responsavel execucao"+ASP2+"\n\n"
Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"+ASP2+"\n"
              
EndProc

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

ClearAll

{Ask} {PFACRIG} Check
Moveto [Numero_Programacao] TypeIn "~NPROG"
Do_It!
ClearAll

Sort "Answer" on "Codigo da Grade", "Sequencia do Lancamento"
ClearAll

While True

 View "Answer"
 View "\\Sistemas\\Estoque\\Tpgrade"
 View "\\Sistemas\\Cadastro\\Destinat"
 View "PFACC"
 Moveto [Numero_Programacao]
 Locate NPROG
 If Not RetVal
    Then QuitLoop
 EndIf

 View "\\Sistemas\\Cadastro\\Destinat"
 Moveto [Codigo]
 Locate [PFACC->Codigo]
 If RetVal
    Then CopyToArray Regclie
    Else Regclie=""
 EndIf
 Moveto "Answer"

 Seta_FilePrint("RP_0000")
 IMPPROG()
 Imprime_FilePrint("Imprimindo Programacao -> "+NPROG,"1")

 QuitLoop
EndWhile
ClearAll

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

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