;** RM_0020  *******************************************************************
;*  Emissao dos Titulos a Pagar por Data de Vencimento                         *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 12/01/2021 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                                         
;Motivo Alteracao: 

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA=""
MSG_CAMPO=""

If Disparo="OPEN" Or Disparo="UPDATE" 
   Then If Campo="TG_OPCHEQ" 
            Then  if VSDGOPCHEQ=1 or
                     VSDGOPCHEQ=3
                     then 
                          wcol=35
                          wlin=10
                          CampoAnterior="TG_OPCHEQ"
                     else ;inverte ao que esta no evento 13
                          wcol=80
                          wlin=6
                          CampoAnterior="TG_OPCHEQ"
                          
                  endif   
                 refazershowdialog=true
                 AcceptDialog
       Endif
EndIf

If Disparo="OPEN"  
   Then AoCriarShowDialog()
        TiraSombraShowDialog()

        If refazershowdialog 
           Then Campo=CampoAnterior 
                refazershowdialog=false 
        EndIf  
EndIf

If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] = -60 Or 
          Evento["KeyCode"] = "F2" : If Campo="TG_TPLANC" Or Campo="TG_TPPAGTO"                     
                                        Then ListaRegra_F2() 
                                     EndIf     
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESATE"     : Campo="NO"
            Case Campo="TG_CONTA"         : Campo="TG_EMPRESATE"
            Case Campo="TG_TPLANC"        : Campo="TG_CONTA"
            Case Campo="TG_TPPAGTO"       : Campo="TG_TPLANC"
            Case Campo="TG_DESTINAT"      : Campo="TG_TPPAGTO"
            Case Campo="TG_ATIVIDADE"     : Campo="TG_DESTINAT"
            Case Campo="TG_OPDTCP"        : Campo="TG_ATIVIDADE"
            Case Campo="TG_DTINI"         : Campo="TG_OPDTCP"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_OPCHEQ"        : Campo="TG_DTFIM"
            Case Campo="TG_OPCHPRE"       : Campo="TG_OPCHEQ"
            Case Campo="TG_OPCOES"        : Campo="TG_OPCHEQ"
            Case Campo="TG_CODMODELO"     : Campo="TG_OPCHEQ"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESATE"
          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_EMPRESATE"   : Campo="TG_CONTA"
                    Case Campo="TG_CONTA"       : Campo="TG_TPLANC"
                    Case Campo="TG_TPLANC"      : Campo="TG_TPPAGTO"
                    Case Campo="TG_TPPAGTO"     : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT"    : Campo="TG_ATIVIDADE"
                    Case Campo="TG_ATIVIDADE"   : Campo="TG_OPDTCP"
                    Case Campo="TG_OPDTCP"      : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"       : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"       : Campo="TG_OPCHEQ"
                    Case Campo="TG_OPCHEQ"      : 
                      if VSDGOPCHEQ=1 or
                         VSDGOPCHEQ=3
                         then 
                              wcol=80
                              wlin=6
                              CampoAnterior="TG_OPCOES"
                         else 
                              wcol=35
                              wlin=10
                              CampoAnterior="TG_OPCHPRE"
                      endif   
                      refazershowdialog=true
                      AcceptDialog
                      
                    Case Campo="TG_OPCHPRE"     : Campo="TG_OPCOES" 
                    
                    Case Campo="TG_OPCOES"      : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"   : Campo="YES"
                    
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
Case Campo="TG_OPCHEQ"  or Campo="TG_OPCHPRE":
     MensagemRadioButtons()
Case Campo="TG_OPCOES":
     MensagemCheckBoxes()
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  Por Vencimento")
ModeloRelatoriosAdd("02  Por Conta/Vencimento")
ModeloRelatoriosAdd("03  Por Pessoa/Vencimento")
ModeloRelatoriosAdd("25  Por Tipo Lan‡amento/Conta/Vencimento")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("17  Por Entrada")
ModeloRelatoriosAdd("17B Por Pessoa/Entrada")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("35A Por Pessoa/Vencimento")
ModeloRelatoriosAdd("35B Por Pessoa/Vencimento + Observa‡äes")
ModeloRelatoriosAdd("35C Por Pessoa/Vencimento + Saldo Anterior")
ModeloRelatoriosAdd("Fim")              
                           
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA =""
VSDGCONTA   =""
VSDGTPLANC  =""
VSDGTPPAGTO =""
VSDGOPDTCP  =""
VSDGATIVIDADE =""
VSDGDESTINAT=""

VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()

Array VSDGOPCAO[2]
VSDGOPCAO[1]=true 
VSDGOPCAO[2]=true                                                 

refazershowdialog=false
wcol             =35
wlin             =10

ModeloRelatoriosCarregaLista()      

ListaRegra_TGAtivado="[TG_TPLANC],[TG_TPPAGTO]"

While True

  ShowDialog "T¡tulos … Pagar por Vencimento,Conta,Pessoa.." Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE","UPDATE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140, -60, "F2"  
    @ 01,00 Height 22 Width 80

    Label  @ 00,00 "Empresa"  For "TG_EMPRESATE"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESATE" To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP
    
    Label  @ 02,00 "Conta"  For "TG_CONTA"
    Accept @ 03,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

    Label  @ 04,00 "Tipo de Lan‡amento"  For "TG_TPLANC"
    Accept @ 05,04 Width 04 "A1"  Picture "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Z" Tag "TG_TPLANC" To VSDGTPLANC
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMLANC"  To VSDGNOMLANC

    Label  @ 06,00 "Forma de Pagamento"  For "TG_TPPAGTO"
    Accept @ 07,03 Width 05 "A2"  Picture "!*!" Tag "TG_TPPAGTO"    To VSDGTPPAGTO
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMTPPG"    To VSDGNOMTPPAGTO

    Label  @ 08,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 09,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 09,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    Label  @ 10,00 "Atividade"  For "TG_ATIVIDADE"
    Accept @ 11,01 Width 07 "A4"  Picture "!*!" Tag "TG_ATIVIDADE" To VSDGATIVIDADE
    Accept @ 11,09 Width 25 "A30"  Picture "#*#" Tag "TG_NOMATIV" To VSDGNOMATIV

    Label  @ 12,00 "Op‡äes de Datas" For "TG_OPDTCP"
    Accept @ 13,04 Width 04 "A1"  Picture "1,2,3,4,5,6" Tag "TG_OPDTCP" To VSDGOPDTCP
    Accept @ 13,09 Width 25 "A20"  Picture "!*!" Tag "TG_NOMOPDTCP" To VSDGNOMOPDTCP
    
    Label  @ 14,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 15,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 15,16 "at‚" For "TG_DTFIM"
    Accept @ 15,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
    
    Label @ 00,35 "Cheques nÆo apresentados" For "TG_OPCHEQ"
    RadioButtons @ 01,35 Height 4 Width 34
      "~1~ NÆo incluir",
      "~2~ Incluir todos",
      "~3~ Incluir sem os Pr‚-Datados",
      "~4~ Incluir s¢  os Pr‚-Datados"
        Tag "TG_OPCHEQ"
        To VSDGOPCHEQ

    Label @ 06,wcol "Cheques Pr‚-Datados" For "TG_OPCHPRE"
    RadioButtons @ 07,wcol Height 2 Width 34
      "~1~ S¢ do per¡odo informado",
      "~2~ Incluir os nÆo apresentados"
        Tag "TG_OPCHPRE"
        To VSDGOPCHPRE

    Label  @ wlin,35 "Op‡”es de Dados" For "TG_OPCOES"
    CheckBoxes @ wlin+1,35 Height 4 Width 33 Tag "TG_OPCOES"
    "Incluir Ordem de Compra   " to VSDGOPCAO[1],
    "Incluir T¡tulos de Cr‚dito" to VSDGOPCAO[2]

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

    Pushbutton @ 18,54 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 18,66 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf
  
  if refazershowdialog then loop endif
  if not ValidarModelosRelatorios() then loop endif         

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  If VSDGEMPRESA="0000"
     Then VSDGEMPRESA2=""
     Else VSDGEMPRESA2=VSDGEMPRESA
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf
  
  Switch
    
    Case VSDGCODMODELO="35A" Or
         VSDGCODMODELO="35B" Or
         VSDGCODMODELO="35C"    : Play "RM_0020C"   ;RM_2011
    OtherWise                   : Play "RM_0020A"   ;RM_0020     
  EndSwitch
EndWhile
ClearAll
Release Vars All
Release Procs All