;** Rm_0001*********************************************************************
;* Rela‡Æo de Contratos                                                        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido  em: 21/11/2016 por Rafael Matos 
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes ShowDialog TG_DESTINAT   
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()

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

{Ask} TypeIn "\\Sistemas\\Geec\\Cobtmpc" Enter Check
 Moveto [Codigo                 ] Example "clie" TypeIn ", ~VSDGDESTINAT.."
 Moveto [Codigo da Rota         ] TypeIn "~VSDGROTA.."
 Moveto [Data Referente         ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 
 {Ask} TypeIn "\\Sistemas\\Geec\\CobtmpI" Enter
 Moveto [Codigo                 ] Example "clie"
 Moveto [Numero_Contrato        ] Check
 Moveto [Codigo_TpContrato      ] TypeIn "~VSDGTPCONTRATO.." Check
 Moveto [Descricao_TpContrato   ] Check
 Moveto [Valor_TpContrato       ] Check
 
 Do_It!
 
 View "Answer"
           
 ClearAll
         
EndProc   ; (Seleciona)

;*******************************************************************************
;* Rotina 2 p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc Seleciona2()

{Ask} TypeIn "\\Sistemas\\Geec\\Cobtmpc" Enter Check
 Moveto [Codigo                 ] Example "clie" TypeIn ", ~VSDGDESTINAT.."
 Moveto [Codigo da Rota         ] TypeIn "~VSDGROTA.."
 Moveto [Data Referente         ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 
 Do_It!
 
 View "Answer"
           
 ClearAll
         
EndProc   ; (Seleciona)

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

;ModeloRelatoriosAdd("XXX  XX maximo 61 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Anal¡tico por Rota")
ModeloRelatoriosAdd("02  Anal¡tico por Pessoa/Contratos")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("03  Sint‚tico por Rota")
ModeloRelatoriosAdd("04  Sint‚tico por Tipo de Contrato")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9: Temp=False
     Case Evento["KeyCode"] = -59: 
          Switch
            Case Campo="TG_CODMODELO" : If ModeloRelatorios()
                                           Then VSDGCODMODELO=Rtrim(SubStr(Array_OpModeloRelatorios[VSDGOPMODELORELATORIOS],1,3))
                                                VSDGMODELO   =SubStr(Array_OpModeloRelatorios[VSDGOPMODELORELATORIOS],5,75)
                                        EndIf
          Otherwise : Dialog_F1()                              
          EndSwitch
     
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_DESTINAT"          : Campo="NO"
            Case Campo="TG_TPCONTRATO"        : Campo="TG_DESTINAT"
            Case Campo="TG_ROTA"              : Campo="TG_TPCONTRATO"
            Case Campo="TG_DTINI"             : Campo="TG_ROTA"
            Case Campo="TG_DTFIM"             : Campo="TG_DTINI"
            Case Campo="TG_CODMODELO"         : Campo="TG_DTFIM"
            Case Campo="YES" Or Campo="NO"    : Campo="TG_DESTINAT"
          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_DESTINAT"    : Campo="TG_TPCONTRATO"
                    Case Campo="TG_TPCONTRATO"  : Campo="TG_ROTA"
                    Case Campo="TG_ROTA"          : 
                         VSDGROTA=ControlValue("TG_ROTA")
                         If Not IsBlank(VSDGROTA)
                           Then VSDGROTA=ALINHM(VSDGROTA,4)
                                View NOWINDOW "\\Sistemas\\Cadastro\\Rota"
                                Moveto [Codigo da Rota]
                                Locate VSDGROTA
                                If Not RetVal
                                   Then MENSAGEM("Rota n„o Cadastrada !")
                                        Valor=False
                                   Else VSDGNOMROTA=[Descricao da Rota]
                                        Campo="TG_DTINI"
                                EndIf
                                ClearAll
                           Else VSDGNOMROTA="TODAS"
                                Campo="TG_DTINI"
                         EndIf                       
                    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()

VSDGDESTINAT =""
VSDGNOMDEST  =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()
VSDGTPCONTRATO =""
VSDGNOMTPCONTRATO =""

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Rela‡Æo de Cobran‡as Geradas" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 16 Width 72

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

    Label  @ 02,00 "Tipo do Contrato"  For "TG_TPCONTRATO"
    Accept @ 03,01 Width 09 "A6"  Picture "[&,#][#*#]" Tag "TG_TPCONTRATO" To VSDGTPCONTRATO
    Accept @ 03,10 Width 24 "A20" Picture "!*!" Tag "TG_NOMTPCONTRATO"  To VSDGNOMTPCONTRATO
    
    Label  @ 04,00  "Rota"  For "TG_ROTA"
    Accept @ 05,01  Width 07 "A4"  Picture "!*!" Tag "TG_ROTA" To VSDGROTA
    Accept @ 05,09  Width 25 "A15"  Picture "!*!" Tag "TG_NOMROTA" To VSDGNOMROTA

    Label  @ 06,00 "Data Referente de" For "TG_DTINI"
    Accept @ 07,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 07,16 "at‚" For "TG_DTFIM"
    Accept @ 07,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
    
    Label  @ 09,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 10,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 10,06  Width 63 "A64"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO  

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  if not ValidarModelosRelatorios() then loop endif         
  
  DISPOSITIVO()
  
  If OK=""  Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")

    If VSDGCODMODELO="02" or VSDGCODMODELO="04"
       Then Seleciona()
       Else Seleciona2()
    EndIf
    
  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Loop
  EndIf

  Switch
    Case VSDGCODMODELO="01": Impressao_Orientacao="Retrato" CopyReport "\\Base\\Sistemas\\Geec\\Rm_0003" "R" "Answer" "R"
    Case VSDGCODMODELO="02": Impressao_Orientacao="Retrato" CopyReport "\\Base\\Sistemas\\Geec\\Rm_0003" "1" "Answer" "R"
    Case VSDGCODMODELO="03": Impressao_Orientacao="Retrato" CopyReport "\\Base\\Sistemas\\Geec\\Rm_0003" "2" "Answer" "R"
    Case VSDGCODMODELO="04": Impressao_Orientacao="Retrato" CopyReport "\\Base\\Sistemas\\Geec\\Rm_0003" "3" "Answer" "R"
  EndSwitch

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

