;** RC_0227 ********************************************************************
;** Imprime a Programacao Corte                                      - Siri    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 09/02/2010 por Anivel Augusto Rodrigues
;Ultima Alteracao: 08/01/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Siri 

;*******************************************************************************
;* Verifica as Grades no Pedido                                                *
;*******************************************************************************
Proc Verifica_Grades()
Private wc,gok

DynArray Array_Grade[]

Moveto "CFACRIG"
Moveto [Numero_Corte]
Locate [CFACC->Numero_Corte]
While [Numero_Corte]=[CFACC->Numero_Corte]
  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
Moveto "CFACRIG"

Release Vars wc,wi,gok,array_tittm
EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc Cabecalho_Item()
Private wc,linha

          linha="----------------------------------------------------------------------------------------------------------------------------------"
Print File ARQIMP linha+"\n"

Moveto "CFACRIG"
For wc From 1 to DynArraySize(Array_Grade)
  If wc=DynArraySize(Array_Grade)
     Then linha="SeqÝRef   ÝDescricao              Cor                    Ý"+Array_Grade[wc]+" TotalÝUNÝ"
     Else linha="                                                         Ý"+Array_Grade[wc]+"          "
  EndIf
  Print File ARQIMP linha+"\n"
  nlin=nlin+1
EndFor

          linha="---+------+----------------------------------------------+-+----+----+----+----+----+----+----+----+----+----+----+----+------+---"
Print File ARQIMP linha+"\n"

nlin=nlin+2
EndProc

;*******************************************************************************
;* Rodape para Itens                                                           *
;*******************************************************************************
Proc Rodape(tp)
Private tp
If tp="Item"
   Then Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------------------"+"\n"
Endif
Print File ARQIMP "\n"
Print File ARQIMP Format("W132,AR","*** Continua proxima pagina ==> ")+"\f"+"\n"
EndProc


;*******************************************************************************
;* Rotina para Impressao do Cabecalho titulo                                   *
;*******************************************************************************
Proc Cabecalho_Tit()
npag=npag+1

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf


Print File ARQIMP CI_6LPP+CI_15CPP+"\n"
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------" +"\n"
Print File ARQIMP Format("W40,AL",NOMEMPRESA)+Format("W62,AC","ORDEM DE CORTE")+"Impressao: "+Format("D13",Today())+"-"+Time()+"\n"
Print File ARQIMP "------------------------------------------------------------------------------------------------------------------------------------" +"\n\n"

nlin=5

EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho da Programacao                           *
;*******************************************************************************
Proc Cabecalho_Prog()

Moveto "CFACC"
Cabecalho_Tit()

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

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


nlin=nlin+3

Imprime_Observacoes()

Cabecalho_Item()
EndProc


;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc Checa_Linha(nl,tp)
private nl,tp

If (nlin+nl)>=64
   Then Rodape(tp)
        Cabecalho_Tit()
        If tp="Item"
           Then Cabecalho_Item()
        EndIf
EndIf
nlin=nlin+nl
EndProc

;*******************************************************************************
;* Imprime Observacoes do Pedido                                               *
;*******************************************************************************
Proc Imprime_Observacoes()
Private obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs

tamobs=132
For wc From 1 To 1
	Switch
    Case wc=1 : obs    =[CFACC->Observacoes]
                tit_obs="Obs: "
	EndSwitch

  nlobs=Len(obs)/tamobs
	If nlobs-Int(nlobs)>0
		 Then nlobs=Int(nlobs)+1
		 Else nlobs=Int(nlobs)
	EndIf
	If nlobs=0 Then nlobs=1 EndIf

	posobs=1
	For i from 1 to nlobs
		Checa_Linha(1,"")
    Print File ARQIMP CI_INEG+tit_obs+SubStr(obs,posobs,tamobs)+CI_FNEG+"\n"

    tit_obs=Spaces(18)
    posobs =posobs+tamobs
	EndFor
EndFor
Checa_Linha(1,"")
Print File ARQIMP "\n"

Release Vars obs,tit_obs,wi,wc,tamobs,nlobs,posobs,tit_obs
EndProc


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

If Not IsAssigned(NOMEMPRESA)
   Then NOMEMPRESA=""
