;** Rm_0670a *******************************************************************
;* Emissao de Tabela de Precos                                                 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/04/1998 por Anivel Augusto Rodrigues
;Ultima Alteracao: 06/10/2003 por Karen Lauar Nery
;Motivo Alteracao: Inclusao Proc Preco

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

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item           ] Example "CODIGO"
Moveto [Codigo da Familia        ] Check TypeIn ">=~VSDGFAMIINI,<=~VSDGFAMIFIM"
Moveto [Descricao da Familia     ] Check
Moveto [Codigo da Marca          ] Check
Moveto [Descricao da Marca       ] Check
Moveto [Codigo do Grupo          ] Check
Moveto [Descricao do Grupo       ] Check
Moveto [Codigo da Cor_Tecido     ] Check
Moveto [Descricao da Cor_Tecido  ] Check
Moveto [Unidade Embalagem        ] Check
Moveto [Fator Conversao Embalagem] Check
{Ask} {TbPrite} Check
Moveto [Codigo da Tabela] TypeIn "~VSDGTABELA.."
Moveto [Codigo do Item  ] Example "CODIGO"
Do_It!
ClearAll

{Modify} {Restructure} {Answer}
Moveto [Field Name]
Locate "Preco Unitario_Formatado"
       If Not RetVal
          Then End Down
              "Preco Unitario_Formatado" Enter "A13"  Enter
       EndIf
       Do_It! ClearImage

EndProc   ;  (Seleciona)

;************************************
;* ROTINA PARA FORMATAR O PRECO     *
;************************************
Proc Preco()

Coedit "Answer"

Scan for Not IsBlank([Preco Unitario])

 PRECO=Format("W10.3,EIC",[Preco Unitario])
 If SubStr(PRECO,Len(PRECO),1)="0"
    Then PRECO=Format("W9.2,EIC",[Preco Unitario])+" "
 EndIf
 [Preco Unitario_Formatado]=PRECO

EndScan
Do_It!

EndProc ;(Preco)

;*******************************************************************************
;* 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_TABELA"         : Campo="NO"
            Case Campo="TG_FAMIINI"        : Campo="TG_TABELA"
            Case Campo="TG_FAMIFIM"        : Campo="TG_FAMIINI"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_CORFIM"
            Case Campo="YES" Or Campo="NO" : Campo="TG_TABELA"
          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_TABELA"     :Campo="TG_FAMIINI"
                    Case Campo="TG_FAMIINI"    :Campo="TG_FAMIFIM"
                    Case Campo="TG_FAMIFIM"    :Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF":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"
LimpAguarde()

VSDGTABELA  =""
VSDGFAMIINI =""
VSDGFAMIFIM =""

While True

  ShowDialog "Emiss„o da Tabela de Pre‡o V" 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 12 Width 50

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

    Label  @ 03,00 "Familia:"  For "TG_FAMIINI"
    Accept @ 03,10 Width 06 "A3"  Picture "#*#" Tag "TG_FAMIINI" To VSDGFAMIINI
    Label  @ 03,16 "at‚"  For "TG_FAMIFIM"
    Accept @ 03,21 Width 06 "A3"  Picture "#*#" Tag "TG_FAMIFIM" To VSDGFAMIFIM

    Label  @ 05,00 "Ordem" For "TG_OPRELCODALF"
    Accept @ 06,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 06,06 Width 15 "A12" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Pushbutton @ 08,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 08,28 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 a Tabela de Pre‡os")
  Seleciona()

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

  If VSDGOPRELCODALF = "1"
     Then CopyReport "\\Base\\Sistemas\\Vendas\\RM_3001" "R" "Answer" "R"
     Else CopyReport "\\Base\\Sistemas\\Vendas\\RM_3001" "1" "Answer" "R"
  EndIf

  Preco()

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
