;** Rm_0100  *******************************************************************
;* Relacao de Pedidos por Entrega                                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 17/06/2009 por Anivel Augusto Rodrigues
;Ultima Alteracao: 18/09/2009 por Cleber Alves
;Motivo Alteracao: Alteracao na Ask [Codigo da Empresa ]
;Ultima Alteracao: 06/12/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes de criterios

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

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item   ] Example "ITEM"
Moveto [Codigo da Marca  ] TypeIn "~VSDGMARCA.."

{Ask} {\\Sistemas\\Vendas\\Destin}
Moveto [Codigo da Destinacao  ] Example "cd"
Moveto [Tipo Movimento Estoque] TypeIn "S"

{Ask} {\\Sistemas\\Vendas\\PedidoC} Check
Moveto [Numero do Pedido] Example "Pedido"
Moveto [Codigo da Empresa ] TypeIn "~VSDGEMPRESA.."
Moveto [Data de Entrega   ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
Moveto [Codigo da Destinacao  ] Example "cd"
Moveto [Situacao do Pedido    ] TypeIn "ABERTO"

{Ask} {\\Sistemas\\Vendas\\PedidoI} Check
Moveto [Numero do Pedido  ] Example "Pedido"
Moveto [Codigo do Item    ] Example "ITEM"
Do_It!
ClearAll

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_MARCA"         : Campo="TG_EMPRESA"
            Case Campo="TG_DTINI"         : Campo="TG_MARCA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            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_MARCA"
                    Case Campo="TG_MARCA"           : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"           : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"           : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO=""
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA=""
VSDGMARCA  = ""
VSDGDTINI            =BlankDate()
VSDGDTFIM            =BlankDate()

While True

  ShowDialog "Rela‡„o de Pedidos por Entrega" 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 11 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_NOMEMPRESA" To VSDGNOMEMP

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

    Label  @ 04,00 "Per¡odo de Entrega" For "TG_DTINI"
    Label  @ 05,00 "de" For "TG_DTINI"
    Accept @ 05,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 05,17 "at‚" For "TG_DTFIM"
    Accept @ 05,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  Seleciona()

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

  CopyReport "\\Base\\Sistemas\\Producao\\Rm_0100" "R" "Answer" "R"

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
