;** RM_0380H *******************************************************************
;** Imprime a Digitacao do Pedido/Grade - Sem Preco - Saldo a Faturar          *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 06/10/2020 por Bruno Carvalho
;Ultima Altera‡Æo:   /  /     por  
;Motivo Alteracao:  
                                      
;*******************************************************************************
;* Checa linha na area de impressao dos itens                                  *
;*******************************************************************************
Proc RM_0380H_Checa_Linha(nl,tp)
Private nl,tp,ntab

ntab=table()

If (nlin+nl) >= 64              
   Then 
        Print File ARQIMP "\n"
        Print File ARQIMP Format("W131,AC","*** Continua proxima pagina ==> ")    

        Print File ARQIMP CI_10CPP
        Print File ARQIMP "\f"

        RM_0380H_Cabecalho_Tit()

        If tp="Item"
           Then RM_0380H_Cabecalho_Item()
        EndIf
EndIf

nlin=nlin+nl
moveto ntab

EndProc ;Checa_Linha()

;*******************************************************************************
;* Verifica as Grades no Pedido                                                *
;*******************************************************************************
Proc RM_0380H_Verifica_Grades()
Private i

Release vars Array_Grade, array_tittm, array_tqtd
DynArray Array_Grade[]

Moveto TabelaGrade
Moveto [Numero do Pedido]
Locate [Answer->Numero do Pedido]
While [Numero do Pedido]=[Answer->Numero do Pedido]
  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

SEQ  = 0      

Array array_tittm[12]
Array  array_tqtd[14]                             

For i From 1 to 12
  array_tittm[i]=""
EndFor

For i From 1 to 14
  array_tqtd[i]=0
EndFor

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]
  EndIf

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

EndProc

;*******************************************************************************
;* Rotina para Impressao do Cabecalho titulo                                   *
;*******************************************************************************
Proc RM_0380H_Cabecalho_Tit()
NPAG = NPAG + 1

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

Moveto "Answer"
Print File ARQIMP CI_6LPP+CI_15CPP+"\n"
Print File ARQIMP Fill("-",133)+"\n"
Print File ARQIMP  Completa(NOMEMPRESA,55," ")+"Pedido de Venda"+Spaces(24)+"Emissao: "+Format("D13",Today())+"-"+Time()+
                        "   Pag: "+Format("W3,EIC",npag)+"\n"
Print File ARQIMP Fill("-",133)+"\n"

Print File ARQIMP format("W99,AC","* * * QUANTIDADE A FATURAR * * *")+"N§ do Pedido : "+CI_INEG+CI_IEXP+Format("W06.3,AL",[Numero do Pedido])+CI_FNEG+CI_FEXP+"\n\n"

NLIN = 6

EndProc ;Cabecalho_Tit()

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Pedido                                *
;*******************************************************************************
Proc RM_0380H_Cabecalho_Ped()
private FRETECONTA

RM_0380H_Cabecalho_Tit()

Moveto "Answer"
Print File ARQIMP "Cliente: "
Print File ARQIMP Format("W05,AL",[Codigo])
Print File ARQIMP Format("W39,AL",[Razao Social])+Spaces(1)
Print File ARQIMP Format("W45,AL",[Nome Fantasia EmitDest])
Print File ARQIMP "Ped.Origem: "+[Numero Pedido Origem]+"\n"

Print File ARQIMP Spaces(14)+Format("W40,AL",[Endereco])
Print File ARQIMP Format("W18,AL",[CGC])+Spaces(07)+"Emissao: "
Print File ARQIMP Format("D13",[Data de Emissao])+"\n"

Print File ARQIMP Spaces(14)+Format("W20,AL",[Bairro])
Print File ARQIMP Format("W20,AL",[CEP])
Print File ARQIMP Format("W25,AL",[IE])
Print File ARQIMP "Entrega: "+Format("D13",[Data de Entrega])+"\n"

