;** Rc_0030 ********************************************************************
;*  Relatorio de Clientes por Cidade                                           *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 07/06/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 02/04/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 02/10/2009 por Bruno Carvalho
;Motivo Alteracao: InclusÆo da Op‡Æo "Consumidor Final"
;Ultima Alteracao: 04/02/2011 por Karina Andrade
;Motivo Alteracao: Ajustes ShowDialog
;Ultima Alteracao: 20/04/2021 por Bruno Carvalho             
;Motivo Alteracao: Ajustes no processo do filtro "TG_STATUS" na "Bib_Show"

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
{Ask} {Destinat} Check
Moveto [Tipo  ] TypeIn "C"
Moveto [UF    ] TypeIn "~VSDGESTADO.."
Moveto [Cidade] TypeIn CIDADE
Switch
  Case VSDGSTATUS="INATIVO" : Moveto [Inativo] TypeIn "S"
  OtherWise                 : Moveto [Inativo] TypeIn "Not S"
EndSwitch     
Moveto [Consumidor Final]
Switch
  Case VSDGCONSFINAL="S": TypeIn "S"
  Case VSDGCONSFINAL="N": TypeIn "Not S"
EndSwitch
Do_It!
ClearAll
If VSDGOPRELLISTCAD="1"
   Then  If VSDGOPRELCODALF="2"
            Then  If VSDGOPRELANALSINT="1"
                     Then DORDEM="Alfabetica"
                          CopyReport "Destinat" "7" "Answer" "R"
                     Else DORDEM="Alfabetica"
                          If VSDGCABECALHO="S"
                             Then If VSDGOBSERVACAO="S"
                                     Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "7" "Answer" "R"
                                     Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "4" "Answer" "R"
                                  EndIf
                             Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "12" "Answer" "R"
                          Endif
                  EndIf
            Else  If  VSDGOPRELANALSINT="2"
                      Then DORDEM="de Codigo "
                           CopyReport "Destinat" "8" "Answer" "R"
                      Else DORDEM="de Codigo "
                          If VSDGCABECALHO="S"
                             Then If VSDGOBSERVACAO="S"
                                     Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "8" "Answer" "R"
                                     Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "5" "Answer" "R"
                                  EndIf
                             Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "13" "Answer" "R"
                         EndIf
                  EndIf
         EndIf
   Else  If VSDGOPRELCODALF="2"
            Then DORDEM="Alfabetica"
                If VSDGCABECALHO="S"
                    Then If VSDGOBSERVACAO="S"
                            Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "9" "Answer" "R"
                            Else CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "R" "Answer" "R"
                         EndIf
                    Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0040" "R" "Answer" "R"
                EndIf
            Else DORDEM="de Codigo "
                 If VSDGCABECALHO="S"
                    Then If VSDGOBSERVACAO="S"
                            Then CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "10" "Answer" "R"
                            Else CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "4" "Answer" "R"
                         EndIf
                    Else CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0030" "14" "Answer" "R"
                 EndIf
         EndIf
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"] <= -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"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_ESTADO"         : Campo="NO"
            Case Campo="TG_CIDADE"         : Campo="TG_ESTADO"
            Case Campo="TG_STATUS"         : Campo="TG_CIDADE"
            Case Campo="TG_OPRELLISTCAD"   : Campo="TG_STATUS"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_OPRELLISTCAD"
            Case Campo="TG_CONSFINAL"      : Campo="TG_OPRELCODALF"
            Case Campo="TG_CABECALHO"      : Campo="TG_CONSFINAL"
            Case Campo="TG_OBSERVACAO"     : Campo="TG_CABECALHO"
            Case Campo="TG_OPRELANALSINT"  : Campo="TG_OBSERVACAO"
            Case Campo="YES" Or Campo="NO" : Campo="TG_ESTADO"
          EndSwitch
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_ESTADO"      : Campo="TG_CIDADE"
                    Case Campo="TG_CIDADE"      : Campo="TG_STATUS"
                         If Upper(VSDGCIDADE)="TODAS"
                            Then CIDADE=""
                            Else CIDADE=VSDGCIDADE
                         EndIf
                    Case Campo="TG_STATUS"      : Campo="TG_OPRELLISTCAD"
                    Case Campo="TG_OPRELLISTCAD": Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF" : Campo="TG_CONSFINAL"
                    Case Campo="TG_CONSFINAL":
                        VSDGCONSFINAL=ControlValue("TG_CONSFINAL")
                        Switch
                          Case VSDGCONSFINAL="S": VSDGNOMCONSFINAL="SIM"
                          Case VSDGCONSFINAL="N": VSDGNOMCONSFINAL="NAO"
                          OtherWise             : VSDGNOMCONSFINAL="TODOS"
                        EndSwitch
                        Campo="TG_CABECALHO"
                    Case Campo="TG_CABECALHO"   :
                        VSDGCABECALHO=ControlValue("TG_CABECALHO")
                        If Not ISBlank(VSDGCABECALHO)
                           Then If VSDGCABECALHO="N"
                                   Then VSDGNOMCABECALHO="NAO"
                                   Else VSDGNOMCABECALHO="SIM"
                                EndIf
                                If VSDGCABECALHO="S"
                                   Then Campo="TG_OBSERVACAO"
                                   Else VSDGOBSERVACAO="N"
                                        VSDGNOMOBSERVACAO="NAO"
                                        If VSDGOPRELLISTCAD="1"
                                           Then If (VSDGOBSERVACAO="N") and (VSDGCABECALHO="N")
                                                   Then Campo="TG_OPRELANALSINT"
                                                   Else VSDGOPRELANALSINT="1"
                                                        VSDGNOMOPRELANALSINT="ANALITICO"
                                                        Campo="YES"
                                                EndIf
                                           Else Campo="YES"
                                                VSDGOPRELANALSINT=""
                                                VSDGNOMOPRELANALSINT=""
                                        EndIf
                                EndIf
                        EndIf
                    Case Campo="TG_OBSERVACAO"  :
                         VSDGOBSERVACAO=ControlValue("TG_OBSERVACAO")
                         If Not IsBlank(VSDGOBSERVACAO)
                            Then Switch
                                   Case VSDGOBSERVACAO="S":
                                        VSDGNOMOBSERVACAO="SIM"
                                   Case VSDGOBSERVACAO="N":
                                        VSDGNOMOBSERVACAO="NAO"
                                 EndSwitch
                                 If VSDGOPRELLISTCAD="1"
                                    Then If (VSDGOBSERVACAO="N") and (VSDGCABECALHO="N")
                                            Then Campo="TG_OPRELANALSINT"
                                            Else VSDGOPRELANALSINT="1"
                                                 VSDGNOMOPRELANALSINT="ANALITICO"
                                                 Campo="YES"
                                         EndIf
                                    Else Campo="YES"
                                         VSDGOPRELANALSINT=""
                                         VSDGNOMOPRELANALSINT=""
                                 EndIf
                         EndIf
                    Case Campo="TG_OPRELANALSINT":
                         If Not IsBlank(VSDGOPRELANALSINT)
                            Then Campo="YES"
                         EndIf
                EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OBSERVACAO":
       MSG_CAMPO="Informe Sim ou N„o"
  Case Campo="TG_CABECALHO":
       MSG_CAMPO="Informe Sim ou N„o"
  Case Campo="TG_CONSFINAL":
       MSG_CAMPO="Informe Sim ou N„o"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()

