;** Rm_0200 *******************************************************************
;*  Analitico  p/ Plano de Contas                                             *
;******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/04/2018 por Anivel Augusto Rodrigues
;Ultima Alteracao: 30/04/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao novo processo concetrador            
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()

;*******************************************************************************
;* 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_PLCONTAS"      : Campo="TG_CONTA"
            Case Campo="TG_DESTINAT"      : Campo="TG_PLCONTAS"
            Case Campo="TG_OPDTEMISCOMP"  : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"         : Campo="TG_OPDTEMISCOMP"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_DESP"          : Campo="TG_DTFIM"
            Case Campo="TG_CODMODELO"     : Campo="TG_DESP"
            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_PLCONTAS"
                    Case Campo="TG_PLCONTAS"     : Campo="TG_DESTINAT"
                         If VSDGPLCONTAS=""
                            Then VSDGDESP    = ""
                                 VSDGNOMDESP = "TODAS"    
                         EndIf   
                    Case Campo="TG_DESTINAT"     : Campo="TG_OPDTEMISCOMP"
                    Case Campo="TG_OPDTEMISCOMP" : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"        : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"        : Campo="TG_DESP"
                    Case Campo="TG_DESP"         : Campo="TG_CODMODELO"
                         VSDGDESP = ControlValue("TG_DESP")
                         Switch
                            Case VSDGDESP = "F": VSDGNOMDESP = "FIXA"
                            Case VSDGDESP = "V": VSDGNOMDESP = "VARIAVEL"
                            OtherWise          : VSDGDESP    = ""
                                                 VSDGNOMDESP = "TODAS"    
                         EndSwitch                  
                    Case Campo="TG_CODMODELO"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DESP":
       MSG_CAMPO="Op‡äes: F=Fixa  V=Vari vel  Em Branco= Todas"
  Case Campo="TG_DTINI":
       MSG_CAMPO="Informe a Data Inicial"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Simples")
ModeloRelatoriosAdd("03  Detalhado")
ModeloRelatoriosAdd("02  Agrupado por Emitente/Destinat rio")
ModeloRelatoriosAdd("04  Agrupado por Emitente/Destinat rio e Mˆs/Ano")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("01C Agrupado por Conta/Mˆs/Ano")
ModeloRelatoriosAdd("03C Agrupado por Conta/Dia/Mˆs/Ano")
ModeloRelatoriosAdd("02C Agrupado por Conta/Emitente/Destinat rio")
ModeloRelatoriosAdd("04C Agrupado por Conta/Emitente/Destinat rio e Mˆs/Ano")
ModeloRelatoriosAdd("Fim")

EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA     =""
VSDGCONTA       =""
VSDGNOMPLCONTAS =""
VSDGDESTINAT    =""
VSDGDESP        =""
VSDGNOMDESP     =""
VSDGDTINI       =BlankDate()
VSDGDTFIM       =BlankDate()
VSDGOPDTEMISCOMP   =""
VSDGNOMOPDTEMISCOMP=""

ModeloRelatoriosCarregaLista()

While True
  ShowDialog "Anal¡tico p/ Plano de Contas" 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 17 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 "Plano de Contas" For "TG_PLCONTAS"
    Accept @ 05,01 Width 33 "A13"  Picture "!*!" Tag "TG_PLCONTAS" To VSDGPLCONTAS
    Accept @ 06,01 Width 33 "A40" Picture "!*!" Tag "TG_NOMPLCONTAS"  To VSDGNOMPLCONTAS
    
    Label  @ 07,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 08,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 08,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST
                              
    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  @ 04,35 "Tipo de Despesas"  For "TG_DESP"
    Accept @ 05,39 Width 04 "A1"  Picture "F,V" Tag "TG_DESP" To VSDGDESP
    Accept @ 05,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMDESP"  To VSDGNOMDESP

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

    Pushbutton @ 13,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 13,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  if not ValidarModelosRelatorios() then loop endif         

  If VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  If Len(VSDGPLCONTAS)<13
     Then PLCONTAS=VSDGPLCONTAS + ".."
     Else PLCONTAS=VSDGPLCONTAS
  EndIf

  If VSDGEMPRESA="0000"
     Then VSDGEMPRESA2=""
     Else VSDGEMPRESA2=VSDGEMPRESA
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relatorio")
  switch
    case VSDGCODMODELO="01"  Or
         VSDGCODMODELO="02"  Or
         VSDGCODMODELO="03"  Or
         VSDGCODMODELO="04" : Play "RM_0200A"

    case VSDGCODMODELO="01C" Or
         VSDGCODMODELO="02C" Or
         VSDGCODMODELO="03C" Or
         VSDGCODMODELO="04C" : Play "RM_0200B"
         
  endswitch

EndWhile
ClearAll
Release Vars All
Release Procs All
