;** Rm_4100  *******************************************************************
;*  Itens Comprados Periodo                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 15/04/2015 por Andrey Fillipe
;Ultima Alteracao: 18/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 27/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 06/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   
;Ultima Alteracao: 08/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   
;Ultima Alteracao: 30/07/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ask tipo do item nova fun‡Æo

;*******************************************************************************
;* Rotina p/ Selecionar Itens Comprados                                        *
;*******************************************************************************
Proc Seleciona()
ClearAll

{Ask} TypeIn "\\Sistemas\\Estoque\\SdEstq" Enter
Moveto [Codigo da Empresa       ] Check TypeIn "~VSDGEMPRESA.."  
Moveto [Codigo do Item          ] Check Example "ite"
Moveto [Data do Preco de Custo  ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM, as Data da Compra"
Moveto [Ano Referencia          ] TypeIn "~ANO"
Moveto [Mes Referencia          ] TypeIn "~MES"
Moveto [Saldo Atual             ] Check TypeIn "Not Blank, Not 0"
Moveto [Preco de Custo          ] Check TypeIn "as Ultimo Custo"
Moveto [Ultimo Custo Atual      ] Check TypeIn "as Custo Medio"
{Ask} TypeIn "\\Sistemas\\Estoque\\Itens" Enter
Moveto [Codigo do Item          ] Example "ite"  
Moveto [Descricao do Item       ] Check
Moveto [Codigo da Marca         ] TypeIn "~VSDGMARCA.."
Moveto [Codigo da Familia       ] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo         ] TypeIn "~VSDGGRP.."
Moveto [Descricao da Marca      ] Check
Moveto [Codigo de Barras        ] Check  
Moveto [Unidade Interna         ] Check
Moveto [Localizacao             ] Check
Do_It!
ClearAll

{Ask} {Answer} Check
Moveto [Codigo do Item          ] Example "ite"
{Ask} TypeIn "\\Sistemas\\Estoque\\EstqPrm" Enter
Moveto [Codigo da Empresa       ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo do Item          ] Example "ite"
Moveto [Data da Ultima Saida    ] Check
Do_It!
ClearAll

{Ask} {Answer} Check
Moveto [Codigo da Empresa       ] Example "cemp" 
{Ask} TypeIn "\\Sistemas\\Cadastro\\Empresas" Enter
Moveto [Codigo da Empresa       ] Example "cemp"  
Moveto [Nome Fantasia Empresa   ] Check
Do_It!
ClearAll

{Ask} {Answer} Check
Moveto [Codigo do Item          ] Example "ite" 
{Ask} TypeIn "\\Sistemas\\Vendas\\Tbprite" Enter
Moveto [Codigo do Item          ] Example "ite"  
Moveto [Codigo da Tabela        ] TypeIn "~VSDGTABELA.."
Moveto [Preco Unitario          ] Check TypeIn "as Preco de Venda"
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_FAMI"           : Campo="TG_EMPRESA"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_TABELA"         : Campo="TG_MARCA"
            Case Campo="TG_DTINI"          : Campo="TG_TABELA"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_MESANO"         : Campo="TG_DTFIM"
            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_FAMI" 
                    Case Campo="TG_FAMI"     : Campo="TG_GRP"
                    Case Campo="TG_GRP"      : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"    : Campo="TG_TABELA"
                    Case Campo="TG_TABELA"   : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"    :
                         If Not IsBlank(VSDGDTINI)
                            Then Campo="TG_DTFIM"
                         EndIf
                    Case Campo="TG_DTFIM"    : Campo="TG_MESANO"
                    Case Campo="TG_MESANO"   : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTINI":
       MSG_CAMPO="Informe a Data Inicial"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA  = ""
VSDGMARCA    = ""
VSDGFAMI     = ""
VSDGGRP      = ""
VSDGDTINI    = BlankDate()
VSDGDTFIM    = Today()
VSDGTABELA   = ""
VSDGMESANO   = AlinhM(StrVal(Month(Today())),2)+"."+AlinhM(StrVal(Year(Today())),4)

While True

  ShowDialog "Itens com Compras no Periodo" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 03,12   Height 17 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_NOMEMPRESA" To VSDGNOMEMP

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

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

    Label  @ 06,00 "Marca"  For "TG_MARCA"
    Accept @ 07,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 07,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA
    
    Label  @ 08,00 "Tabela"  For "TG_TABELA"
    Accept @ 09,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA" To VSDGTABELA
    Accept @ 09,09 Width 25 "A40" Picture "!*!" Tag "TG_NOMTAB" To VSDGNOMTAB
    
    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,35 "Mˆs/Ano Ficha Estoque"  For "TG_MESANO"
    Accept @ 01,36 Width 10 "A7"  Picture "##.####" Tag "TG_MESANO"        To VSDGMESANO

    Pushbutton @ 13,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 13,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 VSDGDTINI=BlankDate()
     Then Mensagem("Data Inicial Invalida !")
          Loop
  EndIf
  If VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf
  If IsBlank(VSDGEMPRESA)
     Then Mensagem("Empresa Invalida !")
          Loop
  EndIf
  If IsBlank(VSDGTABELA)
     Then Mensagem("Tabela de Pre‡o Invalida !")
          Loop
  EndIf

	ANO = SubStr(VSDGMESANO,4,4)
	MES = SubStr(VSDGMESANO,1,2)
	If (NumVal(MES)<1 Or NumVal(MES)>12)
		 Then Mensagem("Mˆs inv lido !")
					Loop
	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")
          Delete "Answer"
          Loop
  EndIf
  
  CopyReport "\\Base\\Sistemas\\Estoque\\Rm_4100" "R" "Answer" "R"

  IMPRIREL("Answer","R")
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