EndIf

npag=0
nlin=0

Array array_tqtd[14]  ;** controla total   13=total pecas  14=total valor **
For wi From 1 to 14
  array_tqtd[wi]=0
EndFor

Verifica_Grades()
Cabecalho_Prog()

Moveto "CFACRIG"
Moveto [Numero_Corte]
Locate [CFACC->Numero_Corte]
SeqItPed=0
While [Numero_Corte]=[CFACC->Numero_Corte]

   Checa_Linha(1,"Item")

   SeqItPed=SeqItPed+1

   Print File ARQIMP Format("W03,AR",StrVal(SeqItPed))+"Ý"
   Print File ARQIMP Format("W06,AL",[Referencia])+"Ý"
   Print File ARQIMP Format("W27,AL",[Descricao do Item])+" "
   Print File ARQIMP Format("W18,AL",[Descricao da Cor_Tecido])+"Ý"
   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])+"Ý"+"\n"

   array_tqtd[01]=array_tqtd[01]+[Qtd1 ]
   array_tqtd[02]=array_tqtd[02]+[Qtd2 ]
   array_tqtd[03]=array_tqtd[03]+[Qtd3 ]
   array_tqtd[04]=array_tqtd[04]+[Qtd4 ]
   array_tqtd[05]=array_tqtd[05]+[Qtd5 ]
   array_tqtd[06]=array_tqtd[06]+[Qtd6 ]
   array_tqtd[07]=array_tqtd[07]+[Qtd7 ]
   array_tqtd[08]=array_tqtd[08]+[Qtd8 ]
   array_tqtd[09]=array_tqtd[09]+[Qtd9 ]
   array_tqtd[10]=array_tqtd[10]+[Qtd10]
   array_tqtd[11]=array_tqtd[11]+[Qtd11]
   array_tqtd[12]=array_tqtd[12]+[Qtd12]

   array_tqtd[14]=array_tqtd[14]+[Preco Total]
   Skip
   If EOT() Then QuitLoop EndIf
EndWhile

;************** IMPRESSAO DOS TOTAIS DAS GRADES DO PEDIDO ****************
For wi From 1 to 12
  If array_tqtd[wi]=0 then array_tqtd[wi]=BlankNum() EndIf
  array_tqtd[13]=array_tqtd[13]+array_tqtd[wi]
EndFor

Checa_Linha(3,"")
Print File ARQIMP "-----------------------------------------------------------+----+----+----+----+----+----+----+----+----+----+----+----+----------"+"\n"

Print File ARQIMP Completa("Totais=>",59," ")+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[01])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[02])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[03])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[04])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[05])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[06])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[07])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[08])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[09])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[10])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[11])+"Ý"
Print File ARQIMP Format("W04,EIC",array_tqtd[12])+"Ý"
Print File ARQIMP Format("W06,EIC",array_tqtd[13])+"Ý"
Print File ARQIMP Spaces(11)+" "+"\n"

Print File ARQIMP "----------------------------------------------------------------------------------------------------------------------------------"+"\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 Checa_Linha(1,"")
           Print File ARQIMP OBS+"\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 Checa_Linha(1,"")
        Print File ARQIMP OBS+"\n"
EndIf
Print File ARQIMP CI_10CPP+"\f"+"\n"

Moveto "CFACC"
EndProc


;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AGUARDE("Imprimindo Programa‡„o-> "+NCORT)

Seta_FilePrint("rc_0000")
Switch
	Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
EndSwitch


Moveto "CFACC"
FormKey

;****** Adicionando tabelas para trabalho **************************************
View NoWindow "\\Sistemas\\Estoque\\TpGrade"
CoEditKey

;*******************************************************************************

ImpProg()
ImpriArq(ARQIMP)

;****** Liberando tabelas de trabalho ******************************************
Do_It!
ClearAll

;*******************************************************************************

LimpAguarde()

Release Vars  nlin,npag,array_grade,
              array_tqtd

Release Procs Seta_FilePrint,ImpProg,ImpriArq,
              Cabecalho_Prog,Cabecalho_Item,Cabecalho_Tit,Rodape,
              Imprime_Observacoes,
              Checa_Linha,
              Verifica_Grades