Print File ARQIMP Spaces(14)+Format("W40,AL",[Cidade]+"/"+[UF])
Print File ARQIMP Format("W25,AL",[Telefone])
Print File ARQIMP "Empresa: "+Format("W05,AL",[Codigo da Empresa])+Format("W20,AL",[Nome Fantasia Empresa])+"\n\n"

Print File ARQIMP "Representante: "+Format("W05,AL",[Codigo do Representante])
Print File ARQIMP Format("W25,AL",[Nome Fantasia Represent])
Print File ARQIMP "Destinacao: "+Format("W04,AL",[Codigo da Destinacao])
Print File ARQIMP Format("W25,AL",[Descricao da Destinacao])
Print File ARQIMP "CFO: "+Format("W09,AL",[CFO])+"      Tabela: "+[Codigo da Tabela]+"\n"

FRETECONTA=""
Switch
  Case [Frete por Conta]="0" : FRETECONTA="SEM FRETE"
  Case [Frete por Conta]="1" : FRETECONTA="EMITENTE"
  Case [Frete por Conta]="2" : FRETECONTA="DESTINATARIO"
  Case [Frete por Conta]="3" : FRETECONTA="TERCEIROS"
EndSwitch

Print File ARQIMP "Transportador: "+Format("W05,AL",[Codigo da Transportadora])
Print File ARQIMP Format("W28,AL",[Nome Fantasia Transport])
Print File ARQIMP "Veiculo: "+Format("W08,AL",[Placa do Veiculo])+"-"+Format("W08,AL",[UF Veiculo])
Print File ARQIMP "Frete por Conta: "+[Frete por Conta]+" "+FRETECONTA+"\n\n"

NLIN = NLIN + 8
                                        
RM_0380H_Cabecalho_Item()

EndProc ;Cabecalho_Ped()

;*******************************************************************************
;* Rotina para Impressao do Cabecalho do Item                                  *
;*******************************************************************************
Proc RM_0380H_Cabecalho_Item()
Private wc

RM_0380H_Checa_Linha(DynArraySize(Array_Grade)+2,"")

Print File ARQIMP Spaces(1)+Fill("-",133)+"\n"
For wc From 1 to DynArraySize(Array_Grade)
  If wc=DynArraySize(Array_Grade)                                                 
     Then linha=Spaces(1)+"Seq"+ESPACO+"Ref   "+ESPACO+"Descricao                                      "+ESPACO+"S"+" "+ESPACO+""+Array_Grade[wc]+"Total "+ESPACO+"UN"      
     Else linha=Spaces(1)+"   "+ESPACO+"      "+ESPACO+"                                               "+ESPACO+" "+" "+ESPACO+""+Array_Grade[wc]+"      "+ESPACO+"  "  
  EndIf                 
  Print File ARQIMP linha+"\n"                                                          
EndFor
Print File ARQIMP Spaces(1)+"---+------+-----------------------------------------------+-+--+----+----+----+----+----+----+----+----+----+----+----+----+------+--"+"\n"
                                                                                                                                              
EndProc ;Cabecalho_Item()

;*******************************************************************************
;* Imprime Totalizador                                                         *
;*******************************************************************************
Proc RM_0380H_Totalizador()


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
 
RM_0380H_Checa_Linha(4,"")
Print File ARQIMP Spaces(1)+"---------------------------------------------------------------+----+----+----+----+----+----+----+----+----+----+----+----+------+--"+"\n"

Print File ARQIMP Spaces(64)+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[01])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[02])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[03])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[04])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[05])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[06])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[07])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[08])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[09])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[10])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[11])+ESPACO
Print File ARQIMP Format("W04,EIC",array_tqtd[12])+ESPACO
Print File ARQIMP Format("W06,EIC",array_tqtd[13])+ESPACO+"\n"

Print File ARQIMP Spaces(1)+Fill("-",133)+"\n\n"

EndProc ;Totalizador()

;*******************************************************************************
;* Rotina para Impressao do Relatorio                                          *
;*******************************************************************************
Proc RM_0380H_ImpPed()
Private SEQ

