;** Rm_0685  *******************************************************************
;* Emissao de Tabela de Precos/C/ Preco de Custo  Particularidade   CARMIG     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/02/97 por Anivel Augusto Rodrigues
;Ultima Alteracao: 06/10/2003 por Karen Lauar Nery
;Motivo Alteracao: Inclusao Proc Preco
;Ultima Alteracao: 21/09/2011 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Ask Custo e Saldo                      

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

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item      ] Example "CODIGO"
Moveto [Codigo da Familia        ] TypeIn ">=~VSDGFAMIINI ,<=~VSDGFAMIFIM"
Moveto [Codigo da Marca          ] TypeIn ">=~VSDGMARCAINI,<=~VSDGMARCAFIM"
Moveto [Codigo do Grupo          ] TypeIn ">=~VSDGGRPINI  ,<=~VSDGGRPFIM"
Moveto [Codigo da Cor_Tecido     ] TypeIn ">=~VSDGCORINI  ,<=~VSDGCORFIM"
Moveto [Inativo                  ] TypeIn "Not S"
{Ask} {TbPrite} Check
Moveto [Codigo da Tabela    ] TypeIn "~VSDGTABELA.."
Moveto [Codigo do Item      ] Example "CODIGO"

Do_It!
ClearAll

If IsEmpty("Answer")
   Then Return
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Modifica estrutura da tabela
{Modify} {Restructure} {Answer} Ins Enter  "codigo da empresa" Enter "a4" Enter
                        Enter End Down "Saldo Atual" Enter "$" Enter "Preco de Custo" Enter "$" Do_It!
{Ask} {Answer} TypeIn "Fast"
Moveto [Codigo da Empresa] TypeIn "Changeto "+VSDGEMPRESA
Do_It!
ClearAll

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Adiciona os valores de saldo
{Ask} {\\Sistemas\\Estoque\\SdEstq}
Moveto [Codigo da Empresa] Example "a"
Moveto [Codigo do Item   ] Example "b"
Moveto [Saldo Atual      ] Example "Saldo"
If VSDGOPCUSTO="M"
   Then Moveto [Custo Total Atual] Example "Custo"
   Else Moveto [Preco de Custo   ] Example "Custo"
EndIf
Moveto [Ano Referencia   ] TypeIn "~VSDGANO"
Moveto [Mes Referencia   ] TypeIn "~VSDGMES"

{Ask} {Answer}
Moveto [Codigo da Empresa] Example "a"
Moveto [Codigo do Item   ] Example "b"
Moveto [Saldo Atual      ] TypeIn "Changeto " Example "Saldo"
If VSDGOPCUSTO="M"
   Then Moveto [Preco de Custo   ] TypeIn  "Changeto _Custo/_Saldo"
   Else Moveto [Preco de Custo   ] TypeIn  "Changeto _Custo"
EndIf
Do_It!
ClearAll

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Deleta os itens em Branco ou Zerado
;{Ask} {Answer} TypeIn "Delete"
;Moveto [Saldo Atual] TypeIn "Blank Or 0"
;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

;************************************
;* 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_EMPRESA"        : Campo="NO"
            Case Campo="TG_MESANO"         : Campo="TG_EMPRESA"
            Case Campo="TG_TABELA"         : Campo="TG_MESANO"
            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_CORINI"         : Campo="TG_GRPFIM"
            Case Campo="TG_CORFIM"         : Campo="TG_CORINI"
            Case Campo="TG_DTINI"          : Campo="TG_CORFIM"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_OPRELCODALF"    : Campo="TG_DTFIM"
            Case Campo="TG_OPCUSTO"        : Campo="TG_OPRELCODALF"
            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"    :
                         If IsBlank(VSDGEMPRESA)
                            Then VSDGNOMEMP=""
                            Else Campo="TG_MESANO"
                         EndIf
                    Case Campo="TG_MESANO"  :
                         VSDGMES=SubStr(VSDGMESANO,1,2)
                         VSDGANO=SubStr(VSDGMESANO,4,4)
                         Campo = "TG_TABELA"
                    Case Campo="TG_TABELA"     :Campo="TG_FAMIINI"
                    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_CORINI"
                    Case Campo="TG_CORINI"     :Campo="TG_CORFIM"
                    Case Campo="TG_CORFIM"     :Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      :
                         If Not VSDGDTINI = BlankDate()
                            Then Campo="TG_DTFIM"
                         EndIf
                    Case Campo="TG_DTFIM"      : Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF":Campo="TG_OPCUSTO"
                    Case Campo="TG_OPCUSTO" :
                         VSDGOPCUSTO=ControlValue("TG_OPCUSTO")
                         If IsBlank(VSDGOPCUSTO)
                            Then VSDGOPCUSTO="M"
                         EndIf
                         Switch
                           Case VSDGOPCUSTO="U": VSDGNOMOPCUSTO="ULTIMO CUSTO"
                           Case VSDGOPCUSTO="M": VSDGNOMOPCUSTO="CUSTO MEDIO"
                         EndSwitch
                         Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTINI":
     MSG_CAMPO="Informe a Data Inicial"
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_OPCUSTO":
       MSG_CAMPO="M=Custo Medio  U=Ultimo Custo "
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGTABELA  =""
VSDGFAMIINI =""
VSDGFAMIFIM =""
VSDGMARCAINI=""
VSDGMARCAFIM=""
VSDGGRP     =""
VSDGMARCA   =""
VSDGCORTECIDO=""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()
TITULO="Lista Pre‡os Reajustados"

While True

  ShowDialog "Tabela de Pre‡o/C/Pre‡o de Custo" 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 20 Width 50

    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  @ 00,34 "Mˆs/Ano"  For "TG_MESANO"
    Accept @ 01,35  Width 10 "A07"  Picture "##.####" Tag "TG_MESANO" To VSDGMESANO

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

    Label  @ 05,00 "Familia.."  For "TG_FAMIINI"
    Accept @ 05,10 Width 07 "A3"  Picture "#*#" Tag "TG_FAMIINI" To VSDGFAMIINI
    Label  @ 05,17 "at‚"  For "TG_FAMIFIM"
    Accept @ 05,22 Width 07 "A3"  Picture "#*#" Tag "TG_FAMIFIM" To VSDGFAMIFIM

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

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

    Label  @ 08,00 "Cor......"  For "TG_CORINI"
    Accept @ 08,10 Width 07 "A4"  Picture "#*#" Tag "TG_CORINI" To VSDGCORINI
    Label  @ 08,17 "at‚"  For "TG_CORFIM"
    Accept @ 08,22 Width 07 "A4"  Picture "#*#" Tag "TG_CORFIM" To VSDGCORFIM

    Label  @ 09,00 "Prazo de Validade" For "TG_DTINI"
    Label  @ 10,00 "de" For "TG_DTINI"
    Accept @ 10,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 10,17 "at‚" For "TG_DTFIM"
    Accept @ 10,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

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

    Label  @ 13,00 "Op‡„o de Pre‡o" For "TG_OPCUSTO"
    Accept @ 14,01 Width 04 "A1"  Picture "M,U,V" Tag "TG_OPCUSTO" To VSDGOPCUSTO
    Accept @ 14,06 Width 21 "A25"  Picture "!*!" Tag "TG_NOMOPCUSTO" To VSDGNOMOPCUSTO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  If IsBlank(VSDGDTINI)
     Then Mensagem("Data Inicial Invalida !")
          Loop
  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_0682" "3" "Answer" "R"
     Else CopyReport "\\Base\\Sistemas\\Vendas\\Rm_0682" "2" "Answer" "R"
  EndIf

  Preco()

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

