;** RM_3003 ********************************************************************
;*  Posicao Estoque/Pedidos  Grade                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 16/09/2014 por Bruno Carvalho
;Ultima Alteracao: 09/10/2014 por Andrey Fillipe
;Motivo Alteracao: Adicionado Procs Processa2() e ImpPed2() p/TERRITORIO NACIONAL
;Ultima Alteracao: 10/10/2014 por Andrey Fillipe
;Motivo Alteracao: Retirado Procs Processa2() e ImpPed2()
;                  SIRI E TERRITORIO ira usar o mesmo relatorio
;Ultima Alteracao: 15/05/2015 por Kamila Gomes
;Motivo Alteracao: Ajustado para ter mais espa‡o para dair a descri‡Æo completa da Cor
;Ultima Alteracao: 26/10/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   
;Ultima Alteracao: 27/01/2017 por Anivel Augusto Rodrigues 
;Motivo Alteracao: Ajustes TG_REFERENCIA

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

If (NLin + NL) >= 64
   Then Print File ARQIMP Spaces(2)+Fill("-",134)+"\f"
        Cabecalho_Tit()
        Cabecalho_Item()
EndIf

NLin = NLin + NL

EndProc ;Checa_Linha()

;*******************************************************************************
;* 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\n"
Print File ARQIMP Spaces(2)+Fill("-",134)+"\n"
Print File ARQIMP Spaces(2)+Completa(NOMEMPRESA,57," ")+"Pedido de Venda"+Spaces(22)+"Impressao: "+Format("D13",Today())+"-"+Time()+"  Pag: "+Format("W3,EIC",NPag)+"\n"
Print File ARQIMP Spaces(2)+Fill("-",134)+"\n\n"

NLin = 6

EndProc ;Cabecalho_Tit()

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

Print File ARQIMP Spaces(2)+" ---------------------------------------------------------------------------------------------------------------------------"+"\n"

For wc From 1 to DynArraySize(Array_Grade)
  If wc = DynArraySize(Array_Grade)
     Then Linha = Spaces(2) + " SeqÝRef   ÝDescricao                                  Ý"+Array_Grade[wc]+" Total"
     Else Linha = Spaces(2) + "    Ý      Ý                                           Ý"+Array_Grade[wc]+"      "
  EndIf
  Print File ARQIMP Linha+"\n"
  Nlin = NLin + 1
EndFor

Print File ARQIMP Spaces(2)+" ---+------+-------------------------------------------+-+----+----+----+----+----+----+----+----+----+----+----+----+------"+"\n"

nlin=nlin+2

EndProc ;Cabecalho_Item()

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

AGUARDE("Aguarde, verificando grade dos itens")

View Tabela
Scan
  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
EndScan

Array array_tittm[12]
View "\\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

ClearAll
Release Vars wc,wi,gok,array_tittm

EndProc ;Verifica_Grades()

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

ARQIMP = PrivDir()+"RM_3003.TXT"
If IsFile(ARQIMP)
   Then Deleta_Arquivo(ARQIMP)
EndIf

Array Array_TQTD[13] 
For wi From 1 to 13
  Array_TQTD[wi]=0
EndFor

DynArray Array_Grade[]

NPag = 0
Nlin = 0
SEQ  = 0
TotQtd1  = 0
TotQtd2  = 0
TotQtd3  = 0
TotQtd4  = 0
TotQtd5  = 0
TotQtd6  = 0
TotQtd7  = 0
TotQtd8  = 0
TotQtd9  = 0
TotQtd10 = 0
TotQtd11 = 0
TotQtd12 = 0
TotQtd   = 0

Sort Tabela On "Referencia"
                           
Verifica_Grades()
Cabecalho_Tit()
Cabecalho_Item()

AGUARDE("Aguarde, imprimindo os itens")

