;** Rm_3210 ********************************************************************
;* Curva ABC Clientes                                                          *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 26/02/2018 por Anivel Augusto Rodrigues
;Ultima Alteracao: 26/02/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Nova logica novos relatorios    
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()
;Ultima Alteracao: 30/10/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado novo relatorio

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  
   Then AoCriarShowDialog()
        TiraSombraShowDialog()
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_EMPRESATE"     : Campo="NO"
            Case Campo="TG_GERENCIA"      :Campo="TG_EMPRESATE"
            Case Campo="TG_REPRESEN"      :Campo="TG_GERENCIA"
            Case Campo="TG_AREA"          :Campo="TG_REPRESEN"
            Case Campo="TG_MARCA"         :Campo="TG_AREA"
            Case Campo="TG_FAMI"          :Campo="TG_MARCA"
            Case Campo="TG_GRP"           :Campo="TG_FAMI"
            Case Campo="TG_DTINI"         : Campo="TG_GRP"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_CURVAABCA"     : Campo="TG_DTFIM"
            Case Campo="TG_CURVAABCB"     : Campo="TG_CURVAABCA"
            Case Campo="TG_CURVAABCC"     : Campo="TG_CURVAABCB"
            Case Campo="TG_OPANALISE4"    : Campo="TG_CURVAABCC"
            Case Campo="TG_COMVALOR"      : Campo="TG_OPANALISE4"
            Case Campo="TG_CODMODELO"     : Campo="TG_COMVALOR"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESATE"
          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_EMPRESATE"   :Campo="TG_GERENCIA"
                    Case Campo="TG_GERENCIA"    :Campo="TG_REPRESEN"
                    Case Campo="TG_REPRESEN"    :Campo="TG_AREA"
                    Case Campo="TG_AREA"        :Campo="TG_MARCA"
                    Case Campo="TG_MARCA"       :Campo="TG_FAMI"
                    Case Campo="TG_FAMI"        :Campo="TG_GRP"
                    Case Campo="TG_GRP"         :Campo="TG_DTINI"
                    Case Campo="TG_DTINI"       :Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"       :Campo="TG_CURVAABCA"
                    Case Campo="TG_CURVAABCA"   :Campo="TG_CURVAABCB"
                    Case Campo="TG_CURVAABCB"   :Campo="TG_CURVAABCC"
                    Case Campo="TG_CURVAABCC"   :Campo="TG_OPANALISE4"
                    Case Campo="TG_OPANALISE4"  :Campo="TG_COMVALOR"
                    Case Campo="TG_COMVALOR"    :Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"   :Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPCOES" :
     MensagemCheckBoxes()
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 CĒdigo da Pessoa")
ModeloRelatoriosAdd("03  Por Representante")
ModeloRelatoriosAdd("24  Por Representante/CĒdigo da Pessoa")
ModeloRelatoriosAdd("2B  Por Representante/CĒdigo da Pessoa II(Repres.NoCadastroDoCliente)")
ModeloRelatoriosAdd("90  Por Representante/FamĄlia/CĒdigo da Pessoa")
ModeloRelatoriosAdd("97  Por ĩrea/CĒdigo da Pessoa")
ModeloRelatoriosAdd("02  Por UF/CĒdigo da Pessoa")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

sys_valor()

VSDGEMPRESA =""
VSDGMARCA   =""
VSDGFAMI    =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()

VSDGCURVAABCA =20
VSDGCURVAABCB =30
VSDGCURVAABCC =50  
VSDGOPANALISE3=""
VSDGCOMVALOR  =""

ModeloRelatoriosCarregaLista()

While True
  ShowDialog "Curva ABC das Vendas por Clientes" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
    @ 01,00 Height 22 Width 80

    Label  @ 00,00 "Empresa"  For "TG_EMPRESATE"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESATE"    To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP
    
    Label  @ 02,00 "Gerncia " For "TG_GERENCIA"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_GERENCIA" To VSDGGERENCIA
    Accept @ 03,09 Width 25 "A10"  Picture "!*!" Tag "TG_DESCGERENCIA" To VSDGDESCGERENCIA    

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

    Label  @ 06,00 "Area"  For "TG_AREA"
    Accept @ 07,01 Width 07 "A2"  Picture "#*#" Tag "TG_AREA"     To VSDGAREA
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMAREA"  To VSDGNOMAREA    

    Label  @ 08,00 "Marca"  For "TG_MARCA"
    Accept @ 09,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 09,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA
    
    Label  @ 10,00 "Familia"  For "TG_FAMI"
    Accept @ 11,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI"    To VSDGFAMI
    Accept @ 11,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

    Label  @ 12,00 "Grupo"  For "TG_GRP"
    Accept @ 13,02 Width 06 "A3"  Picture "#*#" Tag "TG_GRP"    To VSDGGRP
    Accept @ 13,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 14,00 "PerĄodo Referente de" For "TG_DTINI"
    Accept @ 15,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 15,16 "at" For "TG_DTFIM"
    Accept @ 15,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

           @ 00,36 ?? "Informe % por Classe"    
    Label  @ 01,35 "Classe [A]%"                    For "TG_CURVAABCA"
    Accept @ 01,48 Width 06 "S" Tag "TG_CURVAABCA"  To  VSDGCURVAABCA

    Label  @ 02,35 "Classe [B]%"                    For "TG_CURVAABCB"
    Accept @ 02,48 Width 06 "S" Tag "TG_CURVAABCB"  To  VSDGCURVAABCB

    Label  @ 03,35 "Classe [C]%"                    For "TG_CURVAABCC"
    Accept @ 03,48 Width 06 "S" Tag "TG_CURVAABCC"  To  VSDGCURVAABCC
           
    Label  @ 04,35 "Opo p/ An lise" For "TG_OPANALISE4"
    Accept @ 05,39 Width 04 "A1"  Picture "#" Tag "TG_OPANALISE4" To VSDGOPANALISE
    Accept @ 05,44 Width 25 "A25" Picture "!*!" Tag "TG_NOMOPANALISE" To VSDGNOMOPANALISE

    Label  @ 06,35 "Opo de Valor" For "TG_COMVALOR"
    Accept @ 07,39 Width 04 "A1"  Picture "1,2" Tag "TG_COMVALOR" To VSDGCOMVALOR
    Accept @ 07,44 Width 25 "A10"  Picture "!*!" Tag "TG_NOMCOMVALOR" To VSDGNOMCOMVALOR

    Label  @ 17,00  "Modelo de ~R~elatĒrio"  For "TG_CODMODELO"
    Accept @ 18,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 18,06  Width 47 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO        

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf
  if not ValidarModelosRelatorios() then loop endif         

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  If VSDGEMPRESA="0000"
     Then VSDGEMPRESA2=""
     Else VSDGEMPRESA2=VSDGEMPRESA
  EndIf

  DISPOSITIVO()
  If OK=""  Then Loop EndIf
  If Ok="A" Then IMPRIME_ARQUIVO = True Else IMPRIME_ARQUIVO=False EndIf

  switch
    case VSDGCODMODELO="01" : Play "RM_3210A"
    case VSDGCODMODELO="24" : Play "RM_3210B"
    case VSDGCODMODELO="2B" : Play "RM_3210B"
    case VSDGCODMODELO="90" : Play "RM_3210C"
    case VSDGCODMODELO="97" : Play "RM_3210D"
    case VSDGCODMODELO="02" : Play "RM_3210E"
    case VSDGCODMODELO="03" : Play "RM_3210F"
  endswitch

EndWhile
ClearAll
Release Vars All
Release Procs All
