;;** Rm_0015  ******************************************************************
;*  Relacao das Notinhas de Vencimentos/Inclusao                               *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 11/03/2011 por Bruno Carvalho
;Ultima Alteracao: 15/04/2013 por Karina Andrade
;Motivo Alteracao: Inclusao op‡Æo de datas 
;Ultima Alteracao: 08/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 27/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog 
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog TG_DESTINAT  
;Ultima Alteracao: 30/04/2021 por Bruno Carvalho
;Motivo Alteracao: Alterado "TG_OPDT" para "TG_OPDTVENC"                 

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

If IsTable("\\Sistemas\\Ctapag\\"+Dir_Trab+"Titulos") And
   IsTable("\\Sistemas\\Ctapag\\"+Dir_Trab+"TitNota") 
   Then {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"Titulos" Enter 
        Moveto [Numero do Lancamento   ] Example "Nlanc"
        Moveto [Codigo da Empresa      ] Check TypeIn  "~VSDGEMPRESA.."
        Moveto [Nome Fantasia Empresa  ] Check
        Moveto [Codigo do Emitente     ] Check TypeIn  "~VSDGDESTINAT.."
        Moveto [Nome Fantasia EmitDest ] Check
        Moveto [Razao Social           ] Check         
        Moveto [Descricao do Lancamento] Check
        Moveto [Codigo da Conta        ] Check TypeIn  "~VSDGCONTA.."     
        Moveto [Descricao da Conta     ] Check                
        If VSDGOPDTVENC="V"
          Then Moveto [Data de Emissao        ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
        EndIf  
        {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"TitNota" Enter Check
        Moveto [Numero do Lancamento   ] Example "Nlanc"
        Moveto [Responsavel            ] TypeIn "as Descricao Tipo Pagamento"
        If VSDGOPDTVENC="I"
          Then Moveto [Data de Emissao        ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
        EndIf  
          
        Do_It!
        ClearAll  

        ;Procedimento para incluir o Numero do Documento de cada Lan‡amento no Relatorio 
        If IsTable("Answer")
           Then {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"Titulos" Enter 
                Moveto [Numero do Lancamento   ] Example "Nlanc"
                Moveto [Numero do Documento    ] Example "Ndoc"
                {Ask} TypeIn "Answer" Enter 
                Moveto [Numero do Lancamento   ] Example "Nlanc"
                Moveto [Descricao do Lancamento] TypeIn "Changeto " Example "Ndoc"
                Do_It!
                ClearAll  
        EndIf            
EndIf

EndProc  ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA=""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_CONTA"         : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_OPDTVENC"      : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"         : Campo="TG_OPDTVENC" 
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            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_CONTA"
                    Case Campo="TG_CONTA"    : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT" : Campo="TG_OPDTVENC"  
                    Case Campo="TG_OPDTVENC" : Campo="TG_DTINI"
                         VSDGOPDTVENC=ControlValue("TG_OPDTVENC")
                         Switch
                           Case VSDGOPDTVENC="1" : VSDGDESCOPDTVENC="VENCIMENTO"
                           Case VSDGOPDTVENC="2" : VSDGDESCOPDTVENC="INCLUSAO"
                           OtherWise: Campo="TG_OPDTVENC"
                         EndSwitch
                    Case Campo="TG_DTINI"    :  Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"    :  Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_OPDTVENC":
     MSG_CAMPO="Op‡„o:  1=VENCIMENTO  2=INCLUSAO"
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA = ""
VSDGCONTA   = ""
VSDGDTINI   = BlankDate()
VSDGDTFIM   = BlankDate()

While True
  ShowDialog "Relacao de Notinhas" 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 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_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 "Pessoa"  For "TG_DESTINAT"
    Accept @ 05,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST
    
    Label  @ 06,00 "Op‡äes de Datas" For "TG_OPDTVENC"
    Accept @ 07,04 Width 04 "A1"  Picture "1,2" Tag "TG_OPDTVENC" To VSDGOPDTVENC
    Accept @ 07,09 Width 25 "A20"  Picture "!*!" Tag "TG_DESCOPDTVENC" To VSDGDESCOPDTVENC    

    Label  @ 08,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 09,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 09,16 "at‚" For "TG_DTFIM"
    Accept @ 09,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    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(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando o Relat¢rio")
  Tabela=Cria_Temp(PrivDir())

  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    Seleciona()
    If Not IsTable("Answer") Then Loop EndIf
    If IsTable(Tabela)
       Then Add "Answer" Tabela
       Else Rename "Answer" Tabela
    EndIf
  EndWhile

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

  CopyReport "\\Base\\Sistemas\\CtaPag\\Rm_1001" "8" Tabela "R"

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
