;** RM_0050  *******************************************************************
;*  Rela‡Æo de Requisi‡äes                                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 02/08/2006 por Nikolas M. Mateus
;Motivo Alteracao: Acrescimo campo escolher requisitante
;Ultima Alteracao: 29/03/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 30/01/2015 por Luis Gustavo
;Motivo Alteracao: Implementado Filtro por Referencia e por Marca
;Ultima Alteracao: 02/10/2015 por Bruno Carvalho  
;Motivo Alteracao: Incluido "I" no [Tipo de Operacao] para fornecer registros quando for requisi‡äes de Industrializa‡Æo
;Ultima Alteracao: 01/02/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Ask Itens
;Ultima Alteracao: 18/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 28/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog           
;Ultima Alteracao: 29/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes MensagemCheckBoxes()        
;Ultima Alteracao: 27/01/2017 por Anivel Augusto Rodrigues 
;Motivo Alteracao: Ajustes TG_REFERENCIA
;Ultima Alteracao: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   
;Ultima Alteracao: 27/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes agrupamento RM_0050A, RM_0050B, RM_0050C
;Ultima Alteracao: 27/04/2020 por Bruno Carvalho            
;Motivo Alteracao: Adicionado "Bib_Proc"

;*******************************************************************************
;* 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_EMPRESA"        : Campo="NO"
            Case Campo="TG_NLANCINI"       : Campo="TG_EMPRESA"
            Case Campo="TG_NLANCFIM"       : Campo="TG_NLANCINI"
            Case Campo="TG_TPMOV"          : Campo="TG_NLANCFIM"
            Case Campo="TG_TPOPE"          : Campo="TG_TPMOV"
            Case Campo="TG_REQUISIT"       : Campo="TG_TPOPE"
            Case Campo="TG_DTINI"          : Campo="TG_REQUISIT"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_TIPOEST"        : Campo="TG_DTFIM"
            Case Campo="TG_FAMI"           : Campo="TG_TIPOEST"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_ITEM"           : Campo="TG_MARCA"
            Case Campo="TG_REFERENCIA"     : Campo="TG_ITEM"
            Case Campo="TG_CODMODELO"      : Campo="TG_REFERENCIA"
            Case Campo="YES" Or Campo="NO" : Campo="TG_EMPRESA"
          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_EMPRESA"  : Campo="TG_NLANCINI"

                    Case Campo="TG_NLANCINI" : Campo="TG_NLANCFIM"
                         VSDGNLANCINI=AlinhM(ControlVAlue("TG_NLANCINI"),6)

                    Case Campo="TG_NLANCFIM" : Campo="TG_TPMOV"
                         VSDGNLANCFIM=ControlVAlue("TG_NLANCFIM")
                         If Not IsBlank(VSDGNLANCFIM)
                            Then VSDGNLANCFIM=AlinhM(VSDGNLANCFIM,6)
                            Else VSDGNLANCFIM = "999999"
                         Endif

                    Case Campo="TG_TPMOV"    : Campo="TG_TPOPE"
                         VSDGTPMOV=ControlVAlue("TG_TPMOV")
                         switch
                           case VSDGTPMOV="E" : VSDGNOMTPMOV = "ENTRADA"
                           case VSDGTPMOV="S" : VSDGNOMTPMOV = "SAIDA"
                           otherwise          : VSDGNOMTPMOV = "TODOS"
                         endswitch
                    Case Campo="TG_TPOPE"    : Campo="TG_REQUISIT"
                         VSDGTPOPE = ControlValue("TG_TPOPE")
                         Switch
                            Case VSDGTPOPE = "C": VSDGNOMTPOPE = "CONSUMO"
                            Case VSDGTPOPE = "T": VSDGNOMTPOPE = "TRANSFERENCIA"
                            Case VSDGTPOPE = "P": VSDGNOMTPOPE = "PRODUCAO"
                            Case VSDGTPOPE = "I": VSDGNOMTPOPE = "INDUSTRIALIZACAO"     
                            Case VSDGTPOPE = "O": VSDGNOMTPOPE = "OUTROS"
                            Case VSDGTPOPE = "D": VSDGNOMTPOPE = "DEVOLUCAO"
                            Otherwise           : VSDGNOMTPOPE = "TODAS"
                         EndSwitch
                    Case Campo="TG_REQUISIT"   : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_TIPOEST"
                    Case Campo="TG_TIPOEST"    : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"       : Campo="TG_GRP"
                    Case Campo="TG_GRP"        : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"      : Campo="TG_ITEM"
                    Case Campo="TG_ITEM"       : Campo="TG_REFERENCIA"
                    Case Campo="TG_REFERENCIA" : Campo="TG_CODMODELO"   
                    Case Campo="TG_CODMODELO"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
    Case Campo = ""         : MSG_CAMPO = ""
    Case Campo = "TG_TPMOV" : MSG_CAMPO = "Em Branco=Todos, E=Entrada S=Sa¡da"
    Case Campo = "TG_TPOPE" : MSG_CAMPO = "Em Branco=Todas, C=Consumo P=Producao I=Indust. T=Transf. D=Devol. O=Outros"
    Case Campo="TG_OPGRREF" : 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("08  Por Requisitante/Requisi‡Æo/Item")
