;** Rm_2000 ********************************************************************
;*  Inclusao de Titulos a Receber                                              *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 31/12/2020 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                          
;Motivo Alteracao:

;*******************************************************************************
;* 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_TPDOCTO"       : Campo="TG_EMPRESA"
            Case Campo="TG_NCONTROLE"     : Campo="TG_TPDOCTO"
            Case Campo="TG_CHAPA"         : Campo="TG_NCONTROLE"
            Case Campo="TG_OPDT"          : Campo="TG_CHAPA"
            Case Campo="TG_DTINI"         : Campo="TG_OPDT"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_CODMODELO"     : Campo="TG_NCONTROLE"
            Case Campo="YES" Or Campo="NO": Campo="TG_NCONTROLE"
          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_TPDOCTO"
                    Case Campo="TG_TPDOCTO"   : Campo="TG_NCONTROLE"
                    Case Campo="TG_NCONTROLE" :
                         If IsBlank(VSDGNCONTROLE)
                            Then Campo="TG_CHAPA"
                            Else VSDGCHAPA    =""
                                 VSDGNOMCHAPA =""
                                 VSDGDTINI    =BlankDate()
                                 VSDGDTFIM    =BlankDate()

                                 Campo="TG_CODMODELO"
                         EndIf
                    Case Campo="TG_CHAPA"     : Campo="TG_OPDT"
                    Case Campo="TG_OPDT"      : Campo="TG_DTINI"
                         VSDGOPDT=ControlValue("TG_OPDT")
                         Switch
                           Case VSDGOPDT="2": VSDGDESCOPDT="DATA DE ENTRADA"
                           Case VSDGOPDT="3": VSDGDESCOPDT="DATA DE INCLUSAO"
                           OtherWise        : VSDGOPDT="1"
                                              VSDGDESCOPDT="DATA DE EMISSAO"
                         EndSwitch
                    Case Campo="TG_DTINI"     : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"     : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_CHAPA":
     MSG_CAMPO="Informe um codigo de usuario !"
  Case Campo="TG_OPDT":
       MSG_CAMPO="Op‡„o: 1= Emiss„o  2=Entrada  3= Inclusao"   
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("60A Por Data InclusÆo/N§Controle/Titulos")
ModeloRelatoriosAdd("60B Por N§Controle/Data InclusÆo/Titulos")
ModeloRelatoriosAdd("47A Por Data Entrada/Titulos")
ModeloRelatoriosAdd("47B Por Data Entrada - Sint‚tico")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA    = ""
VSDGTPDOCTO    = ""
VSDGNOMTPDOCTO = ""
VSDGCHAPA      = ""
VSDGNCONTROLE  = ""
VSDGOPDT       = ""
VSDGDESCOPDT   = ""
VSDGDTINI      = BlankDate()
VSDGDTFIM      = BlankDate()

ModeloRelatoriosCarregaLista()                                    

While True                                           
  ShowDialog "T¡tulos Gerados por Data Opera‡„o/Tipo Docto" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 20 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_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Tipo do Documento"  For "TG_TPDOCTO"
    Accept @ 03,01 Width 07 "A4"  Picture "!*!" Tag "TG_TPDOCTO" To VSDGTPDOCTO
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMTPDOCTO"  To VSDGNOMTPDOCTO
    
    Label  @ 04,00 "Controle Dia" For "TG_NCONTROLE"
    Accept @ 05,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 05,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMNCONTROLE" To VSDGNOMNCONTROLE

    Label  @ 06,00 "Usu rio" For "TG_CHAPA"
    Accept @ 07,01 Width 07 "A4"  Picture "#*#" Tag "TG_CHAPA" To VSDGCHAPA
    Accept @ 07,09 Width 25 "A30" Picture "!*!" Tag "TG_CHAPA" To VSDGNOMCHAPA
    
    Label  @ 08,00 "Op‡„o de Datas" For "TG_OPDT"
    Accept @ 09,04 Width 04 "A1"  Picture "1,2,3" Tag "TG_OPDT" To VSDGOPDT
    Accept @ 09,09 Width 25 "A20"  Picture "!*!" Tag "TG_DESCOPDT" To VSDGDESCOPDT
    
    Label  @ 10,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 11,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 11,16 "at‚" For "TG_DTFIM"
    Accept @ 11,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

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

    Pushbutton @ 16,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 16,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 VSDGDTFIM=BlankDate() And IsBlank(VSDGNCONTROLE)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  Switch
    case VSDGCODMODELO="60A" Or
         VSDGCODMODELO="60B"  : Play "RM_2000A"
    case VSDGCODMODELO="47A" Or
         VSDGCODMODELO="47B"  : Play "RM_0277A" 
  Endswitch
EndWhile
ClearAll
Release Vars All
Release Procs All