;** Rc_0040 *******************************************************************
;*  Relatorio de Clientes por Representante                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/95 por Anivel Augusto Rodrigues
;Ultima Alteracao: 02/04/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 10/04/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 06/04/2010 por Cleber Alves            
;Motivo Alteracao: Acrescimo modelo 3
;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll                         

{Ask} {Destinat} Check
Moveto [Codigo ] Example "cod" TypeIn "!"
Moveto [Tipo                   ] TypeIn "C"
Moveto [Codigo do Representante] TypeIn "~VSDGREPRESEN.."
Moveto [Inativo]
Switch
  Case VSDGSTATUS="1": TypeIn "N"
  Case VSDGSTATUS="2": TypeIn "S"
EndSwitch

{Ask} {Fichacli}
Moveto [Codigo ] Example "cod"
Moveto [Data da Ultima Compra] Check

Do_It!
ClearAll
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"] =  27:
          Temp=False
          Switch
            Case Campo="TG_REPRESEN"       : Campo="NO"
            Case Campo="TG_STATUS"         : Campo="TG_REPRESEN"
            Case Campo="TG_RELATORIO"      : Campo="TG_STATUS"
            Case Campo="TG_CABECALHO"      : Campo="TG_RELATORIO"
            Case Campo="YES" Or Campo="NO" : Campo="TG_REPRESEN"
          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_REPRESEN"     :Campo="TG_STATUS"
                    Case Campo="TG_STATUS"       :Campo="TG_RELATORIO"
                    Case Campo="TG_RELATORIO"    :
                         VSDGRELATORIO=ControlValue("TG_RELATORIO")
                         Switch
                           Case VSDGRELATORIO=2 Or
                                VSDGRELATORIO=3 Or 
                                VSDGRELATORIO=4:
                                Campo="TG_CABECALHO"
                           OtherWise:
                                VSDGCABECALHO   ="S"
                                VSDGNOMCABECALHO="SIM"
                                Campo="YES"
                         EndSwitch
                    Case Campo="TG_CABECALHO"    :Campo="YES"
                         VSDGCABECALHO=ControlValue("TG_CABECALHO")
                         If VSDGCABECALHO="N"
                            Then VSDGNOMCABECALHO="NˇO"
                            Else VSDGCABECALHO   ="S"
                                 VSDGNOMCABECALHO="SIM"
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
       MSG_CAMPO=" "
  Case Campo="TG_CABECALHO":
     MSG_CAMPO="N = N„o  S = Sim"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGTOTAL =""
VSDGSTATUS=""

While True

  ShowDialog "Relat¢rio de Clientes por Representante" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 06,12   Height 19 Width 56

    Label  @ 01,00 "Representante"  For "TG_REPRESEN"
    Accept @ 02,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN" To VSDGREPRESEN
    Accept @ 02,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMREPR"  To VSDGNOMREPR

    Label  @ 03,00 "Status do Cliente" For "TG_STATUS"
    Accept @ 04,01 Width 04 "A1"  Picture "1,2,3" Tag "TG_STATUS" To VSDGSTATUS
    Accept @ 04,06 Width 23 "A12" Picture "!*!" Tag "TG_NOMSTATUS" To VSDGNOMSTATUS

    Label  @ 05,00 "Op‡äes "  For "TG_RELATORIO"
    RadioButtons @ 06,02 Height 5 Width 40
      "1=Listagem de Clientes",
      "2=Cadastro de Clientes",
      "3=Cadastro de ClientesII",
      "4=Cad.Clientes c/Ender.Entreg./Cobr.",
      "5=Listagem de Clientes/Bairro"
    Tag "TG_RELATORIO"
    To VSDGRELATORIO

    Label  @ 11,00 "Cabecalho" For "TG_CABECALHO"
    Accept @ 12,01 Width 04 "A1"  Picture "S,N" Tag "TG_CABECALHO" To VSDGCABECALHO
    Accept @ 12,06 Width 07 "A3"  Picture "SIM,NAO" Tag "TG_NOMCABECALHO" To VSDGNOMCABECALHO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Usuario_Vendedor() Then Loop EndIf  

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  Aguarde("Aguarde, Selecionando Registros")
  Seleciona()

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

  AGUARDE("Aguarde, Gerando Relat¢rio")

  Switch
    Case VSDGRELATORIO=1                       : CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat"  "9" "Answer" "R"
    Case VSDGRELATORIO=2 And VSDGCABECALHO="S" : CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat"  "5" "Answer" "R"
    Case VSDGRELATORIO=2 And VSDGCABECALHO="N" : CopyReport "\\Base\\Sistemas\\Cadastro\\RC_0040B"  "R" "Answer" "R"
    Case VSDGRELATORIO=3 And VSDGCABECALHO="S" : CopyReport "\\Base\\Sistemas\\Cadastro\\RC_0040B"  "4" "Answer" "R"
    Case VSDGRELATORIO=3 And VSDGCABECALHO="N" : CopyReport "\\Base\\Sistemas\\Cadastro\\RC_0040B"  "5" "Answer" "R"
    Case VSDGRELATORIO=4 And VSDGCABECALHO="S" : CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "11" "Answer" "R"
    Case VSDGRELATORIO=4 And VSDGCABECALHO="N" : CopyReport "\\Base\\Sistemas\\Cadastro\\RC_0040B"  "1" "Answer" "R"
    Case VSDGRELATORIO=5                       : CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "10" "Answer" "R"
      
  EndSwitch

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
