;** Rm_0400  *******************************************************************
;*  Emissao de Ordem de Recebimento                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 29/11/2011 por Bruno Carvalho
;Ultima Alteracao: 24/02/2012 por Bruno Carvalho
;Motivo Alteracao: InclusÆo de Filtro por Data de Entrada/Vencimento e Conta

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

If IsTable("\\Sistemas\\Ctarec\\"+Dir_Trab+"Duplic")
  Then {Ask} TypeIn "\\Sistemas\\Ctarec\\"+Dir_Trab+"Duplic" Enter Check
       Moveto [Codigo da Empresa] TypeIn "~VSDGEMPRESA.."
       If IsBlank(VSDGNCONTROLE)
          Then Switch
                 Case VSDGOPRELCODALF="1" :  Moveto [Data_Inclusao     ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
                 Case VSDGOPRELCODALF="2" :  Moveto [Data de Vencimento] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
               EndSwitch  
               Moveto [Codigo da Conta    ] TypeIn "~VSDGCONTA.."
               Moveto [Codigo_Usuario     ] TypeIn "~VSDGCHAPA.."
          Else Moveto [Numero_Controle_Dia] TypeIn "~VSDGNCONTROLE.."
       EndIf
       Do_It!
       ClearAll
EndIf
EndProc  ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA    =""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     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_CONTA"         : Campo="TG_CHAPA"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_CONTA"
            Case Campo="TG_DTINI"         : Campo="TG_OPRELCODALF"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_MODREL"        : Campo="TG_NCONTROLE"
            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_NCONTROLE"
                    Case Campo="TG_NCONTROLE" :
                         If IsBlank(VSDGNCONTROLE)
                            Then Campo="TG_CHAPA"
                            Else VSDGCHAPA      =""  VSDGNOMCHAPA      =""
                                 VSDGCONTA      =""  VSDGNOMCONTA      =""
                                 VSDGOPRELCODALF=""  VSDGNOMOPRELCODALF=""
                                 VSDGDTINI      =BlankDate()
                                 VSDGDTFIM      =BlankDate()

                                 Campo="TG_MODREL"
                         EndIf
                    Case Campo="TG_CHAPA"        : Campo="TG_CONTA"
                    Case Campo="TG_CONTA"        : Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF"  : Campo="TG_DTINI" 
                         VSDGOPRELCODALF=ControlValue("TG_OPRELCODALF")
                         If IsBlank(VSDGOPRELCODALF)
                            Then VSDGOPRELCODALF="1"
                         EndIf
                         Switch
                           Case VSDGOPRELCODALF="1" : VSDGNOMOPRELCODALF="ENTRADA"
                           Case VSDGOPRELCODALF="2" : VSDGNOMOPRELCODALF="VENCIMENTO"
                         EndSwitch       
                    Case Campo="TG_DTINI"     : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"     : Campo="TG_MODREL"
                    Case Campo="TG_MODREL"    : Campo="YES"
                         Switch
                           Case VSDGMODREL="1" : VSDGNOMMODREL="MODELO 1"
                           Case VSDGMODREL="2" : VSDGNOMMODREL="MODELO 2"
                         EndSwitch       
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_OPRELCODALF" : MSG_CAMPO="1=Entrada  2=Vencimento"
  Case Campo="TG_MODREL"      : MSG_CAMPO="1=Modelo 1  2=Modelo 2"
EndSwitch  

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGNCONTROLE=""
VSDGCHAPA    =""
VSDGOPRELCODALF=""
VSDGDTINI    =BlankDate()
VSDGDTFIM    =BlankDate()
VSDGMODREL="1"

While True
  ShowDialog "Emiss„o de Ordem de Recebimento" 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 19 Width 56
   
    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 01,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "N§ Controle Dia" For "TG_NCONTROLE"
    Accept @ 03,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 03,11 Width 33 "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 33 "A30" Picture "!*!" Tag "TG_CHAPA" To VSDGNOMCHAPA

    Label  @ 06,00 "Conta"  For "TG_CONTA"
    Accept @ 07,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 07,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

    Label  @ 08,00 "Por Data de" For "TG_OPRELCODALF"
    Accept @ 09,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 09,06 Width 23 "A20" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Label  @ 10,00 "Periodo Referente" For "TG_DTINI"
    Label  @ 11,00 "de" For "TG_DTINI"
    Accept @ 11,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 11,17 "ate" For "TG_DTFIM"
    Accept @ 11,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 12,00 "Modelo do Relat¢rio" For "TG_MODREL"
    Accept @ 13,01 Width 04 "A1"  Picture "1,2" Tag "TG_MODREL" To VSDGMODREL
    Accept @ 13,06 Width 28 "A25"  Picture "!*!" Tag "TG_NOMMODREL" To VSDGNOMMODREL

    Pushbutton @ 15,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 15,28 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If IsBlank(VSDGNCONTROLE) And IsBlank(VSDGDTFIM)
     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()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    Seleciona()
    If Not IsTable("Answer") Then Loop EndIf
    If IsTable(Tabela)
       Then Add "Answer" Tabela
       Else Rename "Answer" Tabela
    EndIf
  EndWhile

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

  If VSDGMODREL="1"
     Then CopyReport "\\Base\\Sistemas\\CtaRec\\Rm_1002" "8" Tabela "R"
     Else CopyReport "\\Base\\Sistemas\\CtaRec\\Rm_1011" "7" Tabela "R"
  EndIf
 
  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All

