;** RC_0204 ********************************************************************
;** Imprime a Programacao Corte                           ** Uzze Buzze **     *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido  em: 06/10/2008 por Anivel Augusto Rodrigues
;Alterado em     : 18/10/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes Ordem Crescente Referˆncia

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

;************************* 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","ORDEM DE CORTE")+"Impressao: "+Format("D13",Today())+"-"+Time()+ ASP2+"\n"
Print File ARQIMP ASP1+ "------------------------------------------------------------------------------------------------------------------------------------" +ASP2+ "\n\n"

Print File ARQIMP ASP1+Spaces(02)+"Responsavel: ______________________________"+Spaces(50)
Print File ARQIMP CI_INEG+CI_IEXP+"N§ Corte: "+Format("W06.3,AL",[Numero_Corte])+CI_FNEG+CI_FEXP+ASP2+"\n"

Print File ARQIMP ASP1+Spaces(02)+"Programado : "
Print File ARQIMP Format("D13",[Data_Programacao])+"   "
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+ASP2+"\n"

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

nlobs=Len([CFACC->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                     Ý PP Ý  P Ý  M Ý  G Ý GG "+
                       "Ý    Ý    Ý    Ý    Ý    Ý    Ý    Ý TotalÝUNÝ                   "+ASP2+"\n"
Print File ARQIMP ASP1+"SeqÝRef   ÝDescricao                     Ý 02 Ý 04 Ý 06 Ý 08 Ý 10 "+
                       "Ý 12 Ý 14 Ý 16 Ý    Ý    Ý    Ý    Ý TotalÝUNÝ                   "+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 "Answer"
Moveto [Numero_Corte]
Locate [CFACC->Numero_Corte]
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
SeqItPed=0
While [Numero_Corte]=[CFACC->Numero_Corte]
   SeqItPed=SeqItPed+1

   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])+"Ý"+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]
   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)+"Ý"+ASP2+"\n"

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

;************************* IMPRESSAO DO RODAPE ********************************
Moveto "CFACC"

OBS="Pedidos a atender: "
obs_inicio=True
Moveto "CFACP"
Moveto [Numero_Corte]
Locate [CFACC->Numero_Corte]
While [Numero_Corte]=[CFACC->Numero_Corte]

   If (Len(OBS)+7)>132
      Then Print File ARQIMP ASP1+OBS+ASP2+"\n"
           OBS=""
   EndIf
   If obs_Inicio
      Then OBS=OBS+[Numero do Pedido]
           obs_inicio=false
      Else OBS=OBS+", "+[Numero do Pedido]
   EndIf

   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

If Len(OBS)>0
   Then Print File ARQIMP ASP1+OBS+ASP2+"\n"
EndIf
Print File ARQIMP ASP1+CI_10CPP+"\f"+ASP2+"\n"

Moveto "CFACC"
EndProc

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

Moveto "CFACC"
FormKey
Seta_FilePrint("RC_0204")

{Ask} TypeIn "CFACRIG" Enter Check
Moveto [Numero_Corte] TypeIn "~NCORT" 
Do_It!

Sort "Answer" On "Referencia"

Moveto "CFACC"
Moveto [Numero_Corte]
Locate NCORT

IMPPROG()   
ClearAll
Imprime_FilePrint("Imprimindo Producao -> "+NCORT,"1")

Release Vars QUANT, QUANT1, QUANT2, QUANT3, QUANT4, QUANT5, QUANT6,
             QUANT7, QUANT8, QUANT9, QUANT10, QUANT11, QUANT12,
             SeqItPed,OBS,obs_inicio

Release Procs IMPPROG,
              Seta_FilePrint, Imprime_FilePrint
