;** Rm_0901  *******************************************************************
;* Emissao de Tabela de Pre‡os Conforme Condi‡„o de Pagamento                  *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/01/99 por Anivel Augusto Rodrigues
;Ultima Alteracao: 08/09/2004 por Jos‚ Lu¡s Ameno da Silva
;Motivo Alteracao: PrivDir

;*******************************************************************************
;* 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 TypeIn ">=~VSDGMARCAINI,<=~VSDGMARCAFIM"
Moveto [Descricao da Marca       ] Check
Moveto [Codigo do Grupo          ] Check TypeIn ">=~VSDGGRPINI  ,<=~VSDGGRPFIM"
Moveto [Descricao do Grupo       ] Check
Moveto [Inativo                  ] TypeIn "Not S"
{Ask} {Tbprcab} Check
Moveto [Codigo da Tabela] Example "TAB" TypeIn ",~VSDGTABELA"
{Ask} {TbPrite} Check
Moveto [Codigo da Tabela] Example "TAB"
Moveto [Codigo do Item  ] Example "CODIGO"

Do_It!
ClearAll

{Ask} {Answer}
Moveto [Codigo da Tabela    ] Example "a"
Moveto [Codigo do Item      ] Example "b"
Moveto [Tipo do Item        ] Example "c"
Moveto [Descricao do Item   ] Example "d"
Moveto [Unidade Fiscal      ] Example "e"
Moveto [Preco Unitario      ] Example "f" TypeIn ",Not 0,not Blank"
Moveto [Data Ultimo Reajuste] Example "g"
Moveto [Taxa Ultimo Reajuste] Example "h"
Moveto [Codigo da Familia   ] Example "cf"
Moveto [Descricao da Familia] Example "df"
Moveto [Codigo do Grupo     ] Example "cg"
Moveto [Descricao do Grupo  ] Example "dg"
Moveto [Codigo da Marca     ] Example "cm"
Moveto [Descricao da Marca  ] Example "dm"

{Ask} TypeIn Tabela Enter TypeIn "Fast Insert"
Moveto [Codigo da Tabela    ] Example "a"
Moveto [Codigo do Item      ] Example "b"
Moveto [Tipo do Item        ] Example "c"
Moveto [Descricao do Item   ] Example "d"
Moveto [Unidade Fiscal      ] Example "e"
Moveto [Preco Unitario      ] Example "f"
Moveto [Data Ultimo Reajuste] Example "g"
Moveto [Taxa Ultimo Reajuste] Example "h"
Moveto [Codigo da Familia   ] Example "cf"
Moveto [Descricao da Familia] Example "df"
Moveto [Codigo do Grupo     ] Example "cg"
Moveto [Descricao do Grupo  ] Example "dg"
Moveto [Codigo da Marca     ] Example "cm"
Moveto [Descricao da Marca  ] Example "dm"
Do_It!
ClearAll

For I From 1 to 6
    DESCPAGTO[I]=""
    TAXA[I]     =BlankNum()
EndFor

View "Tbprcpg"
If not IsEmpty("Tbprcpg")
   Then Moveto [Codigo da Tabela]
        Locate VSDGTABELA
        i=1
        While [Codigo da Tabela]=VSDGTABELA
            If i>6
               Then QuitLoop
               Else DESCPAGTO[I]=[Tbprcpg->Descricao CondPagto]
                    TAXA[I]     =[Tbprcpg->Taxa Financeira]
            Endif
            i=i+1
            Skip
            If EOT()
               Then QuitLoop
            Endif
        Endwhile
