;** Rm_0400  *******************************************************************
;*  Emissao de Ordem de Pagamento                                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/07/2012 por Anivel Augusto Rodrigues
;Ultima Alteracao: 30/07/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Substituindo scriptïs Rm_0120, Rm_0130, Rm_0220

;*******************************************************************************
;* Rotina p/ Selecionar e Ordenar 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.."
       If IsBlank(VSDGNCONTROLE)
          Then Switch
                 Case VSDGOPRELCODALF="1" :  Moveto [Data_Inclusao     ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
                 Case VSDGOPRELCODALF="2" :  Moveto [Data de Vencimento] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
               EndSwitch  
               Moveto [Codigo da Conta     ] TypeIn "~VSDGCONTA.."
               Moveto [Codigo_Usuario      ] TypeIn "~VSDGCHAPA.."
               Moveto [Numero do Lancamento] TypeIn ">=~VSDGLANINI, <=~VSDGLANFIM"
               Moveto [Codigo do Emitente  ] TypeIn "~VSDGDESTINAT.."
          Else Moveto [Numero_Controle_Dia ] TypeIn "~VSDGNCONTROLE.."
       EndIf
       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_NCONTROLE"     : Campo="TG_EMPRESA"
            Case Campo="TG_LANINI"        : Campo="TG_NCONTROLE"
            Case Campo="TG_LANFIM"        : Campo="TG_LANINI"
            Case Campo="TG_CHAPA"         : Campo="TG_LANFIM"
            Case Campo="TG_CONTA"         : Campo="TG_CHAPA"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_DESTINAT" 
            Case Campo="TG_DTINI"         : Campo="TG_OPRELCODALF"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_MODREL"        : Campo="TG_NCONTROLE"
            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_NCONTROLE"
                    Case Campo="TG_NCONTROLE" :
                         If IsBlank(VSDGNCONTROLE)
                            Then Campo="TG_LANINI"
                            Else VSDGCHAPA      =""  VSDGNOMCHAPA      =""
                                 VSDGCONTA      =""  VSDGNOMCONTA      =""
                                 VSDGOPRELCODALF=""  VSDGNOMOPRELCODALF=""
                                 VSDGDTINI      =BlankDate()
                                 VSDGDTFIM      =BlankDate()
                                 VSDGDESTINAT   =""  VSDGNOMDEST    =""
                                 VSDGLANINI     =""  VSDGLANFIM     ="" 

                                 Campo="TG_MODREL"
                         EndIf
                    Case Campo="TG_LANINI"       : Campo="TG_LANFIM"
                         VSDGLANINI=ControlValue("TG_LANINI")
                         If IsBlank(VSDGLANINI)
                            Then VSDGLANINI="000001"
                            Else VSDGLANINI=ALINHM(VSDGLANINI,6)
                         EndIf
                    Case Campo="TG_LANFIM"       : Campo="TG_CHAPA"
                         VSDGLANFIM=ControlValue("TG_LANFIM")
                         If IsBlank(VSDGLANFIM)
                            Then VSDGLANFIM="999999"
                            Else VSDGLANFIM=ALINHM(VSDGLANFIM,6)
                         EndIf
                    Case Campo="TG_CHAPA"        : Campo="TG_CONTA"
                    Case Campo="TG_CONTA"        : Campo="TG_DESTINAT" 
                    Case Campo="TG_DESTINAT"     : Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF"  : Campo="TG_DTINI" 
                         VSDGOPRELCODALF=ControlValue("TG_OPRELCODALF")
                         If IsBlank(VSDGOPRELCODALF)
                            Then VSDGOPRELCODALF="1"
                         EndIf
                         Switch
                           Case VSDGOPRELCODALF="1" : VSDGNOMOPRELCODALF="INCLUS¶O"
                           Case VSDGOPRELCODALF="2" : VSDGNOMOPRELCODALF="VENCIMENTO"
                         EndSwitch       
                    Case Campo="TG_DTINI"     : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"     : Campo="TG_MODREL"
                    Case Campo="TG_MODREL"    : Campo="YES"
                         VSDGMODREL=ControlValue("TG_MODREL")
                         Switch
                           Case VSDGMODREL="1" : VSDGNOMMODREL="MODELO 1"
                           Case VSDGMODREL="2" : VSDGNOMMODREL="MODELO 2"
                         EndSwitch       
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_LANINI"      : MSG_CAMPO="Informe o Numero do Lancamento Inicial"
  Case Campo="TG_LANFIM"      : MSG_CAMPO="Informe o Numero do Lancamento Final"
  Case Campo="TG_OPRELCODALF" : MSG_CAMPO="1=InclusÆo  2=Vencimento"
  Case Campo="TG_MODREL"      : MSG_CAMPO="1=Modelo 1  2=Modelo 2"
EndSwitch  

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA  =""
VSDGNCONTROLE=""
VSDGCHAPA    =""
VSDGOPRELCODALF=""
VSDGCONTA    =""
VSDGDESTINAT=""
VSDGDTINI    =BlankDate()
VSDGDTFIM    =BlankDate()
VSDGMODREL   ="1"
VSDGLANINI   =""  
VSDGLANFIM   ="" 

While True
  ShowDialog "Emiss„o de Ordem de Pagamento" 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 19 Width 78
   
    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 01,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "N§ Controle Dia" For "TG_NCONTROLE"
    Accept @ 03,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 03,11 Width 31 "A30" Picture "!*!" Tag "TG_NOMNCONTROLE" To VSDGNOMNCONTROLE

    Label  @ 02,43 "Lan‡amento" For "TG_LANINI"
    Label  @ 03,43 "de" For "TG_LANINI"
    Accept @ 03,47 Width 9 "A6"  Picture "#*#" Tag "TG_LANINI" To VSDGLANINI
    Label  @ 03,56 "at‚" For "TG_LANFIM"
    Accept @ 03,61 Width 9 "A6"  Picture "#*#" Tag "TG_LANFIM" To VSDGLANFIM

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

    Label  @ 06,00 "Conta"  For "TG_CONTA"
    Accept @ 07,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 07,09 Width 33 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

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

    Label  @ 10,00 "Por Data de" For "TG_OPRELCODALF"
    Accept @ 11,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 11,06 Width 28 "A20" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Label  @ 10,38 "Periodo Referente" For "TG_DTINI"
    Label  @ 11,38 "de" For "TG_DTINI"
    Accept @ 11,42 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 11,55 "ate" For "TG_DTFIM"
    Accept @ 11,60 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 12,00 "Modelo do Relat¢rio" For "TG_MODREL"
    Accept @ 13,01 Width 04 "A1"  Picture "1,2" Tag "TG_MODREL" To VSDGMODREL
    Accept @ 13,06 Width 28 "A25"  Picture "!*!" Tag "TG_NOMMODREL" To VSDGNOMMODREL

    Pushbutton @ 15,24 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 15,38 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If IsBlank(VSDGNCONTROLE) And 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

  Switch
    Case VSDGMODREL="1": CopyReport "\\Base\\Sistemas\\CtaPag\\Rm_1000" "1"  Tabela "R"
    Case VSDGMODREL="2": CopyReport "\\Base\\Sistemas\\CtaRec\\Rm_1000" "R"  Tabela "R"
  EndSwitch

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
