;** Rc_0113  *******************************************************************
;*  Listagem de Itens/ndices por Marca/Fam¡lia                                *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 26/12/2016 por Rafael Matos            
;Ultima Alteracao: 29/08/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ignorar item inativo                 

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

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo da Marca     ] TypeIn "~VSDGMARCA.." Check
Moveto [Descricao da Marca  ] Check
Moveto [Codigo da Familia   ] TypeIn "~VSDGFAMI.."  Check
Moveto [Descricao da Familia] Check
Moveto [Codigo do Item      ] Example "cite" Check
Moveto [Descricao do Item   ] Check
Moveto [Unidade Interna     ] Check
Moveto [Codigo Fornecedor   ] Check
Moveto [NCM                 ] Check
Moveto [Inativo             ] typeIn "not S" 

{Ask} {\\Sistemas\\Vendas\\Tbprite}
Moveto [Codigo da Tabela    ] TypeIn "~VSDGTABELA"
Moveto [Codigo do Item      ] Example "cite"
Moveto [Valor_Base          ] Check

Do_It!
ClearAll

EndProc

;*******************************************************************************
;* Rotina p/ Adicionar Dados                                               *
;*******************************************************************************
Proc Adiciona_Dados()

{Ask} {Answer}

Moveto [Codigo do Item      ] Example "cite"
Moveto [Descricao do Item   ] Example "ditem"
Moveto [Unidade Interna     ] Example "un"
Moveto [Codigo da Familia   ] Example "codfam"
Moveto [Descricao da Familia] Example "descfam"
Moveto [Codigo da Marca     ] Example "codmarca"
Moveto [Descricao da Marca  ] Example "descmarca"
Moveto [NCM                 ] Example "ncm"
Moveto [Codigo Fornecedor   ] Example "codforn"
Moveto [Valor_Base          ] Example "vrbase"

{Ask} TypeIn Tabela Enter TypeIn "Insert"

Moveto [Codigo do Item      ] Example "cite"
Moveto [Descricao do Item   ] Example "ditem"
Moveto [Unidade Interna     ] Example "un"
Moveto [Codigo da Familia   ] Example "codfam"
Moveto [Descricao da Familia] Example "descfam"
Moveto [Codigo da Marca     ] Example "codmarca"
Moveto [Descricao da Marca  ] Example "descmarca"
Moveto [NCM                 ] Example "ncm"
Moveto [Codigo Fornecedor   ] Example "codforn"
Moveto [Valor_Base          ] Example "vrbase"

Do_It!
ClearAll

Delete "Answer"

EndProc
;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Adiciona_Indices()

{Ask} {\\Sistemas\\Vendas\\Tbindpr}
Moveto [Codigo da Familia   ] Example "codfam"
Moveto [Codigo da Marca     ] Example "codmarca"
Moveto [Porc1               ] Example "porc1"
Moveto [Porc2               ] Example "porc2"
Moveto [Porc3               ] Example "porc3"
Moveto [Porc4               ] Example "porc4"
Moveto [Porc5               ] Example "porc5"

{Ask} TypeIn Tabela Enter
Moveto [Codigo da Familia   ] Example "codfam"
Moveto [Codigo da Marca     ] Example "codmarca"
Moveto [Porc1               ] TypeIn "Changeto" Example "porc1"
Moveto [Porc2               ] TypeIn "Changeto" Example "porc2"
Moveto [Porc3               ] TypeIn "Changeto" Example "porc3"
Moveto [Porc4               ] TypeIn "Changeto" Example "porc4"
Moveto [Porc5               ] TypeIn "Changeto" Example "porc5"

Do_It!
ClearAll

EndProc
;*******************************************************************************
;* 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_MARCA"            : Campo="NO"
            Case Campo="TG_FAMI"             : Campo="TG_MARCA"
            Case Campo="TG_TABELA"           : Campo="TG_FAMI"
            Case Campo="YES" Or Campo="NO"   : Campo="TG_MARCA"
          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_MARCA"      : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"       : Campo="TG_TABELA"
                    Case Campo="TG_TABELA"     : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc


;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
If Not IsAssigned(SYS_CODIGO_CLIENTE) Then SYS_CODIGO_CLIENTE="" EndIf
LimpAguarde()

VSDGMARCA     = ""
VSDGNOMMARCA  = ""
VSDGFAMI      = ""
VSDGNOMFAMI   = ""
VSDGTABELA    = ""
VSDGNOMTAB    = ""

While True

  ShowDialog "Listagem de Itens/Indices Tabela Preo" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 04,12   Height 11 Width 72

    Label  @ 00,00 "Marca" For "TG_MARCA"
    Accept @ 01,03 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"     To VSDGMARCA
    Accept @ 01,10 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA"  To VSDGNOMMARCA

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

    Label  @ 04,00 "Tabela" For "TG_TABELA"
    Accept @ 05,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA" To VSDGTABELA
    Accept @ 05,10 Width 25 "A30" Picture "!*!" Tag "TG_NOMTAB" To VSDGNOMTAB

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  
  Tabela=Cria_Temp(PrivDir())
  If IsTable(Tabela) Then Delete Tabela EndIf
   
  Copy "\\Base\\Sistemas\\Estoque\\RC_0113" Tabela
  
  If IsTable("Answer")     Then Delete "Answer" EndIf
  Seleciona()
  
  If IsEmpty("Answer")
     Then Mensagem("NÆo existem registros a processar")
          Loop
  EndIf        
  
  Adiciona_Dados()
  Adiciona_Indices()
      
  If IsEmpty(Tabela)
     Then MENSAGEM("No existem registros a processar")
          Delete Tabela
          Loop
  EndIf      

  IMPRIREL(Tabela,"R")

Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All