VSDGDESTINATINI     =""
VSDGDESTINATFIM     =""
VSDGOPRELCODALF     =""
VSDGOPRELLISTCAD    =""
VSDGOPRELANALSINT   =""
VSDGNOMOPRELANALSINT=""
VSDGOBSERVACAO      =""
VSDGNOMOBSERVACAO   =""
VSDGCIDADE          =""
VSDGSTATUS          =""
VSDGCONSFINAL       =""
While True

  ShowDialog "Relat¢rio de Clientes por Estado/Cidade" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 03,12   Height 13 Width 64

    Label  @ 00,00 "Estado"  For "TG_ESTADO"
    Accept @ 01,01 Width 05 "A2"  Picture "!*!" Tag "TG_ESTADO" To VSDGESTADO
    Accept @ 01,07 Width 23 "A20" Picture "!*!" Tag "TG_NOMESTADO"  To VSDGNOMESTADO

    Label  @ 00,31 "Cidade"  For "TG_CIDADE"
    Accept @ 01,32 Width 23 "A20"  Picture "!*!" Tag "TG_CIDADE" To VSDGCIDADE

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

    Label  @ 02,31 "Op‡„o" For "TG_OPRELLISTCAD"
    Accept @ 03,32 Width 05 "A1"  Picture "1,2" Tag "TG_OPRELLISTCAD" To VSDGOPRELLISTCAD
    Accept @ 03,38 Width 23 "A20" Picture "!*!" Tag "TG_NOMOPRELLISTCAD" To VSDGNOMOPRELLISTCAD

    Label  @ 04,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 05,01 Width 05 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 05,07 Width 23 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF
 
    Label  @ 04,31 "Consumidor Final" For "TG_CONSFINAL"
    Accept @ 05,32 Width 05 "A1"  Picture "S,N" Tag "TG_CONSFINAL" To VSDGCONSFINAL
    Accept @ 05,38 Width 23 "A12"  Picture "SIM,NAO" Tag "TG_NOMCONSFINAL" To VSDGNOMCONSFINAL
    
    Label  @ 06,00 "Cabecalho" For "TG_CABECALHO"
    Accept @ 07,01 Width 05 "A1"  Picture "S,N" Tag "TG_CABECALHO" To VSDGCABECALHO
    Accept @ 07,07 Width 08 "A3"  Picture "SIM,NAO" Tag "TG_NOMCABECALHO" To VSDGNOMCABECALHO

    Label  @ 06,15 "Observa‡„o" For "TG_OBSERVACAO"
    Accept @ 07,16 Width 04 "A1"  Picture "S,N" Tag "TG_OBSERVACAO" To VSDGOBSERVACAO
    Accept @ 07,21 Width 09 "A3"  Picture "SIM,NAO" Tag "TG_NOMOBSERVACAO" To VSDGNOMOBSERVACAO

    Label  @ 06,31 "Tipo" For "TG_OPRELANALSINT"
    Accept @ 07,32 Width 05 "A1"  Picture "1,2" Tag "TG_OPRELANALSINT" To VSDGOPRELANALSINT
    Accept @ 07,38 Width 23 "A12"  Picture "!*!" Tag "TG_NOMOPRELANALSINT" To VSDGNOMOPRELANALSINT

    Pushbutton @ 09,18 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,32 width 11 "~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")

  Seleciona()

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

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

