;** 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
;Ultima Alteracao: 03/09/2014 por Andrey Fillipe
;Motivo Alteracao: Adicionado filtro Op‡ao de data
;Ultima Alteracao: 16/05/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Layout Showdialog
;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: 28/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog.                   
;Ultima Alteracao: 11/08/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes c˘cigos modelo de relatorios
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()
;Ultima Alteracao: 03/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Showdialog                       

;*******************************************************************************
;* 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"
        If VSDGOPDTEMISCOMP = "1"
           Then Moveto [Data Competencia] Check
                Moveto [Data            ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
           Else Moveto [Data            ] Check
                Moveto [Data Competencia] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM, as Data"
        EndIf   
        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 PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Agrupado por Tipo de Lan‡amento/Opera‡Ćo/Destinat rio/Dia")
ModeloRelatoriosAdd("02  Agrupado por Tipo de Lan‡amento/Opera‡Ćo/Dia")
ModeloRelatoriosAdd("03  Agrupado por Dia")
ModeloRelatoriosAdd("Fim")

EndProc ;ModeloRelatoriosCarregaLista

;*******************************************************************************
;* 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_EMPRESATE"       : Campo="NO"
            Case Campo="TG_CONTA"         : Campo="TG_EMPRESATE"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_TPOPER"        : Campo="TG_DESTINAT"
            Case Campo="TG_TPLANC"        : Campo="TG_TPOPER"
            Case campo="TG_OPDTEMISCOMP"  : Campo="TG_TPLANC"
            Case Campo="TG_DTINI"         : Campo="TG_OPDTEMISCOMP"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_CODMODELO"     : 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_CONTA"
                    Case Campo="TG_CONTA"    : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT" : Campo="TG_TPOPER"
                    Case Campo="TG_TPOPER"   : Campo="TG_TPLANC"
                    Case Campo="TG_TPLANC"   : Campo="TG_OPDTEMISCOMP"
                    Case Campo="TG_OPDTEMISCOMP" : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"    : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"    : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO": 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   = ""
VSDGCONTA     = ""
VSDGDESTINAT  = ""
VSDGTPLANC    = ""
VSDGTPOPER    = ""

VSDGDTINI     = BlankDate()
VSDGDTFIM     = BlankDate()
VSDGOPDTEMISCOMP   =""
VSDGNOMOPDTEMISCOMP=""

ModeloRelatoriosCarregaLista()

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

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

    Label  @ 06,00 "Tipo de Opera‡„o"  For "TG_TPOPER"
    Accept @ 07,03 Width 05 "A2"  Picture "!*!" Tag "TG_TPOPER" To VSDGTPOPER
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMOPER"  To VSDGNOMOPER

    Label  @ 08,00 "Tipo de Lan‡amento"  For "TG_TPLANC"
    Accept @ 09,04 Width 04 "A1"  Picture "!*!" Tag "TG_TPLANC" To VSDGTPLANC
    Accept @ 09,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMLANC"  To VSDGNOMLANC

    Label  @ 00,35 "Op‡äes de Datas" For "TG_OPDTEMISCOMP"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPDTEMISCOMP" To VSDGOPDTEMISCOMP
    Accept @ 01,44 Width 25 "A20"  Picture "!*!" Tag "TG_NOMOPDTEMISCOMP" To VSDGNOMOPDTEMISCOMP

    Label  @ 02,35 "Perˇodo Referente de" For "TG_DTINI"
    Accept @ 03,38 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 03,51 "at‚" For "TG_DTFIM"
    Accept @ 03,56 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 11,00  "Modelo de ~R~elat˘rio"  For "TG_CODMODELO"
    Accept @ 12,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 12,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO        

    Pushbutton @ 14,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 14,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 not ValidarModelosRelatorios() 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, 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 VSDGCODMODELO="02": CopyReport "MovCont" "6" Tabela "R"
   Case VSDGCODMODELO="01": CopyReport "MovCont" "1" Tabela "R"
   Case VSDGCODMODELO="03": CopyReport "MovCont" "7" Tabela "R"
 EndSwitch

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
