;** Rm_0021  *******************************************************************
;*  Emissao de Cheques Por Cliente Por Vencimento                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 06/12/99 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/02/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Mudan‡a Tabela Temporaria PrivDir()
;Ultima Alteracao: 07/01/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Cheques em Cobranca
;Ultima Alteracao: 01/07/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes ShowDialog Op‡Æo Cheques Trocados
;Ultima Alteracao: 24/08/2012 po Kamila Gomes
;Motivo Alteracao: Ajustes Cheques Cobrancapgto
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog TG_DESTINAT

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

If IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"ChequeC") And
   IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"ChequeI")
   Then {Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"ChequeC" Enter Check
        Moveto [Numero do Lancamento] Example "NUM"
        Moveto [Codigo da Empresa   ] TypeIn "~VSDGEMPRESA.."
        Moveto [Codigo              ] TypeIn "~VSDGDESTINAT.."

				{Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"ChequeI" Enter Check
        Moveto [Numero do Lancamento] Example "NUM"

        Switch
          Case VSDGSITUACAO="1-EM ABERTO":
            Moveto [Situacao        ] TypeIn "Blank or \"EM ABERTO\""
          Case VSDGSITUACAO="TODAS":
            Moveto [Situacao        ] TypeIn ".."
          OtherWise:
            Moveto [Situacao        ] TypeIn RTrim(SubStr(VSDGSITUACAO,3,30))
        EndSwitch

        Moveto [Data Vencimento     ] 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_DTINI"         : Campo="TG_EMPRESA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_DESTINAT"      : Campo="TG_DTFIM"
            Case Campo="TG_SITUACAO"      : Campo="TG_DESTINAT"
            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_DESTINAT"
                    Case Campo="TG_DESTINAT": Campo="TG_SITUACAO"
                    Case Campo="TG_SITUACAO":
                         VSDGSITUACAO=ControlValue("TG_SITUACAO")
                         If IsBlank(VSDGSITUACAO)
                            Then VSDGSITUACAO="TODAS"
                         EndIf
                         Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

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

While True
  ShowDialog "Cheques por Cliente/Vencimento" 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 62

    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 1,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 1,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Periodo Referente" For "TG_DTINI"
    Label  @ 03,00 "de" For "TG_DTINI"
    Accept @ 03,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 03,17 "ate" For "TG_DTFIM"
    Accept @ 03,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 04,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 5,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 5,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    Label  @ 06,00 "Situa‡„o"  For "TG_SITUACAO"
    Label  @ 07,19 "1-EM ABERTO, 2-LIQUIDADO, 3-SEM FUNDOS"  For "TG_SITUACAO"
    Label  @ 08,19 "4-PRORROGADO, 5-EM COBRANCA, 6-TROCADO"  For "TG_SITUACAO"
    Label  @ 09,19 "7-COBRANCAPGTO"  For "TG_SITUACAO"
    Accept @ 7,01 Width 18 "A15"  Picture "1-EM ABERTO,2-LIQUIDADO,3-SEM FUNDOS,4-PRORROGADO,5-EM COBRANCA,6-TROCADO,7-COBRANCAPGTO" Tag "TG_SITUACAO" To VSDGSITUACAO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then 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\\Cheqrec\\Rm_0010" "9" Tabela "R"

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