View Tabela
Home
REF = [Referencia]
While True
   Checa_Linha(1,"Item")
   SEQ = SEQ + 1
   
   Print File ARQIMP Spaces(2)
   Print File ARQIMP Format("W04,AR",StrVal(SEQ))+"Ý"
   Print File ARQIMP Format("W06,AL",[Referencia])+"Ý"
   Print File ARQIMP Format("W22,AL",[Descricao do Item])+" "+Format("W20,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])+"\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[13] = Array_TQTD[13] + [Qtd1] + [Qtd2 ] + [Qtd3 ] + [Qtd4 ] + [Qtd5] + [Qtd6] + [Qtd7] + [Qtd8] +
                                     [Qtd9] + [Qtd10] + [Qtd11] + [Qtd12]
   
   TotQtd1 = TotQtd1 +[Qtd1 ] 
   TotQtd2 = TotQtd2 +[Qtd2 ] 
   TotQtd3 = TotQtd3 +[Qtd3 ] 
   TotQtd4 = TotQtd4 +[Qtd4 ] 
   TotQtd5 = TotQtd5 +[Qtd5 ] 
   TotQtd6 = TotQtd6 +[Qtd6 ] 
   TotQtd7 = TotQtd7 +[Qtd7 ] 
   TotQtd8 = TotQtd8 +[Qtd8 ] 
   TotQtd9 = TotQtd9 +[Qtd9 ] 
   TotQtd10= TotQtd10+[Qtd10] 
   TotQtd11= TotQtd11+[Qtd11] 
   TotQtd12= TotQtd12+[Qtd12]
   TotQtd  = TotQtd+([Qtd1]+[Qtd2]+[Qtd3]+[Qtd4]+[Qtd5]+[Qtd6]+[Qtd7]+[Qtd8]+[Qtd9]+[Qtd10]+[Qtd11]+[Qtd12])
   
   Skip
   
   If REF<>[Referencia] Or EOT()
      Then Print File ARQIMP Spaces(2)+" --------------------------------------------------------+----+----+----+----+----+----+----+----+----+----+----+----+------"+"\n"
           Print File ARQIMP Spaces(40)+"Total Referencia:  Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd1)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd2)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd3)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd4)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd5)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd6)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd7)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd8)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd9)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd10)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd11)+"Ý"
           Print File ARQIMP Format("W04,EIC",TotQtd12)+"Ý"
           Print File ARQIMP Format("W06,EIC",TotQtd)+"\n"
           Print File ARQIMP "\n"                                   
           TotQtd1 = 0
           TotQtd2 = 0
           TotQtd3 = 0 
           TotQtd4 = 0 
           TotQtd5 = 0 
           TotQtd6 = 0 
           TotQtd7 = 0 
           TotQtd8 = 0 
           TotQtd9 = 0 
           TotQtd10= 0 
           TotQtd11= 0 
           TotQtd12= 0
           TotQtd  = 0
           REF=[Referencia]
           Nlin=Nlin+3
   EndIf   
   
   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
EndFor

Checa_Linha(3,"")
Print File ARQIMP Spaces(2)+" --------------------------------------------------------+----+----+----+----+----+----+----+----+----+----+----+----+------"+"\n"
 
Print File ARQIMP Spaces(44)+"Total Geral :  Ý"
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])+"\n"

Print File ARQIMP Spaces(2)+" ---------------------------------------------------------------------------------------------------------------------------"+"\n"
Print File ARQIMP "\f"    
      
EndProc ;ImpPed()

;*******************************************************************************
;* Rotina para processar os pedidos da rela‡Æo                                 *
;*******************************************************************************
Proc Processa()

AGUARDE("Aguarde, checando dados")

{Ask} {RPedidos}
Moveto [Numero do Pedido       ] Example "NPed"

{Ask} {\\Sistemas\\Vendas\\PedidoC}
Moveto [Numero do Pedido       ] Example "NPed" 
Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."

{Ask} {\\Sistemas\\Vendas\\PedidoG} 
Moveto [Codigo do Item         ] Example "CodI"
Moveto [Numero do Pedido       ] Example "NPed"
Moveto [Codigo da Grade        ] Check
Moveto [Referencia             ] Check
Moveto [Descricao do Item      ] Check
Moveto [Descricao da Cor_Tecido] Check
Moveto [Qtd1                   ] TypeIn "Calc Sum as Qtd1"
Moveto [Qtd2                   ] TypeIn "Calc Sum as Qtd2"
Moveto [Qtd3                   ] TypeIn "Calc Sum as Qtd3"
Moveto [Qtd4                   ] TypeIn "Calc Sum as Qtd4"
Moveto [Qtd5                   ] TypeIn "Calc Sum as Qtd5"
Moveto [Qtd6                   ] TypeIn "Calc Sum as Qtd6"
Moveto [Qtd7                   ] TypeIn "Calc Sum as Qtd7"
Moveto [Qtd8                   ] TypeIn "Calc Sum as Qtd8"
Moveto [Qtd9                   ] TypeIn "Calc Sum as Qtd9"
Moveto [Qtd10                  ] TypeIn "Calc Sum as Qtd10"
Moveto [Qtd11                  ] TypeIn "Calc Sum as Qtd11"
Moveto [Qtd12                  ] TypeIn "Calc Sum as Qtd12" 

{Ask} {\\Sistemas\\Estoque\\Itens} 
Moveto [Codigo do Item         ] Example "CodI"
Moveto [Codigo da Familia      ] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo        ] TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca        ] TypeIn "~VSDGMARCA.."
Moveto [Referencia             ] TypeIn "~VSDGREFERENCIA.."
Do_It!
ClearAll

{Ask} {Answer} TypeIn "Delete" 
Moveto [Qtd1                   ] TypeIn "Blank"
Moveto [Qtd2                   ] TypeIn "Blank"
Moveto [Qtd3                   ] TypeIn "Blank"
Moveto [Qtd4                   ] TypeIn "Blank"
Moveto [Qtd5                   ] TypeIn "Blank"
Moveto [Qtd6                   ] TypeIn "Blank"
Moveto [Qtd7                   ] TypeIn "Blank"
Moveto [Qtd8                   ] TypeIn "Blank"
Moveto [Qtd9                   ] TypeIn "Blank"
Moveto [Qtd10                  ] TypeIn "Blank"
Moveto [Qtd11                  ] TypeIn "Blank"
Moveto [Qtd12                  ] TypeIn "Blank" 
Do_It!
ClearAll
 
