;** GR_0001 ********************************************************************
;*  Grafico de evolu‡Æo de clientes                                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 21/07/2014 por Anivel Augusto Rodrigues
;Ultima Alteracao: 30/08/2014 por Anivel Augusto Rodrigues 
;Motivo Alteracao: ajustes filtros

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

{Ask} TypeIn "\\Sistemas\\Cadastro\\Destinat" Enter 
Moveto [Codigo               ] TypeIn "Calc Count as Qtde"
Moveto [Data_Cadastro        ] Check
Moveto [Tipo                 ] TypeIn "C"
Do_It!
ClearAll

PROCESSA("C")

EndProc

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

{Ask} TypeIn "\\Sistemas\\Cadastro\\Destinat" Enter 
Moveto [Codigo               ] TypeIn "Calc Count as Qtde"
Moveto [Data_Inativo         ] Check typein "As \"Data_Cadastro\""
Moveto [Inativo              ]       typein "S"
Moveto [Tipo                 ] TypeIn "C"
Do_It!
ClearAll

PROCESSA("I")

EndProc

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc PROCESSA(tipo)
ClearAll


View PrivDir()+"GR_0001"
CoEdit "Answer"
Scan
   If IsBlank([Data_Cadastro]) Then [Data_Cadastro]=DateVal("01.01.2002") EndIf
   ano=StrVal(Year([Data_Cadastro]))
   
   Moveto PrivDir()+"GR_0001"
   Moveto [Mes]
   Locate Ano
   If Not RetVal
      Then End Down
           [Mes   ]=ano
   EndIf
   switch
     case tipo="C": [Valor 1 ]=[Valor 1]+[Answer->Qtde]
     case tipo="I": [Valor 2 ]=[Valor 2]+[Answer->Qtde]
   endswitch

   Moveto "Answer"
EndScan
Do_It!
ClearAll

EndProc

;*******************************************************************************
;* 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: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="YES" Or Campo="NO": Campo="TG_CONTA"
          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 
          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()

VSDGCONTA  =""
VSDGMESANO =AlinhM(StrVal(Month(Today())),2)+"."+AlinhM(StrVal(Year(Today())),4)

While True
  ShowDialog "Evolu‡Æo de Clientes" 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 09 Width 56


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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVOG()
  If OK="" Then Loop EndIf
  
  Copy "\\Base\\Sistemas\\Ctacor\\GR_0001" PrivDir()+"GR_0001"
  Empty(PrivDir()+"GR_0001")

  AGUARDE("Aguarde, Gerando Dados")
  
  Seleciona()
  Seleciona2()
  
  If IsEmpty(PrivDir()+"GR_0001")
     Then MENSAGEM("N„o existem registros a processar")
          Loop
  EndIf

  GRAF_TAB = PrivDir()+"GR_0001"
  GRAF_TIPO= "3"
  GRAF_TIT1= "Evolu‡Æo de Clientes"
  GRAF_TIT2= ""
  GRAF_LINX= "Qtde"
  GRAF_LINY= "Ano"
  GRAF_LENG= "Y"
  GRAF_LENG1= "Ativos"
  GRAF_LENG2= "Inativos"
  GRAF_CAMPO= 2

  MONTAGRAFICO(GRAF_TAB)

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

