;** Rc_0011 ********************************************************************
;*  Opcao de Relatorio para Fornecedores                                       *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/10/2003 por Karen Lauar Nery
;Ultima Alteracao: 12/09/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Inclusao LCE - MODELO P10
;Ultima Alteracao: 09/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 27/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog                  
;Ultima Alteracao: 06/04/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado Destobs 

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

{Ask} {Destinat} Check
Moveto [Codigo          ] TypeIn "_codigo!, >=~VSDGDESTINATINI,<=~VSDGDESTINATFIM"
Moveto [Tipo            ] TypeIn "F"
Moveto [Codigo Atividade] TypeIn "~VSDGATIVIDADE.."
If Not IsBlank (VSDGESTADO)
   Then Moveto [UF      ] TypeIn "~VSDGESTADO"
EndIf 
Moveto [Inativo         ]
Switch
  Case VSDGSTATUS="1": TypeIn "N"
  Case VSDGSTATUS="2": TypeIn "S"
EndSwitch
{Ask} {Destobs} Check
Moveto [Codigo          ] check TypeIn "_codigo"
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_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_DESTINATINI"    : Campo="NO"
            Case Campo="TG_DESTINATFIM"    : Campo="TG_DESTINATINI"
            Case Campo="TG_STATUS"         : Campo="TG_DESTINATFIM"
            Case Campo="TG_ATIVIDADE"      : Campo="TG_STATUS"
            Case Campo="TG_ESTADO"         : Campo="TG_ATIVIDADE"
            Case Campo="TG_OPRELLISTCAD"   : Campo="TG_ESTADO"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_OPRELLISTCAD"
            Case Campo="TG_CODMODELO"      : Campo="TG_OPRELCODALF"
            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_ATIVIDADE"
                    Case Campo="TG_ATIVIDADE"   : Campo="TG_ESTADO"
                    Case Campo="TG_ESTADO"      : Campo="TG_OPRELLISTCAD"
                    Case Campo="TG_OPRELLISTCAD":
                         If Not IsBlank(VSDGOPRELLISTCAD)
                            Then Switch
                                    Case VSDGOPRELLISTCAD="1":
                                         VSDGNOMOPRELLISTCAD="LISTAGEM DE FORNECEDOR"
                                    Case VSDGOPRELLISTCAD="2":
                                         VSDGNOMOPRELLISTCAD="CADASTRO DE FORNECEDOR"
                                    OtherWise:
                                         VSDGOPRELLISTCAD   =""
                                         VSDGNOMOPRELLISTCAD=""
                                 EndSwitch
                         EndIf
                         If Not IsBlank(VSDGOPRELLISTCAD)
                            Then 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_OPRELLISTCAD":
     MSG_CAMPO="1-Listagem de Fornecedor  2-Cadastro de Fornecedor"
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  Listagem de Fornecedores")
ModeloRelatoriosAdd("02  Cadastro de Fornecedores")
ModeloRelatoriosAdd("03  Listagem de Fornecedores por Atividade")
ModeloRelatoriosAdd("04  Cadastro de Fornecedores por Atividade")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("05  Lista de CĒdigos de Emitentes - LCE - Modelo P10")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista


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

VSDGDESTINATINI    =""
VSDGDESTINATFIM    =""
VSDGSTATUS         =""
VSDGNOMSTATUS      =""
VSDGATIVIDADE      =""
VSDGNOMATIV        =""
VSDGESTADO         =""
VSDGNOMESTADO      =""
VSDGOPRELLISTCAD   =""
VSDGNOMOPRELLISTCAD=""
VSDGOPRELCODALF    =""
VSDGNOMOPRELCODALF =""

DESCTP           ="Fornecedores"

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "RelatĒrio de Fornecedores" 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 16 Width 72

    Label  @ 00,00 "Intervalo CĒdigo de"  For "TG_DESTINATINI"
    Accept @ 01,01 Width 14 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATINI" To VSDGDESTINATINI
    Label  @ 01,15 "at"  For "TG_DESTINATFIM"
    Accept @ 01,20 Width 14 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATFIM" To VSDGDESTINATFIM

    Label  @ 02,00 "Status do Fornecedor" For "TG_STATUS"
    Accept @ 03,04 Width 04 "A1"  Picture "1,2,3" Tag "TG_STATUS" To VSDGSTATUS
    Accept @ 03,09 Width 25 "A12" Picture "!*!" Tag "TG_NOMSTATUS" To VSDGNOMSTATUS
    
    Label  @ 04,00 "Atividade"  For "TG_ATIVIDADE"
    Accept @ 05,01 Width 07 "A4"  Picture "!*!" Tag "TG_ATIVIDADE" To VSDGATIVIDADE
    Accept @ 05,09 Width 25 "A30"  Picture "#*#" Tag "TG_NOMATIV" To VSDGNOMATIV
    
    Label  @ 06,00 "Estado"  For "TG_ESTADO"
    Accept @ 07,01 Width 07 "A2"  Picture "!*!" Tag "TG_ESTADO" To VSDGESTADO
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMESTADO"  To VSDGNOMESTADO

    Label  @ 00,35 "Opo" For "TG_OPRELLISTCAD"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELLISTCAD" To VSDGOPRELLISTCAD
    Accept @ 01,44 Width 25 "A30" Picture "!*!" Tag "TG_NOMOPRELLISTCAD" To VSDGNOMOPRELLISTCAD

    Label  @ 02,35 "Ordem" For "TG_OPRELCODALF"
    Accept @ 03,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 03,44 Width 25 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF
    
    Label  @ 09,00  "Modelo de ~R~elatĒrio"  For "TG_CODMODELO"
    Accept @ 10,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 10,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO  

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  
  If  VSDGCODMODELO<>"05"
      Then
           DISPOSITIVO()
           If OK="" Then Loop EndIf
      Else Play "Rc_0081" QuitLoop
  EndIf    

  AGUARDE("Aguarde, Gerando RelatĒrio")
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("No Existem Registros a Processar")
          Loop
  EndIf

  Switch
      Case VSDGCODMODELO="01"     :    CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "1"  "Answer" "R"
      Case VSDGCODMODELO="02"     :    CopyReport "\\Base\\Sistemas\\Cadastro\\Destinat" "3"  "Answer" "R"
      Case VSDGCODMODELO="03"     :    CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0040" "7" "Answer" "R"
      Case VSDGCODMODELO="04"     :    CopyReport "\\Base\\Sistemas\\Cadastro\\Rc_0031" "5" "Answer" "R"                                                       
                                                                    
  EndSwitch    
                                                                       
  IMPRIREL("Answer","R")

  Delete "Answer"


EndWhile
ClearAll
Release Vars All
Release Procs All
