;** Rm_0130  *******************************************************************
;*  AMovimentos por centro de csuto                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 26/04/2018 por Anivel Augusto Rodrigues
;Ultima Alteracao: 26/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()

;*******************************************************************************
;* 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_CCUSTO"        : Campo="TG_EMPRESATE"
            Case Campo="TG_OPDTEMISCOMP"  : Campo="TG_CCUSTO"
            Case Campo="TG_DTINI"         : Campo="TG_OPDTEMISCOMP"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_OPCCUSTO"      : Campo="TG_DTFIM"
            Case Campo="TG_OPERACAO"      : Campo="TG_OPCCUSTO"
            Case Campo="TG_CODMODELO"     : Campo="TG_OPERACAO"
            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_CCUSTO"
                    Case Campo="TG_CCUSTO"       : Campo="TG_OPDTEMISCOMP"
                    Case Campo="TG_OPDTEMISCOMP" : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"        : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"        : Campo="TG_OPCCUSTO"
                    Case Campo="TG_OPCCUSTO"     : Campo="TG_OPERACAO"
                    Case Campo="TG_OPERACAO"     : Campo="TG_CODMODELO"
                         VSDGOPERACAO = ControlValue("TG_OPERACAO")
                         Switch
                            Case VSDGOPERACAO = "E": VSDGNOMOPERACAO = "ENTRADA"
                            Case VSDGOPERACAO = "S": VSDGNOMOPERACAO = "SAIDA"
                            OtherWise              : VSDGNOMOPERACAO = "TODOS"
                         EndSwitch
                    Case Campo="TG_CODMODELO"    : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_OPCCUSTO":
     MensagemCheckBoxes()
  Case Campo="TG_OPERACAO":
       MSG_CAMPO="Op‡äes: E=Entrada  S=Sa¡da  Em Branco=Todos" 
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("15  Anal¡tico I")
ModeloRelatoriosAdd("19  Anal¡tico II/Plano de Contas")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("16  Sint‚tico  I/Pessoa")
ModeloRelatoriosAdd("17  Sint‚tico II")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

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

Array TG_OPCCUSTO[1]
TG_OPCCUSTO[1]="Ignorar em Branco"

Array CheckTG_OPCCUSTO[ArraySize(TG_OPCCUSTO)]
CheckTG_OPCCUSTO[1]=False

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Movimentos por centro de custo" 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 "Centro de Custo" For "TG_CCUSTO"
    Accept @ 03,01 Width 33 "A7"  Picture "###.###" Tag "TG_CCUSTO" To VSDGCCUSTO
    Accept @ 04,01 Width 33 "A20" Picture "!*!" Tag "TG_NOMCUST"  To VSDGNOMCUST
    
    Label  @ 05,00 "Op‡äes de Datas" For "TG_OPDTEMISCOMP"
    Accept @ 06,04 Width 04 "A1"  Picture "1,2" Tag "TG_OPDTEMISCOMP" To VSDGOPDTEMISCOMP
    Accept @ 06,09 Width 25 "A20"  Picture "!*!" Tag "TG_NOMOPDTEMISCOMP" To VSDGNOMOPDTEMISCOMP

    Label  @ 07,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 08,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 08,16 "at‚" For "TG_DTFIM"
    Accept @ 08,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 00,35 "Centro de Custo"  For "TG_OPCCUSTO"
    CheckBoxes @ 01,35 Height 1 Width 35 Tag "TG_OPCCUSTO"
    TG_OPCCUSTO[1] to CheckTG_OPCCUSTO[1]
  
    Label  @ 02,35 "Movimento de" For "TG_OPERACAO"
    Accept @ 03,39 Width 04 "A1"  Picture "S,E" Tag "TG_OPERACAO" To VSDGOPERACAO
    Accept @ 03,44 Width 25 "A7" Picture "!*!" Tag "TG_NOMOPERACAO"  To VSDGNOMOPERACAO

    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 IsBlank(VSDGDTFIM)
     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 Relatorio")
  switch
    case VSDGCODMODELO="15" : Play "RM_0130A"
    case VSDGCODMODELO="19" : Play "RM_0130B"
    case VSDGCODMODELO="16" : Play "RM_0130C"
    case VSDGCODMODELO="17" : Play "RM_0130D"
  endswitch

EndWhile
ClearAll
Release Vars All
Release Procs All
