;** Rm_0160 *******************************************************************
;*  Relacao de Alteracao de Conta                                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/02/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Mudan‡a Tabela Temporaria PrivDir()
;Ultima Alteracao: 08/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 23/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 28/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 06/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll
If IsTable("\\Sistemas\\Ctapag\\"+Dir_Trab+"AltContC") And
   IsTable("\\Sistemas\\Ctapag\\"+Dir_Trab+"AltContI")
   Then {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"AltContC" Enter Check
        Moveto [Numero do Lote     ] Example "nl"
        {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"AltContI" Enter Check
        Moveto [Numero do Lote     ] Example "nl" TypeIn ", ~VSDGNLACPG.."
        Moveto [Codigo da Empresa  ] TypeIn "~VSDGEMPRESA.."
        Moveto [Data da Operacao   ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
        Do_It!
        ClearAll
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_NLACPG"        : Campo="TG_EMPRESA"
            Case Campo="TG_DTINI"         : Campo="TG_NLACPG"
            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_NLACPG"
                    Case Campo="TG_NLACPG" : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"  : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  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=""
VSDGDTINI  =BlankDate()
VSDGDTFIM  =BlankDate()
VSDGNLACPG =BlankNum()

While True

  ShowDialog "Relat˘rio de Documentos c/ Altera‡„o de Conta" 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 11 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 "Lote" For "TG_NLACPG"
    Accept @ 03,01 Width 09 "S" Picture "#*#" Tag "TG_NLACPG" To VSDGNLACPG
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMNLACPG" To VSDGNOMNLACPG

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

    Pushbutton @ 07,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 07,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

  If VSDGNLACPG = 0
     Then VSDGNLACPG = BlankNum()
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Processando Dados")
  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_1300" "R" Tabela "R"

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All

