;** Rm_0277 ********************************************************************
;*  Emissao dos Titulos gerados por Data de Operacao                           *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 02/07/2003 por Anivel Augusto Rodrigues
;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: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog modelo relatorio  
;Ultima Alteracao: 31/12/2020 por Bruno Carvalho
;Motivo Alteracao: Ajustes p/ chamar filtro padrao *RM_2000 

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

If IsTable("\\Sistemas\\Ctarec\\"+Dir_Trab+"Duplic")
   Then {Ask} TypeIn "\\Sistemas\\Ctarec\\"+Dir_Trab+"DupliC" Enter Check
        Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."
        Moveto [Tipo do Documento      ] TypeIn "~VSDGTPDOCTO.."
        Moveto [Codigo_Usuario         ] TypeIn "~VSDGCHAPA.."
        Moveto [Numero_Controle_Dia    ] TypeIn "~VSDGNCONTROLE.."
        Switch
          Case VSDGOPDT="1" :
               Moveto [Data de Emissao] TypeIn ">=~VSDGDTINI ,<=~VSDGDTFIM"
          Case VSDGOPDT="2" :
               Moveto [Data de Entrada] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"       
          Case VSDGOPDT="3" :
               Moveto [Data_Inclusao  ] TypeIn ">=~VSDGDTINI ,<=~VSDGDTFIM"
        EndSwitch                
        Do_It!
        ClearAll
EndIf

EndProc ;RM_0277A_Seleciona()

;*******************************************************************************
;* Rotina p/ processar Db temporaria                                           *
;*******************************************************************************
Proc RM_0277A_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   ; RM_0277A_Processa

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AGUARDE("Aguarde, gerando o relatĒrio")
While True
  Tabela=Cria_Temp(PrivDir())
  
  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    RM_0277A_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("No existem registros a processar")
          Delete Tabela
          QuitLoop
  EndIf
  Rename Tabela "Answer"
  RM_0277A_Processa()

  Switch
    Case VSDGCODMODELO="47A"  : CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0200" "11" "Answer" "R"
    Case VSDGCODMODELO="47B"  : CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0200" "12" "Answer" "R"
  Endswitch
  IMPRIREL("Answer","R")

  Delete "Answer"
  QuitLoop
EndWhile
ClearAll

Release Vars RM_0277A_Seleciona,RM_0277A_Processa            