EndIf
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_TABELA"         : Campo="NO"
            Case Campo="TG_FAMIINI"        : Campo="TG_TABELA"
            Case Campo="TG_FAMIFIM"        : Campo="TG_FAMIINI"
            Case Campo="TG_MARCAINI"       : Campo="TG_FAMIFIM"
            Case Campo="TG_MARCAFIM"       : Campo="TG_MARCAINI"
            Case Campo="TG_GRPINI"         : Campo="TG_MARCAFIM"
            Case Campo="TG_GRPFIM"         : Campo="TG_GRPINI"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_GRPFIM"
            Case Campo="TG_COLUNAS"        : Campo="TG_OPRELCODALF"
            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"     :
                         If Not Isblank(VSDGTABELA)
                            Then Campo="TG_FAMIINI"
                            Else VSDGNOMTAB=""
                         EndIf
                    Case Campo="TG_FAMIINI"    :Campo="TG_FAMIFIM"
                    Case Campo="TG_FAMIFIM"    :Campo="TG_MARCAINI"
                    Case Campo="TG_MARCAINI"   :Campo="TG_MARCAFIM"
                    Case Campo="TG_MARCAFIM"   :Campo="TG_GRPINI"
                    Case Campo="TG_GRPINI"     :Campo="TG_GRPFIM"
                    Case Campo="TG_GRPFIM"     :Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF":Campo="TG_COLUNAS"
                    Case Campo="TG_COLUNAS"    :
                         VSDGCOLUNAS=ControlValue("TG_COLUNAS")
                         If Not IsBlank(VSDGCOLUNAS)
                            Then Switch
                                   Case VSDGCOLUNAS="A":
                                        VSDGNOMCOLUNAS="TRES COLUNAS"
                                   Case VSDGCOLUNAS="B":
                                        VSDGNOMCOLUNAS="SEIS COLUNAS"
                                   OtherWise:
                                        VSDGCOLUNAS=""
                                        VSDGNOMCOLUNAS=""
                                 EndSwitch
                                 If Not IsBlank(VSDGCOLUNAS)
                                    Then Campo="YES"
                                 EndIf
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_TABELA":
     MSG_CAMPO="Informe uma Tabela !"
  Case Campo="TG_DTINI":
     MSG_CAMPO="Informe a Data Inicial"
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_COLUNAS":
     MSG_CAMPO="Informe (A- Trˆs Colunas  B- Seis Colunas)"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGTABELA     =""
VSDGFAMIINI    =""
VSDGFAMIFIM    =""
VSDGMARCAINI   =""
VSDGMARCAFIM   =""
VSDGGRP        =""
VSDGMARCA      =""
VSDGCOR        =""
VSDGCOLUNAS    =""
VSDGNOMCOLUNAS =""
Array DESCPAGTO[6]
Array TAXA[6]

While True

  ShowDialog "Emiss„o da Tabela de Pre‡o VIII" 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 15 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 07 "A3"  Picture "#*#" Tag "TG_FAMIINI" To VSDGFAMIINI
    Label  @ 03,17 "at‚"  For "TG_FAMIFIM"
    Accept @ 03,22 Width 07 "A3"  Picture "#*#" Tag "TG_FAMIFIM" To VSDGFAMIFIM

    Label  @ 04,00 "Marca...."  For "TG_MARCAINI"
    Accept @ 04,10 Width 07 "A3"  Picture "#*#" Tag "TG_MARCAINI" To VSDGMARCAINI
    Label  @ 04,17 "at‚"  For "TG_MARCAFIM"
    Accept @ 04,22 Width 07 "A3"  Picture "#*#" Tag "TG_MARCAFIM" To VSDGMARCAFIM

    Label  @ 05,00 "Grupo...."  For "TG_GRPINI"
    Accept @ 05,10 Width 07 "A3"  Picture "#*#" Tag "TG_GRPINI" To VSDGGRPINI
    Label  @ 05,17 "at‚"  For "TG_GRPFIM"
    Accept @ 05,22 Width 07 "A3"  Picture "#*#" Tag "TG_GRPFIM" To VSDGGRPFIM

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

    Label  @ 08,00 "Op‡„o de Colunas" For "TG_COLUNAS"
    Accept @ 09,01 Width 04 "A1"  Picture "A,B" Tag "TG_COLUNAS" To VSDGCOLUNAS
    Accept @ 09,06 Width 20 "A20"  Picture "!*!" Tag "TG_NOMCOLUNAS" To VSDGNOMCOLUNAS

    Pushbutton @ 11,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 11,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")
  Tabela=Cria_Temp(PrivDir())
  Empty "\\Base\\Sistemas\\Vendas\\Rm_0901"
  Copy "\\Base\\Sistemas\\Vendas\\Rm_0901" Tabela
  Seleciona()

  If DESCPAGTO[1]="" and TAXA[1]=BlankNum()
     Then MENSAGEM("N„o Existe Condi‡”es de Pagamento para esta Tabela !")
          Loop
  Endif

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  If VSDGOPRELCODALF="1"
     Then If VSDGCOLUNAS="A"
             Then IMPRIREL(Tabela,"7")
             Else IMPRIREL(Tabela,"2")
          Endif
     Else If VSDGCOLUNAS="A"
             Then IMPRIREL(Tabela,"8")
             Else IMPRIREL(Tabela,"1")
          Endif
  Endif

  Delete Tabela
  If IsTable("Answer")
     Then Delete "Answer"
  EndIf

EndWhile
ClearAll
Release Vars All
Release Procs All
