;** Rm_0071 ********************************************************************
;*  Emissao dos Titulos Recebidos por Tipo de Carteira/Cliente                 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/03/2004 por Karen Lauar Nery
;Ultima Alteracao: 13/01/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: TOTALIZA EMPRESAS
;Ultima Alteracao: 06/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 17/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_EMPRESATE                 
;Ultima Alteracao: 26/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog 
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog TG_DESTINAT                  
;Ultima Alteracao: 31/01/2020 por Bruno Carvalho             
;Motivo Alteracao: Adicionado processo para escolher mais de um tipo de carteira

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc SELECIONA()
ClearAll
If IsTable("\\Sistemas\\Ctarec\\"+Dir_Trab+"Duplic") And
   IsTable("\\Sistemas\\Ctarec\\"+Dir_Trab+"DupBaixa")
   Then {Ask} TypeIn "\\Sistemas\\Ctarec\\"+Dir_Trab+"DupliC" Enter Check
        Moveto [Numero do Lancamento  ] Example "lanc"
        Moveto [Codigo da Empresa     ] TypeIn "~VSDGEMPRESA2.."
        Moveto [Codigo do Destinatario] TypeIn "~VSDGDESTINAT.."
        Switch                                                                                                                            
          Case ListaRegra_VSDGTPCART_Ativo  : Moveto [Tipo do Lancamento] TypeIn ListaRegra_VSDGTPCART
          Otherwise                         : Moveto [Tipo do Lancamento] TypeIn "~VSDGTPCART.."
        EndSwitch
        {Ask} TypeIn "\\Sistemas\\Ctarec\\"+Dir_Trab+"DupBaixa" Enter Check
        Moveto [Numero do Lancamento] Example "lanc"
        Moveto [Data do Pagamento   ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
        Moveto [Tipo da Baixa       ] TypeIn "Blank or NORMAL"
        
        Do_It!
        ClearAll
EndIf

EndProc    ; (Seleciona)

;*******************************************************************************
;* Processa                                                                    *
;*******************************************************************************
Proc Processa()

;***** Ajusta Dados ************************************
If VSDGEMPRESA="0000"
   Then {Ask} TypeIn Tabela Enter TypeIn "Fast"
        Moveto [Codigo da Empresa      ] TypeIn "changeto 0000"
        Moveto [Nome Fantasia Empresa  ] TypeIn "changeto TOTALIZA EMPRESAS"
        Do_It!
        ClearAll
EndIf

EndProc

;*******************************************************************************
;* 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_TPCART"                      
                                        Then ListaRegra_F2() 
                                     EndIf     
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESATE"       : Campo="NO"
            Case Campo="TG_DESTINAT"      : Campo="TG_EMPRESATE"
            Case Campo="TG_DTINI"         : Campo="TG_DESTINAT"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_TPCART"        : Campo="TG_DTFIM"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESATE"
          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_EMPRESATE"    : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT"   : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_TPCART"
                    Case Campo="TG_TPCART"     : 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   =""
VSDGDESTINAT   =""
VSDGTPCART    =""
VSDGDDPROTESTO=""
VSDGDTINI  =BlankDate()
VSDGDTFIM  =BlankDate()

ListaRegra_TGAtivado="[TG_TPCART]"

While True
  ShowDialog "Recebidos por Tipo de Carteira/Clientes" 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 11 Width 72

    Label  @ 00,00 "Empresa"  For "TG_EMPRESATE"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESATE" To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP   
    
    Label  @ 02,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCLI" To VSDGNOMDEST 
                           
    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

    Label  @ 00,35 "Tipo de Carteira"  For "TG_TPCART"
    Accept @ 01,39 Width 04 "A1"  Picture "!" Tag "TG_TPCART"  To VSDGTPCART
    Accept @ 01,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMCART" To VSDGNOMCART

    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 VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  If VSDGEMPRESA="0000"
     Then VSDGEMPRESA2=""
     Else VSDGEMPRESA2=VSDGEMPRESA
  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

  Processa()

  CopyReport "\\Base\\Sistemas\\CtaRec\\Rm_1010a" "6" Tabela "R"

  IMPRIREL(Tabela,"R")

  Delete Tabela
                          
EndWhile
ClearAll
Release Vars All
Release Procs All