CoEdit "Answer"
Scan
  [Descricao do Item] = LTrim(RTrim(SubStr([Descricao do Item],1,22)))
EndScan
Do_It!
ClearAll
 
{Ask} {Answer} Check
Moveto [Qtd1                   ] Check TypeIn "Calc Sum as Qtd1"
Moveto [Qtd2                   ] Check TypeIn "Calc Sum as Qtd2"
Moveto [Qtd3                   ] Check TypeIn "Calc Sum as Qtd3"
Moveto [Qtd4                   ] Check TypeIn "Calc Sum as Qtd4"
Moveto [Qtd5                   ] Check TypeIn "Calc Sum as Qtd5"
Moveto [Qtd6                   ] Check TypeIn "Calc Sum as Qtd6"
Moveto [Qtd7                   ] Check TypeIn "Calc Sum as Qtd7"
Moveto [Qtd8                   ] Check TypeIn "Calc Sum as Qtd8"
Moveto [Qtd9                   ] Check TypeIn "Calc Sum as Qtd9"
Moveto [Qtd10                  ] Check TypeIn "Calc Sum as Qtd10"
Moveto [Qtd11                  ] Check TypeIn "Calc Sum as Qtd11"
Moveto [Qtd12                  ] Check TypeIn "Calc Sum as Qtd12" 
Do_It!

Tabela=Cria_Temp(PrivDir())
Rename "Answer" Tabela

EndProc ;Processa()
              
;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA="F10=Parƒmetros"
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9    : Temp=False
     Case Evento["KeyCode"] = -59  : Dialog_F1()
     Case Evento["KeyCode"] = -68  :
            Temp=False
            Relatorios()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"        : Campo="NO"
            Case Campo="TG_FAMI"           : Campo="TG_EMPRESA"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_REFERENCIA"     : Campo="TG_MARCA"
            Case Campo="YES" Or Campo="NO" : Campo="TG_EMPRESA"
          EndSwitch
     Case (Evento["KeyCode"] <= -104 And Evento["KeyCode"] >= -113) Or 
           Evento["KeyCode"]  = -139 Or  Evento["KeyCode"]  = -140:
           SYS_TECLA_ACIONADA=Evento["KeyCode"]
           Seta_Tecla_Acionada()
           CancelDialog
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_EMPRESA"     : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"        : Campo = "TG_GRP"
                    Case Campo="TG_GRP"         : Campo = "TG_MARCA"
                    Case Campo="TG_MARCA"       : Campo = "TG_REFERENCIA"
                    Case Campo="TG_REFERENCIA"  : Campo = "YES"
                  EndSwitch
          EndIf
   EndSwitch
EndIf

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc              
              
;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"

SYS_VALOR()
                
If Not IsAssigned(SYS_CHAPA_USUARIO)   Then SYS_CHAPA_USUARIO="9999"  EndIf
If Not IsAssigned(SYS_NIVEL_USUARIO)   Then SYS_NIVEL_USUARIO="S"     EndIf
If Not IsAssigned(SYS_NOME_USUARIO)    Then SYS_NOME_USUARIO=""       EndIf
If Not IsAssigned(SYS_CODIGO_CLIENTE)  Then SYS_CODIGO_CLIENTE=""     EndIf
If Not IsAssigned(SYS_CLIENTE_CONFEC)  Then SYS_CLIENTE_CONFEC="0000" EndIf

LimpAguarde()
ClearAll

VSDGEMPRESA  = ""
VSDGNOMEMP   = ""
VSDGFAMI     = ""
VSDGNOMFAMI  = ""
VSDGGRP      = ""
VSDGNOMGRP   = ""
VSDGMARCA    = ""
VSDGNOMMARCA = ""

While True

  ShowDialog "Rela‡„o de Pedidos\\Grade" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140,-68
    @ 01,07 Height 15 Width 72

    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA"    To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Familia"  For "TG_FAMI"
    Accept @ 03,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI" To VSDGFAMI                              
    Accept @ 03,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI                     

    Label  @ 04,00 "Grupo"  For "TG_GRP"
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_GRP" To VSDGGRP
    Accept @ 05,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 06,00 "Marca"  For "TG_MARCA"
    Accept @ 07,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 07,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 08,00 "Referˆncia"  For "TG_REFERENCIA"
    Accept @ 09,01 Width 33 "A20" Picture "!*!" Tag "TG_REFERENCIA"     To VSDGREFERENCIA
    
    Pushbutton @ 11,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 11,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog

  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf

  If IsBlank(VSDGEMPRESA)
     Then Mensagem("Informe uma Empresa !")
          Loop
  EndIf
  
  DISPOSITIVO()
  If OK="" Then Loop EndIf

  If IsEmpty("RPedidos")
     Then Mensagem("N„o h  pedidos listados na rela‡„o de pedidos!")
          Loop
  EndIf   

  AGUARDE("Aguarde, Checando Dados")
  
  Processa()  
  ImpPed()
  ImpriArq(ARQIMP)

  Delete Tabela
EndWhile
ClearAll
Release Vars All
Release Procs All
