;** Rm_0271 ********************************************************************
;*  Emissao dos Titulos Emitidos por Data de Emissao/Tp Pagto                  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 22/10/2010 por Bruno Carvalho
;Ultima Alteracao: 27/10/2010 por Bruno Carvalho 
;Motivo Alteracao: Ajustes     
;Ultima Alteracao: 06/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 26/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 31/01/2020 por Bruno Carvalho             
;Motivo Alteracao: Adicionado processo para escolher mais de uma forma de pagamento 

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc SELECIONA()
ClearAll
{Ask} {Duplic} Check
Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."
Moveto [Data de Emissao        ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
Switch
  Case ListaRegra_VSDGTPPAGTO_Ativo  : Moveto [Tipo do Pagamento] TypeIn ListaRegra_VSDGTPPAGTO
  Otherwise                          : Moveto [Tipo do Pagamento] TypeIn "~VSDGTPPAGTO.."
EndSwitch     
Do_It!
ClearAll

CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0200" "2" "Answer" "R"

EndProc

;*******************************************************************************
;* Rotina p/ processar Db temporaria                                           *
;*******************************************************************************
Proc Processa()

Coedit "Answer"
Scan
  If IsBlank([Valor da Comissao]) Then [Valor da Comissao]=0 EndIf
  If IsBlank([Saldo da Comissao]) Then [Saldo da Comissao]=0 EndIf
EndScan
Do_It!
ClearAll
EndProc   ; (Processa)

;*******************************************************************************
;* 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"] = -60 Or 
          Evento["KeyCode"] = "F2" : If Campo="TG_TPPAGTO"                      
                                        Then ListaRegra_F2() 
                                     EndIf     
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_DTINI"         : Campo="TG_EMPRESA" 
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_TPPAGTO"       : Campo="TG_DTFIM" 
            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_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_TPPAGTO"
                    Case Campo="TG_TPPAGTO"    : 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 =""
VSDGTPDOCTO =""
VSDGTPPAGTO =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()
VSDGOPRELANALSINT=""

ListaRegra_TGAtivado="[TG_TPPAGTO]" 

While True
  ShowDialog "T¡tulos Emitidos/Tp Pagto/*CARTOES*" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
    -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140 , -60, "F2"
    @ 05,12   Height 09 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 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 03,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 03,16 "at‚" For "TG_DTFIM"
    Accept @ 03,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 00,35 "Forma de Pagamento"  For "TG_TPPAGTO"
    Accept @ 01,38 Width 05 "A2"  Picture "!*!" Tag "TG_TPPAGTO"    To VSDGTPPAGTO
    Accept @ 01,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMTPPG"    To VSDGNOMTPPAGTO

    Pushbutton @ 05,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 05,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 VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Selecionando registros")
  SELECIONA()

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

  IMPRIREL("Answer","R")
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
