;** RM_0004A *******************************************************************
;*  Rela‡Æo de Cheques em cobran‡a - contas a receber                          *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 24/01/2020 por Anivel Augusto Rodrigues
;Ultima Alteracao: 24/01/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao novo processo concetrador RM_0004, substitudo do RM_0400, RM_0410, RM_0420   

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

If IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"ChequeC") And
   IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"ChequeI")
   Then 
       {Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"ChequeC" Enter Check
        if VSDGNCHT>0
           then Moveto [Numero do Lancamento] Example "NUM" TypeIn ", ~VSDGNCHT"
           else Moveto [Numero do Lancamento] Example "NUM" 
        endif
        Moveto [Codigo da Empresa       ] TypeIn "~VSDGEMPRESA2.."
        Moveto [Codigo                  ] TypeIn "~VSDGDESTINAT.." 
        Moveto [Codigo do Representante ] TypeIn "~VSDGREPRESEN.."
        Moveto [Numero_Carregamento_Orig] TypeIn "~VSDGNCARREG.."
        
        Moveto [Data de Entrada         ] Check
        Moveto [Data_Inclusao           ] Check

        {Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"ChequeI" Enter Check
        Moveto [Numero do Lancamento    ] Example "NUM"
        Moveto [Codigo da Conta         ] Typein "~VSDGCONTA.."
        Moveto [Situacao                ] TypeIn "EM COBRANCA"
        switch
          case VSDGOPDTCHVLI="1" : Moveto [Data Vencimento     ] TypeIn  ">=~VSDGDTINI ,<=~VSDGDTFIM" 
          case VSDGOPDTCHVLI="2" : Moveto [Data_Liquidado      ] TypeIn  ">=~VSDGDTINI ,<=~VSDGDTFIM" 
          case VSDGOPDTCHVLI="3" : Moveto [Data_Inclusao       ] TypeIn  ">=~VSDGDTINI ,<=~VSDGDTFIM" 
          case VSDGOPDTCHVLI="4" : Moveto [Data_Entrada        ] TypeIn  ">=~VSDGDTINI ,<=~VSDGDTFIM" 
        endswitch

        if not isblank(VSDGCPFCGCTIT)  then  Moveto [CPF           ] TypeIn VSDGCPFCGCTIT    endif
        if not isblank(VSDGNOMETIT)    then  Moveto [Titular_Cheque] TypeIn VSDGNOMETIT      endif
        if not isblank(VSDGNUMCHEQ)    then  Moveto [Numero_Cheque ] TypeIn VSDGNUMCHEQ      endif
        if VSDGVALOR>0                 then  Moveto [Valor         ] TypeIn VSDGVALOR        endif

        Do_It!
        ClearAll
EndIf
EndProc       ; (Seleciona)

;*******************************************************************************
;* Rotina para Processar  Registros                                            *
;*******************************************************************************
Proc RM_0004A_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 Principal                                                            *
;*******************************************************************************
Proc RM_0004A_Principal()

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
  RM_0004A_Seleciona()
  If Not IsTable("Answer") Then Loop EndIf
  If IsTable(Tabela)
     Then Add "Answer" Tabela
     Else Rename "Answer" Tabela
  EndIf
EndWhile

If not IsEmpty(Tabela)
   then
        RM_0004A_Processa()
        
       ;switch
       ;  case VSDGOPRELCODALFRANK2="2"  : Seta_Ordem_Report(Tabela,"8","Codigo do Item","Descricao do Item"  ,"")
       ;  case VSDGOPRELCODALFRANK2="3"  : Seta_Ordem_Report(Tabela,"8","Codigo do Item","Compras_Quantidade" ,"D")
       ;  case VSDGOPRELCODALFRANK2="4"  : Seta_Ordem_Report(Tabela,"8","Codigo do Item","Compras_Preco Total","D")
       ;endswitch

        switch
          case VSDGCODMODELO="27"  : CopyReport "\\Base\\Sistemas\\CheqRec\\Rm_0011" "6"  Tabela "R"  
          case VSDGCODMODELO="28"  : CopyReport "\\Base\\Sistemas\\CheqRec\\Rm_0012" "5"  Tabela "R"  
          case VSDGCODMODELO="29"  : CopyReport "\\Base\\Sistemas\\CheqRec\\Rm_0012" "11" Tabela "R"  
        endswitch
        IMPRIREL(Tabela,"R")
   else 
        MENSAGEM("N„o existem registros a processar")
EndIf

If IsTable(Tabela)   Then Delete Tabela   EndIf
If IsTable("Answer") Then Delete "Answer" EndIf

EndProc

;-- Chamada principal ----------------------------------------------------------
RM_0004A_Principal()

Release Vars Tabela
Release Procs RM_0004A_Principal, RM_0004A_Seleciona, RM_0004A_Processa
