;** Rc_0020  *******************************************************************
;*  Relatorio de Destinacoes                                                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 15/01/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 10/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 20/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 19/05/2020 por Bruno Carvalho
;Motivo Alteracao: Alterado CopyReport "...\\Vendas\\Destin" p/ "...\\Vendas\\RM_0040"

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
If VSDGOPRELCODALF = "2"
   Then {Modify} {Sort} {Destin} {Answer} Down  "1" Do_It!
   Else {Modify} {Sort} {Destin} {Answer}       "1" Do_It!
EndIf

If VSDGCODMODELO="02"
   Then CopyReport "\\Base\\Sistemas\\Vendas\\RM_0040" "1" "Answer" "R"
   Else CopyReport "\\Base\\Sistemas\\Vendas\\RM_0040" "R" "Answer" "R"
EndIf
ClearAll
EndProc ; Ordem

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog1(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_OPRELCODALF" : Campo="NO"
            Case Campo="TG_CODMODELO"   : Campo="TG_OPRELCODALF"
            Case Campo="YES" Or Campo="NO" : Campo="TG_OPRELCODALF"
          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_OPRELCODALF" : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"   : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="": MSG_CAMPO=""
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Rela‡Æo")
ModeloRelatoriosAdd("02  Ficha Cadastral")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista


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

VSDGOPRELCODALF  =""

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Relat¢rio de Destina‡”es" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 06,12   Height 10 Width 72

    Label  @ 00,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 01,04 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Label  @ 03,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 04,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 04,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO  

    Pushbutton @ 06,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 06,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando relat¢rio")
  Seleciona()
  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  IMPRIREL("Answer","R")

  Delete "Answer"
EndWhile
ClearAll
Release Vars All
Release Procs All

