;** Rc_0020 *******************************************************************
;*  Listagem Simples de Clientes                                               *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 09/01/2004 por Karen Lauar Nery
;Ultima Alteracao: 03/08/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao novo relatorio
;Ultima Alteracao: 21/08/2013 por Bruno Carvalho
;Motivo Alteracao: Ajustes "Situacao do Cliente" p/ permitir situa‡Æo como OTIMO
;Ultima Alteracao: 20/04/2021 por Bruno Carvalho             
;Motivo Alteracao: Ajustes no processo do filtro "TG_STATUS" na "Bib_Show"
;Ultima Alteracao: 22/04/2021 por Bruno Carvalho             
;Motivo Alteracao: Alterado TG_SITUACAO p/ TG_SITUACAOCLIENTE
;Ultima Alteracao: 16/07/2021 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes VSDGSTATUS

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

{Ask} {Destinat} Check
Moveto [Codigo     ] TypeIn ">=~VSDGDESTINATINI,<=~VSDGDESTINATFIM"
Moveto [Tipo       ] TypeIn "C"
Moveto [Tipo Pessoa] TypeIn "~VSDGTIPO.."
Switch
  Case VSDGSTATUS="INATIVO" : Moveto [Inativo] TypeIn "S"
  Case VSDGSTATUS="ATIVO"   : Moveto [Inativo] TypeIn "Not S"
EndSwitch      
Switch
  Case ListaRegra_VSDGSITUACAOCLIENTE_Ativo : Moveto [Situacao do Cliente]       TypeIn ListaRegra_VSDGSITUACAOCLIENTE
  Otherwise                                 : Moveto [Situacao do Cliente]       TypeIn "~VSDGSITUACAOCLIENTE.."
EndSwitch                
DEBUG
Do_It!
ClearAll

If VSDGOPRELCODALF = "2"
   Then {Modify} {Sort} {Answer} {Same} Down Down Down "1" Do_It!
        DORDEM="Alfabetica"
   Else {Modify} {Sort} {Answer} {Same} "1" Do_It!
        DORDEM="de Codigo"
EndIf

EndProc  ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog1(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"] = -60: ListaRegra_F2()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_DESTINATINI"      : Campo="NO"
            Case Campo="TG_DESTINATFIM"      : Campo="TG_DESTINATINI"
            Case Campo="TG_STATUS"           : Campo="TG_DESTINATFIM"
            Case Campo="TG_SITUACAOCLIENTE"  : Campo="TG_STATUS"
            Case Campo="TG_OPRELCODALF"      : Campo="TG_SITUACAOCLIENTE"
            Case Campo="TG_TIPO"             : Campo="TG_OPRELCODALF"
            Case Campo="TG_OPMODEL"          : Campo="TG_TIPO" 
            Case Campo="YES" Or Campo="NO"   : Campo="TG_DESTINATINI"
          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_DESTINATINI" :Campo="TG_DESTINATFIM"
                    Case Campo="TG_DESTINATFIM" :
                         If VSDGDESTINATFIM < VSDGDESTINATINI
                            Then Mensagem("Codigo final menor que codigo inicial !")
                            Else Campo="TG_STATUS"
                         EndIf
                    Case Campo="TG_STATUS"          : Campo="TG_SITUACAOCLIENTE"
                    Case Campo="TG_SITUACAOCLIENTE" : Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF"     : Campo="TG_TIPO"
                        Campo="TG_TIPO"
                    Case Campo="TG_TIPO"            :
                         VSDGTIPO=ControlValue("TG_TIPO")
                         If VSDGTIPO="F"
                            Then VSDGTIPO="FISICA"
                                 VSDGNOMTIPO="FISICA"
                         EndIf
                         If VSDGTIPO="J"
                            Then VSDGTIPO="JURIDICA"
                                 VSDGNOMTIPO="JURIDICA"
                         EndIf
                         If VSDGTIPO=""
                            Then VSDGNOMTIPO="Todos"
                         EndIf
                         Campo="TG_OPMODEL"
                    Case Campo="TG_OPMODEL":
                        VSDGOPMODEL=ControlValue("TG_OPMODEL")
                        Switch
                          Case VSDGOPMODEL="2": VSDGNOMOPMODEL="MODELO 2"
                          OtherWise           : VSDGOPMODEL="1"
                                                VSDGNOMOPMODEL="MODELO 1"
                        EndSwitch
                        Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_TIPO":
     MSG_CAMPO="Informe (F=Fisica  J=Juridica  Em Branco=Todos)"
  Case Campo="TG_OPMODEL":
     MSG_CAMPO="1=Modelo 1  2=Modelo 2"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGDESTINATINI  =""
VSDGDESTINATFIM  =""
VSDGOPRELCODALF  =""
VSDGTIPO         =""
VSDGSITUACAO     =""
VSDGSTATUS       =""
DESCTP           ="Clientes"
VSDGOPMODEL      =""
VSDGNOMOPMODEL   =""
VSDGSITUACAOCLIENTE    = ""  
VSDGNOMSITUACAOCLIENTE = ""

ListaRegra_Funcao("ListaRegra_TGAtivado","[TG_SITUACAOCLIENTE]")

While True
  ShowDialog "Listagem Simples de Clientes" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140,-60, -59,"F2"
   @ 05,12   Height 17 Width 40

    Label  @ 00,00 "Cliente"  For "TG_DESTINATINI"
    Label  @ 01,01 "de"  For "TG_DESTINATINI"
    Accept @ 01,05 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATINI" To VSDGDESTINATINI
    Label  @ 01,12 "at‚"  For "TG_DESTINATFIM"
    Accept @ 01,17 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATFIM" To VSDGDESTINATFIM

    Label  @ 02,00 "Status do Cliente" For "TG_STATUS"
    Accept @ 03,01  Width 28 "A12" Picture "ATIVO,INATIVO,TODOS" Tag "TG_STATUS" To VSDGSTATUS 

    Label  @ 04,00 "Situa‡Æo do Cliente" For "TG_SITUACAOCLIENTE"
    Accept @ 05,01 Width 04 "A1"  Picture "O,B,R,P" Tag "TG_SITUACAOCLIENTE" To VSDGSITUACAOCLIENTE
    Accept @ 05,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMSITUACAOCLIENTE" To VSDGNOMSITUACAOCLIENTE
    
    Label  @ 06,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 07,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 07,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Label  @ 08,00 "Tipo do Cliente" For "TG_TIPO"
    Accept @ 09,01 Width 04 "A1"  Picture "F,J, " Tag "TG_TIPO" To VSDGTIPO
    Accept @ 09,06 Width 23 "A9" Picture "!*!" Tag "TG_NOMTIPO" To VSDGNOMTIPO

    Label  @ 10,00 "Modelo relat¢rio" For "TG_OPMODEL"
    Accept @ 11,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPMODEL" To VSDGOPMODEL
    Accept @ 11,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMOPMODEL" To VSDGNOMOPMODEL

    Pushbutton @ 13,07 width 12 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 13,21 width 12 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")
  ORDEM()
  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  Switch
    Case VSDGOPMODEL="1":
      CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0040" "9" "Answer" "R"
    Case VSDGOPMODEL="2":
      If VSDGOPRELCODALF="1"
         Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0040B" "6" "Answer" "R"
         Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0040B" "7" "Answer" "R"
      EndIf   
  EndSwitch
  
  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

