;** Rm_0270 ********************************************************************
;*  Consumo                                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 13/07/2018 por Anivel Augusto Rodrigues
;Ultima Alteracao: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   
;Ultima Alteracao: 14/05/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_OPCCUSTO            
;Ultima Alteracao: 30/07/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ask tipo do item nova fun‡Æo
;Ultima Alteracao: 04/08/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_EMPRESATE"  : Campo="NO"
            Case Campo = "TG_TIPOEST"    : Campo = "TG_EMPRESATE"
            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_REQUISIT"   : Campo = "TG_REFERENCIA"
            Case Campo = "TG_CCUSTO"     : Campo = "TG_REQUISIT"
            Case Campo = "TG_OPCCUSTO"   : Campo = "TG_CCUSTO"
            Case Campo = "TG_DTINI"      : Campo = "TG_OPCCUSTO"
            Case Campo = "TG_DTFIM"      : Campo = "TG_DTINI"
            Case Campo = "TG_OPRELCODALFRANK2"      : Campo = "TG_DTFIM"
            Case Campo = "TG_CODMODELO"             : Campo = "TG_OPRELCODALFRANK2"
            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_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_REQUISIT"
                    Case Campo = "TG_REQUISIT"   : Campo = "TG_CCUSTO"
                    Case Campo = "TG_CCUSTO"     : Campo = "TG_OPCCUSTO"
                    Case Campo = "TG_OPCCUSTO"   : Campo = "TG_DTINI"
                    Case Campo = "TG_DTINI"      : Campo = "TG_DTFIM"
                    Case Campo = "TG_DTFIM"      : Campo = "TG_OPRELCODALFRANK2"
                    Case Campo = "TG_OPRELCODALFRANK2" : Campo = "TG_CODMODELO"
                    Case Campo = "TG_CODMODELO"        : Campo = "YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
   Case Campo="":
        MSG_CAMPO=""
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

TG_CODMODELO_COMCASASDECIMAIS=true

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("14 - Por Tipo Item/C¢digo do Item")
ModeloRelatoriosAdd("13 - Por Tipo Item/Fam¡lia/C¢digo do Item")
ModeloRelatoriosAdd("13B- Por Tipo Item/Fam¡lia")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("50 - Por Tipo Item/Referˆncia")
ModeloRelatoriosAdd("50B- Por Tipo Item/Fam¡lia/Referˆncia")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("12 - Por Requisitante/Tipo Item/Fam¡lia/C¢digo do Item")
ModeloRelatoriosAdd("12B- Por Requisitante/Tipo Item/Fam¡lia")
ModeloRelatoriosAdd("12C- Por Requisitante")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("33 - Por Centro de Custo/C¢digo do Item [S¢ Aplica‡Æo Direta]")
ModeloRelatoriosAdd("33B- Por Centro de Custo                [S¢ Aplica‡Æo Direta]")

ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

sys_Valor()

VSDGEMPRESA = ""
VSDGTIPOEST = ""
VSDGFAMI    = ""
VSDGGRP     = ""
VSDGMARCA   = ""
VSDGITEM    = ""
VSDGREFERENCIA= ""
VSDGREQUISIT= ""
VSDGCCUSTO  = ""
VSDGDTINI   = BlankDate()
VSDGDTFIM   = BlankDate()
VSDGOPRELCODALFRANK2=""

Array CheckTG_OPCCUSTO[1] CheckTG_OPCCUSTO[1]=False

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Relat¢rios Saidas por Consumo - Requisi‡äes" 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 "Tipo do Estoque"  For "TG_TIPOEST"
    Accept @ 03,04 Width 04 "A1"  Picture "!" Tag "TG_TIPOEST" To VSDGTIPOEST
    Accept @ 03,09 Width 25 "A30"  Picture "!*!" Tag "TG_DESCTIPOEST" To VSDGDESCTIPOEST

    Label  @ 04,00 "Familia"  For "TG_FAMI"
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI" To VSDGFAMI
    Accept @ 05,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

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

    Label  @ 08,00 "Marca"  For "TG_MARCA"
    Accept @ 09,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 09,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 10,00 "Item"  For "TG_ITEM"
    Accept @ 11,01 Width 13 "A10" Picture "#*#" Tag "TG_ITEM"     To VSDGITEM
    Accept @ 12,01 Width 33 "A35" Picture "!*!" Tag "TG_NOMITEM" To VSDGNOMITEM

    Label  @ 10,13 "Referˆncia"  For "TG_REFERENCIA"
    Accept @ 11,13 Width 21 "A20" Picture "!*!" Tag "TG_REFERENCIA"     To VSDGREFERENCIA

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

    Label  @ 00,35 "CentroDeCusto" For "TG_CCUSTO"
    Accept @ 01,36 Width 33 "A7"  Picture "###.###" Tag "TG_CCUSTO" To VSDGCCUSTO
    Accept @ 02,36 Width 33 "A20" Picture "!*!" Tag "TG_NOMCUST"  To VSDGNOMCUST

    CheckBoxes @ 00,49 Height 1 Width 20 Tag "TG_OPCCUSTO" "NÆoVerEmBrancos" to CheckTG_OPCCUSTO[1]

    Label  @ 04,35 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 05,38 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 05,51 "at‚" For "TG_DTFIM"
    Accept @ 05,56 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 06,35 "Op‡„o de Ordem" For "TG_OPRELCODALFRANK2"
    Accept @ 07,39 Width 04 "A1"  Picture "1,2,3,4" Tag "TG_OPRELCODALFRANK2" To VSDGOPRELCODALFRANK2
    Accept @ 07,44 Width 25 "A25"  Picture "!*!" Tag "TG_NOMOPRELCODALFRANK2" To VSDGNOMOPRELCODALFRANK2

    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 VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

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

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando o Relat¢rio")
  switch
    case VSDGCODMODELO="14"  : Play "RM_0270A"
 
    case VSDGCODMODELO="13"  : Play "RM_0270B"
    case VSDGCODMODELO="13B" : Play "RM_0270C"
 
    case VSDGCODMODELO="12"  : Play "RM_0270D"
    case VSDGCODMODELO="12B" : Play "RM_0270E"
    case VSDGCODMODELO="12C" : Play "RM_0270H"
    
    case VSDGCODMODELO="50"  : Play "RM_0270F"
    case VSDGCODMODELO="50B" : Play "RM_0270G"
 
    case VSDGCODMODELO="33"  : Play "RM_0270I"
    case VSDGCODMODELO="33B" : Play "RM_0270J"
 
  endswitch

EndWhile
ClearAll
Release Vars All
Release Procs All

