;** Rm_0100  *******************************************************************
;*  Relacao de Recebimentos                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/02/2004 por Anivel Augusto Rodrigues
;Ultima Alteracao: 29/11/2006 por Davi Carrano
;Motivo Alteracao: Mudan‡a Tabela Temporaria PrivDir()
;Motivo Alteracao: Aterar Posicao Analitico Sintetico
;Ultima Alteracao: 05/05/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: TOTALIZA EMPRESAS

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll

If IsTable("\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont")
  Then {Ask} TypeIn "\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont" Enter Check
       Moveto [Codigo da Empresa ] TypeIn "~VSDGEMPRESA2.."
       Moveto [Codigo da Conta   ] TypeIn "~VSDGCONTA.."
       Moveto [Tipo Movimento    ] TypeIn "E"
       Moveto [Data              ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
       Moveto [Codigo do EmitDest] TypeIn "~VSDGDESTINAT.."
       Moveto [Tipo do Lancamento] TypeIn "~VSDGTPLANC.."
       If IsBlank(VSDGTPOPER)
          Then Moveto [Tipo de Operacao  ] TypeIn "03 or 07 or 12"
          Else Moveto [Tipo de Operacao  ] TypeIn "~VSDGTPOPER.."
       EndIf
       Do_It!
       ClearAll
EndIf
EndProc   ;  (Seleciona)

;*******************************************************************************
;* ROTINA Ajusta Dados Empresa                                                 *
;*******************************************************************************
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"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_CONTA"         : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_TPLANC"        : Campo="TG_DESTINAT"
            Case Campo="TG_TPOPER"        : Campo="TG_TPLANC"
            Case Campo="TG_MODELOREL"     : Campo="TG_TPOPER"
            Case Campo="TG_DTINI"         : Campo="TG_MODELOREL"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            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_CONTA"
                    Case Campo="TG_CONTA"    : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT" : Campo="TG_TPLANC"
                    Case Campo="TG_TPLANC"   : Campo="TG_TPOPER"
                    Case Campo="TG_TPOPER"   : Campo="TG_MODELOREL"
                    Case Campo="TG_MODELOREL":
                        VSDGMODELOREL=ControlValue("TG_MODELOREL")
                        Switch
                          Case VSDGMODELOREL="2": VSDGNOMMODELOREL="EMIT/DESTIN"
                          Case VSDGMODELOREL="3": VSDGNOMMODELOREL="ANALITICO"
                          OtherWise:
                               VSDGMODELOREL="1"  VSDGNOMMODELOREL="SINTETICO"
                        EndSwitch
                        ClearImage
                        Campo="TG_DTINI"
										Case Campo="TG_DTINI"    : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"    : Campo="YES"
                   Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
	 Case Campo="TG_MODELOREL" :
       MSG_CAMPO="Modelo: 1=Sintetico 2=Soma p/ Emit/Destin 3=Analitico "
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA   =""
VSDGCONTA     =""
VSDGDESTINAT  =""
VSDGTPLANC    =""
VSDGDTINI     =BlankDate()
VSDGDTFIM     =BlankDate()
VSDGMODELOREL =""

While True
  ShowDialog "Posi‡„o dos Recebimentos Realizados" 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 19 Width 56

    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 "Conta"  For "TG_CONTA"
    Accept @ 03,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 03,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

    Label  @ 04,00 "Emitente"  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 "Tipo de Lan‡amento"  For "TG_TPLANC"
    Accept @ 7,01 Width 04 "A1"  Picture "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Z" Tag "TG_TPLANC" To VSDGTPLANC
    Accept @ 7,06 Width 23 "A20" Picture "!*!" Tag "TG_NOMLANC"  To VSDGNOMLANC

    Label  @ 08,00 "Tipo de Opera‡„o"  For "TG_TPOPER"
    Accept @ 9,01 Width 05 "A2"  Picture "!*!" Tag "TG_TPOPER" To VSDGTPOPER
    Accept @ 9,07 Width 23 "A20" Picture "!*!" Tag "TG_NOMOPER"  To VSDGNOMOPER

    Label  @ 10,00 "Modelo Relat˘rio" For "TG_MODELOREL"
    Accept @ 11,01 Width 04 "A1"   Picture "1,2,3" Tag "TG_MODELOREL" To VSDGMODELOREL
    Accept @ 11,06 Width 23 "A20"  Picture "!*!" Tag "TG_NOMMODELOREL" To VSDGNOMMODELOREL

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

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

  EndDialog
  If Not RetVal Then QuitLoop 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, 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

  Processa()

  Switch
   Case VSDGMODELOREL="2": CopyReport "MovCont" "6" Tabela "R"
   Case VSDGMODELOREL="1": CopyReport "MovCont" "1" Tabela "R"
   Case VSDGMODELOREL="3": CopyReport "MovCont" "7" Tabela "R"
 EndSwitch

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
