;** GNRE ***********************************************************************
;*  Relacao de GNRE por Per¡odo                                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 20/01/2014 por Andrey Fillipe
;Ultima Alteracao: 18/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc Seleciona()
ClearAll

{Ask} TypeIn "\\Sistemas\\Estoque\\GNRE" Enter Check
Moveto [Codigo da Empresa] TypeIn "~VSDGEMPRESA.."
Moveto [Mes Referente    ] TypeIn "~MES.."
Moveto [Ano Referente    ] TypeIn "~ANO.."
Do_It!
ClearAll

EndProc   ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
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"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_MESANO"        : Campo="TG_EMPRESA" 
            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_MESANO"
                    Case Campo="TG_MESANO"   : Campo="YES"           
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_EMPRESA":
     MSG_CAMPO="Informe uma Empresa"
  Case Campo="":
     MSG_CAMPO=""
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()

VSDGEMPRESA = ""
VSDGMESANO  = ""

While True

  ShowDialog "Rela‡Æo de GNRE" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 05,05   Height 09 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 "Mˆs/Ano" For "TG_MESANO"
    Accept @ 03,01 Width 13 "A7"  Picture "##;.####" Tag "TG_MESANO" To VSDGMESANO
    
    Pushbutton @ 05,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 05,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 VSDGEMPRESA=""
     Then Mensagem("Empresa Invalida !")
          Loop
  EndIf

  If VSDGMESANO=""
     Then Mensagem("Mes/Ano Invalido !")
          Loop
  EndIf

  MES=Substr(VSDGMESANO,1,2)
  ANO=Substr(VSDGMESANO,4,4)
  If NumVal(MES) > 12 Or NumVal(MES) <= 0
     Then Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Delete "Answer"
          Loop
  EndIf

  CopyReport "\\Base\\Sistemas\\Estoque\\GNRE" "R" "Answer" "R"
  
  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All