ESPACO= "|"

SEQ  = 0
NPAG = 0
NLIN = 0

TOTQ = 0

MUDOU_GRADE = False

Moveto TabelaG
Moveto [Numero do Pedido]
Locate [Answer->Numero do Pedido]
if retval 
   then Grad=[Codigo da Grade]
        RM_0380H_Verifica_Grades()
        RM_0380H_Cabecalho_Ped()
        
        Moveto TabelaG
        while [Numero do Pedido]=[Answer->Numero do Pedido]
          SEQ  = SEQ + 1

          RM_0380H_Checa_Linha(1,"Item")
          
          Print File ARQIMP Format("W04,AR",AlinhM(StrVal(SEQ),3))+ESPACO
          Print File ARQIMP Format("W06,AL",[Referencia])+ESPACO
          Print File ARQIMP Format("W27,AL",[Descricao do Item])+Format("W20,AL",[Descricao Da Cor_Tecido])+ESPACO
          Print File ARQIMP Format("W1,AL",[ItemSortido])+ESPACO+" "
          Print File ARQIMP Format("W01,AL",[Codigo da Grade])+ESPACO 
          Print File ARQIMP Format("W04,EIC",[Qtd1])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd2])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd3])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd4])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd5])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd6])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd7])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd8])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd9])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd10])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd11])+ESPACO
          Print File ARQIMP Format("W04,EIC",[Qtd12])+ESPACO
          Print File ARQIMP Format("W06,EIC",[Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                                             [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                                             [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])+ESPACO
          Print File ARQIMP Format("W02,AL",[Unidade Fiscal])+"\n"
          
          TOTQ = TOTQ + ([Qtd1]+[Qtd2 ]+[Qtd3 ]+[Qtd4 ]+
                         [Qtd5]+[Qtd6 ]+[Qtd7 ]+[Qtd8 ]+
                         [Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])  
          
          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]
          
          Skip
          If EOT() Then QuitLoop EndIf
        EndWhile

        RM_0380H_Totalizador()  
        RM_0380H_Rodape(False)
endif                 
moveto "Answer"

EndProc ;ImpPed()

;*******************************************************************************
;* Rotina para Impressao do Rodape                                             *
;*******************************************************************************
Proc RM_0380H_Rodape(QUEBRAFORM)
Private QUEBRAFORM

Moveto "Answer"
Print File ARQIMP CI_6LPP+CI_15CPP

RM_0380H_Checa_Linha(4,"")
Print File ARQIMP Spaces(110)+"Total Pedido  "+ESPACO
Print File ARQIMP Format("W06,EIC",TOTQ)+"\n\n"
   
imprimeobs1()

Print File ARQIMP Fill("-",133)

Print File ARQIMP CI_10CPP
Print File ARQIMP "\f"

EndProc ;Rodape()

;*******************************************************************************
;* Rotina de Impressao de Observa‡äes                                          *
;*******************************************************************************
proc imprimeobs1()
private TamObs, nlobs, posobs, i, s

TamObs=133

s=Tira_QuebraLinha([Observacao do Pedido])

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

RM_0380H_Checa_Linha(nlobs,"")
posobs=1
For i from 1 to nlobs
  Print File ARQIMP Spaces(1)+Ltrim(SubStr(s,posobs,tamobs))+"\n"
  posobs=posobs+tamobs
EndFor

endproc

;*******************************************************************************
;* Rotina Monta Aray Grade                                                     *
;*******************************************************************************
Proc RM_0380H_Verifica_Array_Grade()
Private i

Coluna=0

If [Codigo da Grade]<>codgrade
   Then codgrade=[Codigo da Grade]
    
        Moveto "\\Sistemas\\Estoque\\TpGrade"
        Moveto [Codigo da Grade]
        Locate [Answer->Codigo da Grade]
        If Not RetVal
           Then 
                Mensagem("Item "+[Answer->Codigo do Item]+" "+[Answer->Descricao do Item]+", sem grade definida !")
                for i from 1 to 12
                  Array_TM[i] =""
                endfor
                Return
           Else CopyToArray reg_grade
        EndIf

        Array_TM[1] =LTrim(RTrim(reg_grade["Codigo Item1"]))
        Array_TM[2] =LTrim(RTrim(reg_grade["Codigo Item2"]))
        Array_TM[3] =LTrim(RTrim(reg_grade["Codigo Item3"]))
        Array_TM[4] =LTrim(RTrim(reg_grade["Codigo Item4"]))
        Array_TM[5] =LTrim(RTrim(reg_grade["Codigo Item5"]))
        Array_TM[6] =LTrim(RTrim(reg_grade["Codigo Item6"]))
        Array_TM[7] =LTrim(RTrim(reg_grade["Codigo Item7"]))
        Array_TM[8] =LTrim(RTrim(reg_grade["Codigo Item8"]))
        Array_TM[9] =LTrim(RTrim(reg_grade["Codigo Item9"]))
        Array_TM[10]=LTrim(RTrim(reg_grade["Codigo Item10"]))
        Array_TM[11]=LTrim(RTrim(reg_grade["Codigo Item11"]))
        Array_TM[12]=LTrim(RTrim(reg_grade["Codigo Item12"]))
EndIf

Moveto "Answer"
For i from 1 to 12
  If Len(RTrim(SubStr(Array_TM[i],1,2)))=1
     Then If SubStr([Codigo do Item],10,1)=SubStr(Array_TM[i],1,1)
             Then Coluna=i
                  QuitLoop
          EndIf
     Else If SubStr([Codigo do Item],9,2)=SubStr(Array_TM[i],1,2)
             Then Coluna=i
                  QuitLoop
          EndIf
  EndIf
EndFor

EndProc

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
proc RM_0380H_Seleciona()
private qtdaf, NR

ClearAll

If VSDGOPDTPEEIRF="4" or
   VSDGOPDTPEEIRF="5"
   then 
        {Ask} typeIn TabelaRPedidos Enter
        Moveto [Numero do Pedido        ] Example "Pedido"
        {Ask} TypeIn "\\Sistemas\\Vendas\\PedidoC" Enter 
        Moveto [Numero do Pedido        ] Example "Pedido" Check
   else
        {Ask} TypeIn "\\Sistemas\\Vendas\\PedidoC" Enter 
        Moveto [Numero do Pedido        ] Check

        if not isblank(VSDGPEDIDO)
           then 
                Moveto [Numero do Pedido] TypeIn "~VSDGPEDIDO.."
           else 
                Moveto [Numero do Pedido] TypeIn ">=~VSDGNPEDIDOI, <=~VSDGNPEDIDOF"
                Moveto [Codigo da Empresa       ] TypeIn "~VSDGEMPRESA.."
        
                if VSDGOPDTPEEIRF="1" Then Moveto [Data de Entrega ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM" endif
                If VSDGOPDTPEEIRF="2" Then Moveto [Data de Emissao ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM" endif
                if VSDGOPDTPEEIRF="3" Then Moveto [Data_Inclusao   ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM" endif
        
                Moveto [Situacao do Pedido    ]
                switch
                  case VSDGSITUACAOPEDIDO="JUNTAR ABERTO+SUSPENSO"     : TypeIn "ABERTO or SUSPENSO"
                  case VSDGSITUACAOPEDIDO="IGNORAR CANCELADO+SUSPENSO" : TypeIn "not CANCELADO, not SUSPENSO"
                  case VSDGSITUACAOPEDIDO="IGNORAR CANCELADO"          : TypeIn "not CANCELADO"
                  case VSDGSITUACAOPEDIDO<>"TODAS"                     : TypeIn "~VSDGSITUACAOPEDIDO.."
                endswitch
                Moveto [Codigo                 ] TypeIn "~VSDGDESTINAT.."
                Moveto [Codigo do Representante] TypeIn "~VSDGREPRESEN.."
        endif   
endif
Moveto [Razao Social        ] Check
Moveto [Observacao do Pedido] Check   
Do_It!
ClearAll

TabelaC=Adiciona_Indice_Temp("Numero do Pedido")

{Ask} typeIn TabelaC Enter
Moveto [Numero do Pedido        ]       Example "Pedido"
Moveto [Razao Social            ] Check
Moveto [Observacao do Pedido    ] Check
{Ask} TypeIn "\\Sistemas\\Vendas\\PedidoI" Enter
Moveto [Numero do Pedido        ] check Example "Pedido"
Moveto [Item do Pedido          ] check 
Moveto [Codigo do Item          ] check 
Moveto [Descricao do Item       ] check 
Moveto [Codigo da Cor_Tecido    ] check 
Moveto [Descricao da Cor_Tecido ] check 
Moveto [Referencia              ] check 
Moveto [Unidade Fiscal          ] check 
Moveto [ItemSortido             ] check 
Moveto [Quantidade              ] check 
Moveto [Quantidade Faturada     ] check 
Do_It!
ClearAll

{Ask} TypeIn "\\Sistemas\\Estoque\\Itens" Enter 
Moveto [Codigo do Item          ]       typein "_ite"
Moveto [Codigo da Grade         ] check
{Ask}{Answer} check
Moveto [Codigo do Item          ]       typein "_ite!"
Do_It!
ClearAll

TabelaG=Cria_Tabela("","Numero do Pedido(A6*),Referencia(A20*),Codigo da Cor_Tecido(A4*),"+
"Descricao do Item(A30),Descricao da Cor_Tecido(A20),Qtd1(S),Qtd2(S),Qtd3(S),Qtd4(S),Qtd5(S),Qtd6(S),Qtd7(S),Qtd8(S),"+
"Qtd9(S),Qtd10(S),Qtd11(S),Qtd12(S),Quantidade(S),Unidade Fiscal(A4),ItemSortido(A1),Codigo da Grade(A1),"+
"Razao Social(A40),Observacao do Pedido(M1)")

Array Array_TM[12]

NR = NRecords("Answer")

codgrade="???"
View "\\Sistemas\\Estoque\\TpGrade"
View TabelaG
CoEdit "Answer"
scan 
  Barra(NR, RecNo())
  Aguarde("Aguarde, processando saldos de pedidos "+BARRA_STRING)

  If ([Quantidade]>[Quantidade Faturada]) then
  
      RM_0380H_Verifica_Array_Grade()
    
      Moveto TabelaG
      Moveto [Numero do Pedido]
      Locate [Answer->Numero do Pedido],[Answer->Referencia],[Answer->Codigo da Cor_Tecido]
      If Not RetVal
         Then End
              Down     
              [Numero do Pedido       ]=[Answer->Numero do Pedido       ]
              [Codigo da Grade        ]=[Answer->Codigo da Grade        ]
              [Referencia             ]=[Answer->Referencia             ]
              [Codigo da Cor_Tecido   ]=[Answer->Codigo da Cor_Tecido   ]
              [Descricao do Item      ]=Substr([Answer->Descricao do Item],1,23)
              [Descricao da Cor_Tecido]=[Answer->Descricao da Cor_Tecido]
              [Unidade Fiscal         ]=[Answer->Unidade Fiscal         ]
              [ItemSortido            ]=[Answer->ItemSortido            ]
              [Razao Social           ]=[Answer->Razao Social           ]
              [Observacao do Pedido   ]=[Answer->Observacao do Pedido   ]
                            
      EndIf
    
      qtdaf=[Answer->Quantidade]-[Answer->Quantidade Faturada]
    
      Switch
        Case Coluna=0 : [Qtd1  ]=[Qtd1  ]+qtdaf
        Case Coluna=1 : [Qtd1  ]=[Qtd1  ]+qtdaf
        Case Coluna=2 : [Qtd2  ]=[Qtd2  ]+qtdaf
        Case Coluna=3 : [Qtd3  ]=[Qtd3  ]+qtdaf
        Case Coluna=4 : [Qtd4  ]=[Qtd4  ]+qtdaf
        Case Coluna=5 : [Qtd5  ]=[Qtd5  ]+qtdaf
        Case Coluna=6 : [Qtd6  ]=[Qtd6  ]+qtdaf
        Case Coluna=7 : [Qtd7  ]=[Qtd7  ]+qtdaf
        Case Coluna=8 : [Qtd8  ]=[Qtd8  ]+qtdaf
        Case Coluna=9 : [Qtd9  ]=[Qtd9  ]+qtdaf
        Case Coluna=10: [Qtd10 ]=[Qtd10 ]+qtdaf
        Case Coluna=11: [Qtd11 ]=[Qtd11 ]+qtdaf
        Case Coluna=12: [Qtd12 ]=[Qtd12 ]+qtdaf
      EndSwitch
      [Quantidade]=[Quantidade]+qtdaf
    
  endif
  Moveto "Answer"

endscan
Do_it!
ClearAll

Delete TabelaC

{Ask} typeIn TabelaG Enter  typein "Fast Delete"
Moveto [Quantidade              ] typein "0 or blank"
Do_it!
ClearAll

{Ask} typeIn TabelaG Enter 
Moveto [Numero do Pedido        ] check
Do_it!
ClearAll
TabelaC=Adiciona_Indice_Temp("Numero do Pedido")

{Ask} TypeIn TabelaG Enter
Moveto [Numero do Pedido] Check
Moveto [Codigo da Grade ] Check
Do_It!
ClearAll
TabelaGrade=Adiciona_Indice_Temp("Numero do Pedido,Codigo da Grade")

;---- Ordenar Tabela por Razao Social e Descricao da Cor_Tecido ----------------
{Ask} TypeIn TabelaG Enter Check
Do_It!
ClearAll

If Not IsEmpty("Answer")
   Then Sort "Answer" On "Razao Social","Numero do Pedido","Descricao da Cor_Tecido"
        
        ClearAll
 
        Copy "Answer" TabelaG
        Delete "Answer" 
EndIf

{Ask} typeIn TabelaC Enter 
Moveto [Numero do Pedido        ] Example "Pedido"
{Ask} TypeIn "\\Sistemas\\Vendas\\PedidoC" Enter check
Moveto [Numero do Pedido        ] Example "Pedido"
Do_It!
ClearAll

Delete TabelaC

EndProc    ; (Seleciona)

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ArqImp=PrivDir()+"RM_0380H.Txt"
If IsFile(ARQIMP)
  Then ImpriArq(ARQIMP)
       Deleta_Arquivo(ARQIMP)
EndIf 

RM_0380H_Seleciona()
If IsEmpty(TabelaG)
   Then MENSAGEM("N„o existem registros a processar")
   Else Sort "Answer" On "Razao Social","Numero do Pedido"
        ClearAll
        
        View "\\Sistemas\\Estoque\\TpGrade"
        View TabelaG
        View TabelaGrade
        View "Answer"
        scan
          AGUARDE("Imprimindo Pedido -> "+[Numero do Pedido])
        
          RM_0380H_ImpPed()
        
        endscan
        ClearAll
        
        LimpAguarde()
        ImpriArq(ARQIMP)
endif

Delete TabelaG

LimpAguarde()

Release Vars  NLIN,NPAG,
              Grade,Grad,MUDOU_GRADE,
              Array_Grade,array_tqtd,array_tittm,
              TOTQ,
              ESPACO,ARQIMP, Array_TM

Release Procs RM_0380H_Checa_Linha, RM_0380H_Verifica_Grades, RM_0380H_Cabecalho_Tit, RM_0380H_Cabecalho_Ped, RM_0380H_Cabecalho_Item,
              RM_0380H_Rodape,      RM_0380H_Totalizador,     RM_0380H_ImpPed, RM_0380H_Seleciona, RM_0380H_Verifica_Array_Grade