ModeloRelatoriosAdd("08A Por Requisitante/Requisi‡Æo/Item - Agrupado por Referˆncia")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("46  Por Requisi‡Æo/Referˆncia   - Modo GRADE- s¢ ENTRADA/PRODU€¶O")
ModeloRelatoriosAdd("18  Por Requisi‡Æo/Conferˆncia! - Modo GRADE- s¢ ENTRADA/PRODU€¶O")
ModeloRelatoriosAdd("Fim")

EndProc ;ModeloRelatoriosCarregaLista

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

sys_valor()

VSDGEMPRESA  = ""
VSDGNLANCINI = ""
VSDGNLANCFIM = ""
VSDGTPMOV    = ""
VSDGTPOPE    = ""
VSDGREQUISIT = ""
VSDGTIPOEST  = ""
VSDGFAMI     = ""
VSDGMARCA    = ""
VSDGGRP      = ""
VSDGITEM     = ""
VSDGREFERENCIA=""
VSDGDTINI    = BlankDate()
VSDGDTFIM    = BlankDate()

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Rela‡Æo de Requisi‡oes por ?" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 05,05   Height 22 Width 80

    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA"    To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Intervalo de Lan‡amentos de" For "TG_NLANCINI"
    Accept @ 03,03 Width 13 "A6"  Picture "#*#" Tag "TG_NLANCINI" To VSDGNLANCINI
    Label  @ 03,16 "at‚" For "TG_NLANCFIM"
    Accept @ 03,21 Width 13 "A6"  Picture "#*#" Tag "TG_NLANCFIM" To VSDGNLANCFIM

    Label  @ 04,00 "Tipo de Movimento" For "TG_TPMOV"
    Accept @ 05,04 Width 04 "A1"   Picture "E,S" Tag "TG_TPMOV" To VSDGTPMOV
    Accept @ 05,09 Width 25 "A30"  Picture "!*!" Tag "TG_NOMTPMOV" To VSDGNOMTPMOV
    
    Label  @ 06,00 "Tipo de Opera‡„o" For "TG_TPOPE"
    Accept @ 07,04 Width 04 "A1"   Picture "C,P,T,O,D,I" Tag "TG_TPOPE" To VSDGTPOPE
    Accept @ 07,09 Width 25 "A30"  Picture "!*!" Tag "TG_NOMTPOPE" To VSDGNOMTPOPE

    Label  @ 08,00 "Requisitante"  For "TG_REQUISIT"
    Accept @ 09,01 Width 09 "A6"  Picture "#*#" Tag "TG_REQUISIT"  To VSDGREQUISIT
    Accept @ 09,09 Width 25 "A35" Picture "!*!" Tag "TG_NOMREQUI" To VSDGNOMREQUI

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



    Label  @ 00,38 "Tipo do Estoque"  For "TG_TIPOEST"
    Accept @ 01,39 Width 04 "A1"  Picture "!" Tag "TG_TIPOEST" To VSDGTIPOEST
    Accept @ 01,44 Width 25 "A30"  Picture "!*!" Tag "TG_DESCTIPOEST" To VSDGDESCTIPOEST

    Label  @ 02,35 "Familia"  For "TG_FAMI"
    Accept @ 03,37 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI" To VSDGFAMI
    Accept @ 03,44 Width 25 "A25" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

    Label  @ 04,35 "Grupo"  For "TG_GRP"
    Accept @ 05,37 Width 06 "A3"  Picture "#*#" Tag "TG_GRP" To VSDGGRP
    Accept @ 05,44 Width 25 "A25" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 06,35 "Marca"  For "TG_MARCA"
    Accept @ 07,37 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 07,44 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 08,35 "Item"  For "TG_ITEM"
    Accept @ 09,36 Width 13 "A10" Picture "#*#" Tag "TG_ITEM"     To VSDGITEM
    Accept @ 10,36 Width 33 "A35" Picture "!*!" Tag "TG_NOMITEM" To VSDGNOMITEM

    Label  @ 08,48 "Referˆncia"  For "TG_REFERENCIA"
    Accept @ 09,48 Width 21 "A20" Picture "!*!" Tag "TG_REFERENCIA"     To VSDGREFERENCIA


    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

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  Impressao_Orientacao=""
  Switch
    Case VSDGCODMODELO="08" or
         VSDGCODMODELO="08A":  Play "RM_0050A"
    
    Case VSDGCODMODELO="46" :  Play "RM_0050B"

    Case VSDGCODMODELO="18" :  Play "RM_0050C"

    otherwise               : Play "RM_00XXA"

  EndSwitch

EndWhile
ClearAll
Release Vars All
Release Procs All
