;** Rm_2000  *******************************************************************
;* Inclusao de Titulos a Pagar por Usuario                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 29/01/2005 por Jose Luis Ameno da Silva
;Ultima Alteracao: 08/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 04/11/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes modelo impressÆo com plano de contas/centro de custo
;Ultima Alteracao: 05/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_NCONTROLE                   
;Ultima Alteracao: 23/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc SELECIONA()
ClearAll

If IsTable("\\Sistemas\\Ctapag\\"+Dir_Trab+"Titulos")
  Then {Ask} TypeIn "\\Sistemas\\Ctapag\\"+Dir_Trab+"Titulos" Enter Check
       Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."
       Moveto [Codigo_Usuario         ] TypeIn "~VSDGCHAPA.."
       Moveto [Numero_Controle_Dia    ] TypeIn "~VSDGNCONTROLE.."
       If IsBlank(VSDGNCONTROLE)
          Then Moveto [Data_Inclusao  ] TypeIn ">=~VSDGDTINI ,<=~VSDGDTFIM"
       EndIf
       Do_It!
       ClearAll
EndIf
EndProc  ; (Seleciona)

;*******************************************************************************
;* 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_NCONTROLE"     : Campo="TG_EMPRESA"
            Case Campo="TG_CHAPA"         : Campo="TG_NCONTROLE"
            Case Campo="TG_DTINI"         : Campo="TG_CHAPA"
            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_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_DTINI"
                    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 !"
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 Data InclusÆo/N§Controle/Titulos")
ModeloRelatoriosAdd("01B Por N§Controle/Data InclusÆo/Titulos")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA  =""
VSDGCHAPA    =""
VSDGNCONTROLE=""
VSDGDTINI    =BlankDate()
VSDGDTFIM    =BlankDate()

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Inclus„o/Titulos a Pagar - Usu rio" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 16 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 "Controle Dia" For "TG_NCONTROLE"
    Accept @ 03,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 03,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMNCONTROLE" To VSDGNOMNCONTROLE

    Label  @ 04,00 "Usu rio" For "TG_CHAPA"
    Accept @ 05,01 Width 07 "A4"  Picture "#*#" Tag "TG_CHAPA" To VSDGCHAPA
    Accept @ 05,09 Width 25 "A30" Picture "!*!" Tag "TG_CHAPA" To VSDGNOMCHAPA

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

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

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

  AGUARDE("Aguarde, processando")
  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

  Impressao_Orientacao="Paisagem"

  switch
    case VSDGCODMODELO="01"  : CopyReport "\\Base\\Sistemas\\CtaPag\\Rm_1000" "7" Tabela "R"
    case VSDGCODMODELO="01B" : CopyReport "\\Base\\Sistemas\\CtaPag\\Rm_1000" "8" Tabela "R"
  endswitch

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
rm_
