;** Rc_0130 *******************************************************************
;*  Relatorio de Aniversarios                                                      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 09/03/98 por Anivel Augusto Rodrigues
;Ultima Alteracao: 02/04/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 21/08/2013 por Bruno Carvalho
;Motivo Alteracao: Ajustes "Situacao do Cliente" p/ permitir situa‡Æo como OTIMO
;Ultima Alteracao: 09/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 23/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 26/04/2018 por Bruno Carvalho
;Motivo Alteracao: Ajustes p/ [Data de Nascimento] ser consultada/armazenada pela Destinat                   
;Ultima Alteracao: 23/04/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ask              
;Ultima Alteracao: 24/04/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes modelo relatorio 

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

{Ask} {Destinat} check
Moveto [Tipo               ] TypeIn "C"
Moveto [Situacao do Cliente] TypeIn "OTIMO or BOM or Blank"
Do_It!
ClearAll
If IsEmpty("Answer")
   Then Return
EndIf

Edit "Answer"
scan
  if isblank([Data de Nascimento ]) or month([Data de Nascimento ])<>numval(VSDGMES)
     then 
          [Tipo]="0"
     else
          If Day([Data de Nascimento]) < NumVal(VSDGDIAINI) Or
             Day([Data de Nascimento]) > NumVal(VSDGDIAFIM)
             Then [Tipo]="0"
          Endif
  endif   
endscan
Do_It!
ClearAll


{Ask}{Answer} typein "Delete"
Moveto [Tipo               ] TypeIn "0"
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="TG_MES"           : Campo="NO"
            Case Campo="TG_DIAINI"        : Campo="TG_MES"
            Case Campo="TG_DIAFIM"        : Campo="TG_DIAINI"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_DIAFIM"
            Case Campo="TG_CODMODELO"     : Campo="TG_OPRELCODALF" 
            Case Campo="YES" Or Campo="NO": Campo="TG_MES"
          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_MES":
                         VSDGMES=ControlValue("TG_MES")
                          If isblank(VSDGMES) then VSDGMES=strval(month(today())) endif
                         VSDGMES=AlinhM(VSDGMES,2)
                         If NumVal(VSDGMES) <= 0 Or NumVal(VSDGMES) > 12
                            Then MENSAGEM("Mes Informado nÆo ‚ V lido !")
                            Else Campo="TG_DIAINI"
                         EndIf
                    Case Campo="TG_DIAINI" :
                          VSDGDIAINI=ControlValue("TG_DIAINI")
                          If isblank(VSDGDIAINI) then VSDGDIAINI="1" endif
                          VSDGDIAINI=AlinhM(VSDGDIAINI,2)
                          If NumVal(VSDGDIAINI) <= 0 Or NumVal(VSDGDIAINI) > 31 Or VSDGDIAINI =""
                             Then MENSAGEM("Dia Informado nÆo ‚ V lido !")
                             Else Campo="TG_DIAFIM"
                          EndIf
                    Case Campo="TG_DIAFIM" :
                          VSDGDIAFIM=ControlValue("TG_DIAFIM")
                          If isblank(VSDGDIAFIM) then VSDGDIAFIM="31" endif
                          VSDGDIAFIM=AlinhM(VSDGDIAFIM,2)

                          If NumVal(VSDGDIAFIM) <= 0 Or NumVal(VSDGDIAFIM) > 31
                             Then MENSAGEM("Dia Informado nÆo ‚ V lido !")
                             Else Campo="TG_OPRELCODALF"
                          EndIf
                    Case Campo="TG_OPRELCODALF"  : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"    : Campo="YES" 
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_MES"    : MSG_CAMPO="Informe o mes"
  Case Campo="TG_DIAINI" : MSG_CAMPO="Informe o dia Inicial"
  Case Campo="TG_DIAFIM" : MSG_CAMPO="Informe o dia Final"
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  Por Data de Nascimento")
ModeloRelatoriosAdd("02  Por Dia da Data de Nascimento")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista


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

VSDGDIAINI=""
VSDGDIAFIM=""
VSDGDMES =""
VSDGOPRELCODALF=""

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Rela‡„o de Aniversariantes" 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 14 Width 72

    Label  @ 00,00 "Mˆs Referente" For "TG_MES"
    Accept @ 01,03 Width 05 "A2"  Picture "#[#]" Tag "TG_MES" To VSDGMES

    Label  @ 02,00 "Per¡odo Dia de" For "TG_DIAINI"
    Accept @ 03,03 Width 05 "A2"  Picture "#[#]" Tag "TG_DIAINI" To VSDGDIAINI
    Label  @ 03,08 "at‚" For "TG_DIAFIM"
    Accept @ 03,13 Width 05 "A2"  Picture "#[#]" Tag "TG_DIAFIM" To VSDGDIAFIM

    Label  @ 04,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 05,04 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 05,09 Width 25 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    @ 01,35 ?? "S¢ Cliente OTIMO, BOM, .."

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

    Pushbutton @ 10,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 10,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(VSDGDIAINI)
     Then Mensagem("Dia Inicial Invalida !")
          Loop
  EndIf

  If IsBlank(VSDGDIAFIM)
     Then Mensagem("Dia Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")

  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  switch
    case VSDGCODMODELO="01" : CopyReport "\\Base\\Sistemas\\Cadastro\\rc_0130" "R" "Answer" "R"
    case VSDGCODMODELO="02" : CopyReport "\\Base\\Sistemas\\Cadastro\\rc_0130" "1" "Answer" "R"
  Endswitch
  If VSDGOPRELCODALF="1"
    Then Seta_Ordem_Report("Answer","R","Codigo","Razao Social","") 
    Else Seta_Ordem_Report("Answer","R","Razao Social","Razao Social","")
  Endif
  
  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

