;** Rm_0055  *******************************************************************
;*  Conferencia das requisicoes por periodo/usuario/controle                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 02/02/2005 por Nikolas M. Mateus
;Motivo Alteracao: Selecao por usuario e n£mero de controle
;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: 18/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 05/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_NCONTROLE                   
;Ultima Alteracao: 27/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   

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

If IsTable("\\Sistemas\\Estoque\\"+Dir_Trab+"RqCabeca") And
   IsTable("\\Sistemas\\Estoque\\"+Dir_Trab+"RqItem")
   Then {Ask} TypeIn "\\Sistemas\\Estoque\\"+Dir_Trab+"RqCabeca" Enter Check
        Moveto [Numero do Lancamento] Example "LANCTO"
        Moveto [Codigo da Empresa   ] TypeIn "~VSDGEMPRESA.."
        Moveto [Codigo_Usuario      ] TypeIn "~VSDGCHAPA.."
        Moveto [Numero_Controle_Dia ] TypeIn "~VSDGNCONTROLE.."

        If IsBlank(VSDGNCONTROLE)
            Then Moveto [Data_Inclusao] TypeIn ">=~VSDGDTINI ,<=~VSDGDTFIM"
        EndIf

        {Ask} TypeIn "\\Sistemas\\Estoque\\"+Dir_Trab+"RqItem" Enter Check
        Moveto [Numero do Lancamento] Example "LANCTO"
        Do_It!
        ClearAll

        If IsTable(Tabela)
           Then Add "Answer" Tabela
           Else Rename "Answer" Tabela
        EndIf
EndIf

If IsTable("\\Sistemas\\Estoque\\"+Dir_Trab+"RqCabeca") And
   IsTable("\\Sistemas\\Estoque\\"+Dir_Trab+"RqMatPri")
   Then {Ask} TypeIn "\\Sistemas\\Estoque\\"+Dir_Trab+"RqCabeca" Enter Check
        Moveto [Numero do Lancamento] Example "LANCTO"
        Moveto [Codigo da Empresa   ] TypeIn "~VSDGEMPRESA.."
        Switch
          Case (VSDGTPMOV="S" Or VSDGTPMOV="") And (VSDGTPOPE="C" Or VSDGTPOPE=""):
                Moveto [Tipo de Movimento   ] TypeIn "E"
                Moveto [Tipo de Operacao    ] TypeIn "P Or I"
         OtherWise:
                Moveto [Tipo de Movimento   ] TypeIn "X"
                Moveto [Tipo de Operacao    ] TypeIn "X"
        EndSwitch

        If IsBlank(VSDGNCONTROLE)
            Then Moveto [Data_Inclusao] TypeIn ">=~VSDGDTINI ,<=~VSDGDTFIM"
        EndIf

        {Ask} TypeIn "\\Sistemas\\Estoque\\"+Dir_Trab+"RqMatPri" Enter Check
        Moveto [Numero do Lancamento] Example "LANCTO"
        Moveto [Sequencia do Item   ] Check
        Do_It!
        ClearAll

        If Not IsEmpty("Answer")
           Then {Ask} {Answer} TypeIn "Fast"
                Moveto [Tipo de Movimento   ] TypeIn "Changeto S"
                Moveto [Tipo de Operacao    ] TypeIn "Changeto C"
                Do_It!
                ClearAll

                If IsTable(Tabela)
                   Then Add "Answer" Tabela
                   Else Rename "Answer" Tabela
                EndIf
        EndIf
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_EMPRESA"       : Campo="NO"
            Case Campo="TG_NCONTROLE"     : Campo="TG_EMPRESA"
            Case Campo="TG_CHAPA"         : Campo="TG_NCONTROLE"
            Case Campo="TG_DTINI"         : Campo="TG_CHAPA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="YES" Or Campo="NO": Campo="TG_NCONTROLE"
          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_NCONTROLE"
                    Case Campo="TG_NCONTROLE" :
                         If IsBlank(VSDGNCONTROLE)
                            Then Campo="TG_CHAPA"
                            Else VSDGCHAPA    =""
                                 VSDGNOMCHAPA =""
                                 VSDGDTINI    =BlankDate()
                                 VSDGDTFIM    =BlankDate()

                                 Campo="YES"
                         EndIf
                    Case Campo="TG_CHAPA"     : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"     : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"     : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_CHAPA":
     MSG_CAMPO="Informe um codigo de usuario !"
Endswitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA   =""
VSDGTPMOV     =""
VSDGTPOPE     =""
VSDGCHAPA     =""
VSDGNCONTROLE =""
VSDGDTINI     =BlankDate()
VSDGDTFIM     =BlankDate()
While True
  ShowDialog "Conferencia de Requisi‡äes por Usuario" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 13 Width 72

    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_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Controle Dia" For "TG_NCONTROLE"
    Accept @ 03,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 03,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMNCONTROLE" To VSDGNOMNCONTROLE

    Label  @ 04,00 "Usu rio" For "TG_CHAPA"
    Accept @ 05,01 Width 07 "A4"  Picture "#*#" Tag "TG_CHAPA" To VSDGCHAPA
    Accept @ 05,09 Width 25 "A30" Picture "!*!" Tag "TG_CHAPA" To VSDGNOMCHAPA

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

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf

   If VSDGDTFIM=BlankDate() And IsBlank(VSDGNCONTROLE)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  Tabela=Cria_Temp(PrivDir())

  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    Seleciona()
  EndWhile

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o existem registros a processar")
          Delete Tabela
          Loop
  EndIf

  CopyReport "\\Base\\Sistemas\\Estoque\\RM_0050" "1" Tabela "1"

  IMPRIREL(Tabela,"1")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
