;** R_tbpr04 *******************************************************************
;*  Reajuste da Tabela de Preco                                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 19/12/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog + op‡Æo de somar/subtrair valor e inclusao R_TBPR01,R_TBPR02,R_TBPR03
;Ultima Alteracao: 09/04/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog     

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Ajusta_Tabela()
private s, nr, dtref, atualizapreco, codigoanterior

ClearAll

Aguarde("Aguarde, Selecionando registros")

{Ask}{\\Sistemas\\Estoque\\Itens}
moveto [codigo do item      ] typein "_citem"
moveto [Tipo do Item        ] typein "~VSDGTPITEM.." 
moveto [Codigo da Familia   ] typein "~VSDGFAMI.." 
moveto [Codigo do Grupo     ] typein "~VSDGGRP.." 
moveto [Codigo da Marca     ] typein "~VSDGMARCA.."  
moveto [Codigo da Cor_Tecido] typein "~VSDGCORTECIDO.."

if VSDGOPMUDANCA="3";  VSDGNOM_OPMUDANCA="APLICAR VALOR POR KG '$' "
   then moveto [Peso Liquido] check
endif

Switch 
 Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
      {Ask} {Tbprcit} check
      Moveto [Codigo da Tabela       ] typeIn "~VSDGTABELA.."
      Moveto [Codigo                 ] typeIn "~VSDGDESTINAT.."
      moveto [codigo do item         ] typein "_citem"
      do_it!
      ClearAll
                      
 Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
      {Ask} {Tbprrit} check
      Moveto [Codigo da Tabela       ] typeIn "~VSDGTABELA.."
      Moveto [Codigo do Representante] typeIn "~VSDGREPRESEN.."
      moveto [codigo do item         ] typein "_citem"
      do_it!
      ClearAll

 Otherwise            : ;VSDGNOMOPTABELA="BASE"
      {Ask} {Tbprite} check
      Moveto [Codigo da Tabela    ] typeIn "~VSDGTABELA.."
      moveto [codigo do item      ] typein "_citem"
      do_it!
      ClearAll

EndSwitch

if isempty("Answer")
   then mensagem("Sem registros a processar !")
        return false
endif        


Switch 
 Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
      sort "Answer" On "Codigo da Tabela", "Codigo","Codigo do Item"
                      
 Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
      sort "Answer" On "Codigo da Tabela", "Codigo do Representante","Codigo do Item"

 Otherwise            : ;VSDGNOMOPTABELA="BASE"
      sort "Answer" On "Codigo da Tabela", "Codigo do Item"

EndSwitch
Clearall

codigoanterior="****"

NR = NRecords("Answer")
   
for wi from 1 to 2

  switch
    case wi=1:
      ARQIMP=PrivDir()+"R_TBPR01.Txt"
      If IsFile(ARQIMP)
         Then Deleta_Arquivo(ARQIMP)
      EndIf

      cabecalho()

      Switch 
       Case VSDGPRBASE="2":
         View "\\Sistemas\\Producao\\FormulaC" ImageRights ReadOnly
                            
       Case VSDGPRBASE="3":
         View "\\Sistemas\\Producao\\FormulaC" ImageRights ReadOnly
  
      EndSwitch

      Switch 
        Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
          View "\\Sistemas\\Cadastro\\Destinat"
                            
        Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
          View "\\Sistemas\\Cadastro\\Represen"
      
      endswitch
      
    case wi=2:
           
      if not ConfGeral("Imprimir simula‡Æo da tabela "+VSDGTABELA+" ?")
        Then Return false          
        Else ImpriArq(ARQIMP)
      EndIf

      if not ConfGeral("Os itens da tabela de pre‡o "+VSDGTABELA+" ser„o atualizados.//Confirma Opera‡„o ?")
         then return false
      endif   

      Switch 
        Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
          View "TbPrcit"
                            
        Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
          View "TbPrrit"
      
        Otherwise            : ;VSDGNOMOPTABELA="BASE"
          View "TbPrite"
      
      endswitch
      
  endswitch

  Coedit "Answer"
  scan
    Barra(NR, RecNo())
    
    switch
      case wi=1: 
        Aguarde("Aguarde, Simulando altera‡Æo tabela "+VSDGTABELA+" "+BARRA_STRING)

        Switch 
          Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
            if [Answer->Codigo]<>codigoanterior
               then codigoanterior=[Answer->Codigo]
                    GrupoPessoa()
            endif        
                              
          Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
            if [Answer->Codigo do Representante]<>codigoanterior
               then codigoanterior=[Answer->Codigo do Representante]
                    GrupoRepresen()
            endif        
        
        endswitch
        verificalinha(1)

        okpr=true
        if VSDGPRBASE="2" or VSDGPRBASE="3"
           then
                getrecord "\\Sistemas\\Producao\\FormulaC" [Answer->Codigo do Item] to regformulac
                If RetVal
                 Then If VSDGPRBASE="2"
                       Then [Preco Unitario]=regformulac["Preco de Venda_Calculado"]
                       Else [Preco Unitario]=regformulac["Preco de Venda_Livre"    ]
                      EndIf 
       
                 else okpr=false      
              endif       
        endif

        if okpr
           then
                Switch 
                  Case VSDGOPMUDANCA="2":  ;VSDGNOM_OPMUDANCA="ALTERAR PELO NOVO VALOR '$' "
                    NOVO_VALOR=VSDGNOVO_VALOR
                    TAXA      =calcreajuste([Preco Unitario      ],NOVO_VALOR)            
                                       
                  Case VSDGOPMUDANCA="3":  ;VSDGNOM_OPMUDANCA="APLICAR VALOR POR KG '$' "
                    NOVO_VALOR=Round(([Peso Liquido]*VSDGVALOR_KG),2)
                    TAXA      =calcreajuste([Preco Unitario      ],NOVO_VALOR)
                    
                    if NOVO_VALOR=0 or isblank(NOVO_VALOR)
                       then
                            TAXA      =blanknum()
                            NOVO_VALOR=blanknum()
                    endif               

                  Case VSDGOPMUDANCA="4":  ;VSDGNOM_OPMUDANCA="SOMAR/SUBTRAIR UM VALOR"
                    NOVO_VALOR=[Preco Unitario]+VSDGVALOR
                    if NOVO_VALOR<0
                       then NOVO_VALOR=0
                    endif               
                    TAXA      =calcreajuste([Preco Unitario      ],NOVO_VALOR)            

                  Otherwise             :  ;VSDGNOM_OPMUDANCA="APLICAR A PORCENTAGEM '%' "
                    NOVO_VALOR=[Preco Unitario]+Round((([Preco Unitario]*VSDGTAXA)/100),2)
                    TAXA      =VSDGTAXA            

                EndSwitch

                dtref        =VSDGDATA
                atualizapreco=true

                switch
                  case ([Preco Unitario]=0 or isblank([Preco Unitario])) and
                        NOVO_VALOR      =0 or isblank(NOVO_VALOR):

                        atualizapreco=false

                        dtref     =blankdate()
                        TAXA      =blanknum()
                        NOVO_VALOR=blanknum()
                        
                endswitch
                
                s=Completa([Codigo do Item   ],11," ")+
                  Completa([Descricao do Item],31," ")+
                  Format("W12.2,EIC",[Preco Unitario])+
                  Format("W13.2,EIC",NOVO_VALOR)+
                  Format("W11.2,EIC",TAXA)+"%"+Spaces(2)+
                  Completa(Format("D13",[Data Ultimo Reajuste]),11," ")+
                  Format("D13",dtref)+"\n"
                            
                Print File ARQIMP s

                if atualizapreco
                   then
                        [Preco Unitario      ]=NOVO_VALOR
                        [Taxa Ultimo Reajuste]=TAXA
                        [Data Ultimo Reajuste]=VSDGDATA
                endif
        endif

      case wi=2: 
        Aguarde("Aguarde, Atualizando tabela "+VSDGTABELA+" "+BARRA_STRING)

        Switch 
         Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
              moveto "Tbprcit"
              moveto [Codigo da Tabela]
              locate [Answer->Codigo da Tabela],[Answer->Codigo],[Answer->Codigo do Item]
                              
         Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
              moveto "Tbprrit"
              moveto [Codigo da Tabela]
              locate [Answer->Codigo da Tabela],[Answer->Codigo do Representante],[Answer->Codigo do Item]
        
         Otherwise            : ;VSDGNOMOPTABELA="BASE"
              moveto "Tbprite"
              moveto [Codigo da Tabela]
              locate [Answer->Codigo da Tabela],[Answer->Codigo do Item]
        
        EndSwitch
        if retval
           then
                moveto [Preco Unitario      ]
                
                [Preco Unitario      ]=[Answer->Preco Unitario      ]
                [Taxa Ultimo Reajuste]=[Answer->Taxa Ultimo Reajuste]
                [Data Ultimo Reajuste]=[Answer->Data Ultimo Reajuste]
                unlockrecord
        endif
      
    endswitch

    moveto "Answer"
          
  endscan
  Do_It!
  ClearAll

  LimpaRodape(0)

endfor

Return true

EndProc  ;Ajusta_Tabela()

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc calcreajuste(vrold, vrnew)
private vrold,vrnew

return ndecimal(((vrnew*100)/vrold)-100,2)

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
proc verificalinha(nl)
private nl

If NLinha+nl > 64
  Then Print File ARQIMP "\f"
       Cabecalho()

       Switch 
        Case VSDGOPTABELA="2":  ;VSDGNOMOPTABELA="POR PESSOA"
          GrupoPessoa()
                              
        Case VSDGOPTABELA="3":  ;VSDGNOMOPTABELA="POR REPRESENTANTE"
          GrupoRepresen()
           
       EndSwitch
       
  else NLinha=NLinha+nl
EndIf

endproc

;*******************************************************************************
;* Cabe‡alho                                                                   *
;*******************************************************************************
Proc Cabecalho()
private titulo

titulo=" - "+VSDGNOMOPTABELA+" - "+VSDGNOM_OPMUDANCA+" - "+VSDGNOM_OPPRBASE+" = "   

Switch 
  Case VSDGOPMUDANCA="2":  ;VSDGNOM_OPMUDANCA="ALTERAR PELO NOVO VALOR '$' "
    titulo=titulo+ltrim(format("W13.3,EIC",VSDGNOVO_VALOR))
                       
  Case VSDGOPMUDANCA="3":  ;VSDGNOM_OPMUDANCA="APLICAR VALOR POR KG '$' "
    titulo=titulo+ltrim(format("W13.3,EIC",VSDGVALOR_KG))

  Case VSDGOPMUDANCA="4":  ;VSDGNOM_OPMUDANCA="SOMAR/SUBTRAIR UM VALOR"
    titulo=titulo+ltrim(format("W13.3,EIC",VSDGVALOR))

  Otherwise             :  ;VSDGNOM_OPMUDANCA="APLICAR A PORCENTAGEM '%' "
    titulo=titulo+ltrim(format("W13.3,EIC",VSDGTAXA))+"%"

EndSwitch

Print File ARQIMP Chr(27)+Chr(120)+Chr(48)+Chr(15)

Print File ARQIMP "\n"
Print File ARQIMP "==================================================================================================================================="+"\n"
Print File ARQIMP "Tabela : "+VSDGTABELA+" - "+VSDGNOMTAB+"\n"
Print File ARQIMP "Simula‡Æo Reajuste da Tabela "+titulo+"\n"
Print File ARQIMP "==================================================================================================================================="+"\n\n"
Print File ARQIMP "                                          ____ Preco Unitario _____   %Reajuste  __ Data Alteracao ___"+"\n"
Print File ARQIMP "Item                                             Atual   Reajustado   Calculado    Ultima   Reajustada"+"\n"
Print File ARQIMP "----------------------------------------  ------------ ------------  ----------  ---------- ----------"+"\n"
  
NLinha = 9  

EndProc ;Cabecalho()

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
proc GrupoPessoa()
private regdestinat, codigo, razao

getrecord "\\Sistemas\\Cadastro\\Destinat" [Answer->Codigo] to regdestinat
If RetVal
   then codigo=regdestinat["Codigo"]
        razao =regdestinat["Razao Social"]
   else codigo="????"
        razao ="*?*"
endif        

verificalinha(2)

Print File ARQIMP "\n"
Print File ARQIMP "Pessoa/Cliente: "+codigo+" "+razao+"\n"

endproc

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
proc GrupoRepresen()
private regrepresen, codigo, razao

getrecord "\\Sistemas\\Cadastro\\Represen" [Answer->Codigo do Representante] to regrepresen
If RetVal
   then codigo=regrepresen["Codigo do Representante"]
        razao =regrepresen["Razao Social Represent"]
   else codigo="????"
        razao ="*?*"
endif        

verificalinha(2)

Print File ARQIMP "\n"
Print File ARQIMP "Representante: "+codigo+" "+razao+"\n"

endproc

;*******************************************************************************
;* Rotina do ShowDialog                                                        *
;*******************************************************************************
Proc ShowOpcoes(tgcampo,tp)
private tgcampo,tp

if tp="F1"
   then
        MSG_CAMPO=""
        TECLA    =""
        echo normal
        echo off

        Switch
          Case tgcampo="TG_OPTABELA":
            ShowPopup " Op‡äes de Tabela " CENTERED
             "~1~  Tabela base/matriz                " : " Utilizar a tabela base/matriz                                 " : "1",
             "~2~  Tabela por pessoa/cliente         " : " Utilizar a tabela por pessoa/cliente                          " : "2",
             "~3~  Tabela por representante          " : " Utilizar a tabela por representante                           " : "3",
               Separator,
             "~C~ancelar                              " : " Cancelar a Opera‡„o                                          " : "CANCELAR"
            EndMenu
             To spopcao
            If RetVal
               Then VSDGOPTABELA=spopcao
            EndIf

          Case tgcampo="TG_OPMUDANCA"   : 
            ShowPopup " Op‡äes de opera‡Æo " CENTERED
             "~1~  Porcentagem(%)                    " : " Aplicar % no pre‡o                                               " : "1",
             "~2~  Novo Valor                        " : " Substituir pre‡o por um valor fixo informado                     " : "2",
             "~3~  Valor do Kilo                     " : " Calcular pre‡o sobre peso do item X valor/Kg informado           " : "3",
             "~4~  Somar/Subtrair valor              " : " Somar/substituir no pre‡o o valor fixo informado                 " : "4",
               Separator,
             "~C~ancelar                              " : " Cancelar a Opera‡„o                                             " : "CANCELAR"
            EndMenu
             To spopcao
            If RetVal
               Then VSDGOPMUDANCA=spopcao
            EndIf

          Case tgcampo="TG_PRBASE":
            ShowPopup " Op‡äes origem do Pre‡o " CENTERED
             "~1~  Pr¢pria Tabela                    " : " Utilizar o Pre‡o da pr¢pria Tabela                            " : "1",
             "~2~  Form£la, Pre‡o de Venda Calculado " : " Utilizar o Pre‡o de Venda Calculado da Form£la do Item        " : "2",
             "~3~  Form£la, Pre‡o de Venda … Praticar" : " Utilizar o Pre‡o de Venda … Praticar da Form£la do Item       " : "3",
               Separator,
             "~C~ancelar                              " : " Cancelar a Opera‡„o                                          " : "CANCELAR"
            EndMenu
             To spopcao
            If RetVal
               Then VSDGPRBASE=spopcao
            EndIf
            
          OtherWise               : Dialog_F1()
          
        EndSwitch
endif

Switch
  Case tgcampo="TG_OPTABELA":
    Switch 
     Case VSDGOPTABELA="1":  VSDGNOMOPTABELA="BASE/MATRIZ"
                             VSDGDESTINAT   =""
                             VSDGNOMDEST    =""
                             VSDGREPRESEN   =""
                             VSDGNOMREPR   =""
                             Campo="TG_TPITEM"

     Case VSDGOPTABELA="2":  VSDGNOMOPTABELA="POR PESSOA/CLIENTE"
                             VSDGREPRESEN   =""
                             VSDGNOMREPR   =""
                             Campo="TG_DESTINAT"
                          
     Case VSDGOPTABELA="3":  VSDGNOMOPTABELA="POR REPRESENTANTE"
                             VSDGDESTINAT   =""
                             VSDGNOMDEST    =""
                             Campo="TG_REPRESEN" 
    
    EndSwitch

  Case tgcampo="TG_PRBASE"       : 
    Switch 
     Case VSDGPRBASE="2":
          VSDGNOM_OPPRBASE="FORMéLA, PR.VENDA CALCULADO"
                          
     Case VSDGPRBASE="3":
          VSDGNOM_OPPRBASE="FORMéLA, PR.VENDA A PRATICAR"

     otherwise          :
          VSDGPRBASE="1"  
          VSDGNOM_OPPRBASE="DA PRàPRIA TABELA"   

    EndSwitch
    Campo="TG_OPMUDANCA"    

  Case tgcampo="TG_OPMUDANCA"   : 
    Switch 
     Case VSDGOPMUDANCA="1":  VSDGNOM_OPMUDANCA="APLICAR A PORCENTAGEM '%' "
                              VSDGNOVO_VALOR   =blanknum()
                              VSDGVALOR_KG     =blanknum()
                              VSDGVALOR        =blanknum()
                              Campo="TG_TAXA"              

     Case VSDGOPMUDANCA="2":  VSDGNOM_OPMUDANCA="ALTERAR PELO NOVO VALOR '$' "
                              VSDGTAXA         =blanknum()
                              VSDGVALOR_KG     =blanknum()
                              VSDGVALOR        =blanknum()
                              Campo="TG_NOVO_VALOR"
                          
     Case VSDGOPMUDANCA="3":  VSDGNOM_OPMUDANCA="APLICAR VALOR POR KG '$' "
                              VSDGTAXA         =blanknum()
                              VSDGNOVO_VALOR   =blanknum()
                              VSDGVALOR        =blanknum()
                              Campo="TG_VALOR_KG"   
    
     Case VSDGOPMUDANCA="4":  VSDGNOM_OPMUDANCA="SOMAR/SUBTRAIR UM VALOR"
                              VSDGTAXA         =blanknum()
                              VSDGNOVO_VALOR   =blanknum()
                              VSDGVALOR_KG     =blanknum()
                              Campo="TG_VALOR"
    
    EndSwitch

EndSwitch

endproc

;*******************************************************************************
;* Rotina do ShowDialog                                                        *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
   
If Disparo="OPEN"  
   Then AoCriarShowDialog()
        TiraSombraShowDialog()
        Campo="TG_TABELA"
EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9: Temp=False
     Case Evento["KeyCode"] = -59:
     
          ShowOpcoes(Campo,"F1")

     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_TABELA"        : Campo="NO"

            Case Campo="TG_OPTABELA"      : Campo="TG_TABELA"
            Case Campo="TG_DESTINAT"      : Campo="TG_OPTABELA"
            Case Campo="TG_REPRESEN"      : Campo="TG_OPTABELA"

            Case Campo="TG_TPITEM"        : Campo="TG_OPTABELA"
            Case Campo="TG_FAMI"          : Campo="TG_TPITEM"
            Case Campo="TG_GRP"           : Campo="TG_FAMI"
            Case Campo="TG_MARCA"         : Campo="TG_GRP"
            Case Campo="TG_COR_TECIDO"    : Campo="TG_MARCA"

            Case Campo="TG_PRBASE"        : Campo="TG_COR_TECIDO"
            Case Campo="TG_OPMUDANCA"     : Campo="TG_PRBASE" 

            Case Campo="TG_TAXA"          : Campo="TG_OPMUDANCA"
            Case Campo="TG_VALOR"         : Campo="TG_OPMUDANCA"
            Case Campo="TG_NOVO_VALOR"    : Campo="TG_OPMUDANCA"
            Case Campo="TG_VALOR_KG"      : Campo="TG_OPMUDANCA"

            Case Campo="TG_DATA"          : Campo="TG_OPMUDANCA"
            
            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 IsBlank(VSDGTABELA)
                            Then fastmsg("Valor inv lido!")
                            Else Campo="TG_OPTABELA"
                         endif   

                    Case Campo="TG_OPTABELA"   : 
                         VSDGOPTABELA=ControlValue("TG_OPTABELA")
                         if isblank(VSDGOPTABELA)
                            then VSDGOPTABELA="1"
                         endif   
                         ShowOpcoes(Campo,"")

                    Case Campo="TG_DESTINAT"   : Campo="TG_TPITEM"
                    Case Campo="TG_REPRESEN"   : Campo="TG_TPITEM"

                    Case Campo="TG_TPITEM"     : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"       : Campo="TG_GRP"
                    Case Campo="TG_GRP"        : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"      : Campo="TG_COR_TECIDO"
                    Case Campo="TG_COR_TECIDO" : Campo="TG_PRBASE"
                    Case Campo="TG_PRBASE"       : 
                         VSDGPRBASE=ControlValue("TG_PRBASE")
                         if isblank(VSDGPRBASE)
                            then VSDGPRBASE="1"
                         endif   
                         ShowOpcoes(Campo,"")
                         
                    Case Campo="TG_OPMUDANCA"   : 
                         VSDGOPMUDANCA=ControlValue("TG_OPMUDANCA")
                         if isblank(VSDGOPMUDANCA)
                            then VSDGOPMUDANCA="1"
                         endif   
                         ShowOpcoes(Campo,"")

                    Case Campo="TG_TAXA"       :
                         VSDGTAXA=ControlValue("TG_TAXA")
                         If IsBlank(VSDGTAXA) or VSDGTAXA=0
                            Then fastmsg("Valor inv lido!")
                            Else Campo="TG_DATA"
                         endif   

                    Case Campo="TG_NOVO_VALOR"       :
                         VSDGNOVO_VALOR=ControlValue("TG_NOVO_VALOR")
                         If IsBlank(VSDGNOVO_VALOR) or VSDGNOVO_VALOR=0
                            Then fastmsg("Valor inv lido!")
                            Else Campo="TG_DATA"
                         endif   

                    Case Campo="TG_VALOR_KG"       :
                         VSDGVALOR_KG=ControlValue("TG_VALOR_KG")
                         If IsBlank(VSDGVALOR_KG) or VSDGVALOR_KG=0
                            Then fastmsg("Valor inv lido!")
                            Else Campo="TG_DATA"
                         endif   

                    Case Campo="TG_VALOR"       :
                         VSDGVALOR=ControlValue("TG_VALOR")
                         If IsBlank(VSDGVALOR) or VSDGVALOR=0
                            Then fastmsg("Valor inv lido!")
                            Else Campo="TG_DATA"
                         endif   

                    Case Campo="TG_DATA"   :
                         VSDGDATA=ControlValue("TG_DATA")
                         If IsBlank(VSDGDATA)
                            Then VSDGDATA=Today()
                         EndIf
                        Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_TABELA"     : MSG_CAMPO="Informe uma tabela de pre‡o"
  Case Campo="TG_OPTABELA"   : MSG_CAMPO="Informe a op‡Æo tabela, [F1]Consultar tabela"
  Case Campo="TG_OPMUDANCA"  : MSG_CAMPO="Informe a opera‡Æo a plicar, [F1]Consultar tabela"
  Case Campo="TG_PRBASE"     : MSG_CAMPO="Informe o origem do pre‡o a utilizar, [F1]Consultar tabela"
  Case Campo="TG_TAXA"       : MSG_CAMPO="Informe a Porcentagem do Reajuste"
  Case Campo="TG_NOVO_VALOR" : MSG_CAMPO="Informe o Novo Valor a substituir"
  Case Campo="TG_VALOR_KG"   : MSG_CAMPO="Informe o Valor do Kilo"
  Case Campo="TG_VALOR"      : MSG_CAMPO="Informe a Valor a somar/subtrair"
  Case Campo="TG_DATA"       : MSG_CAMPO="Informe a Data da Altera‡Æo"

Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)

Return Temp
EndProc   ; (SD_Dialog)

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

VSDGTABELA       =""
VSDGTPITEM       =""
VSDGFAMI         =""
VSDGGRP          =""
VSDGMARCA        =""
VSDGCORTECIDO    =""

VSDGDESTINAT     =""
VSDGREPRESEN     =""

VSDGOPTABELA ="1"  ShowOpcoes("TG_OPTABELA" ,"")   
VSDGOPMUDANCA="1"  ShowOpcoes("TG_OPMUDANCA","")   
VSDGPRBASE   ="1"  ShowOpcoes("TG_PRBASE"   ,"")      

VSDGTAXA         =blanknum()
VSDGNOVO_VALOR   =blanknum()
VSDGVALOR_KG     =blanknum()
VSDGVALOR        =blanknum()
VSDGDATA         =BlankDate()

While True

  ShowDialog "Reajuste/Simula‡Æo da Tabela de Pre‡os" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
    @ 01,00 Height 22 Width 80

    Label  @ 00,00 "Tabela"  For "TG_TABELA"
    Accept @ 01,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA" To VSDGTABELA
    Accept @ 01,09 Width 25 "A70" Picture "!*!" Tag "TG_NOMTAB" To VSDGNOMTAB

    Label  @ 02,00 "Op‡Æo de Tabela" For "TG_OPTABELA"
    Accept @ 03,01 Width 07 "A1" picture "1,2,3" Tag "TG_OPTABELA" to VSDGOPTABELA
    Accept @ 03,09 Width 25 "A48" Picture "!*!" Tag "TG_NOMOPTABELA" To VSDGNOMOPTABELA
    
    Label  @ 04,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 05,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCLI" To VSDGNOMDEST
    
    Label  @ 06,00 "Representante"  For "TG_REPRESEN"
    Accept @ 07,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN"   To VSDGREPRESEN
    Accept @ 07,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMREPR" To VSDGNOMREPR

    Label  @ 08,00 "Tipo do Item"  For "TG_TPITEM" 
    Accept @ 09,01 Width 07 "A1"  Picture "&" Tag "TG_TPITEM" To VSDGTPITEM
    Accept @ 09,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMTPITEM" To VSDGNOMTPITEM

    Label  @ 10,00 "Fam¡lia"  For "TG_FAMI"
    Accept @ 11,01 Width 07 "A3"  Picture "!*!" Tag "TG_FAMI" To VSDGFAMI
    Accept @ 11,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

    Label  @ 12,00 "Grupo"  For "TG_GRP"
    Accept @ 13,01 Width 07 "A3"  Picture "!*!" Tag "TG_GRP" To VSDGGRP
    Accept @ 13,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 14,00 "Marca"  For "TG_MARCA"
    Accept @ 15,01 Width 07 "A3"  Picture "!*!" Tag "TG_MARCA" To VSDGMARCA
    Accept @ 15,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 16,00 "Cor/Tecido"  For "TG_COR_TECIDO"
    Accept @ 17,01 Width 07 "A4"  Picture "!*!" Tag "TG_COR_TECIDO" To VSDGCORTECIDO
    Accept @ 17,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCOR_TECIDO" To VSDGNOMCORTECIDO

    Label  @ 00,35 "Qual Pre‡o Usar?" For "TG_PRBASE"
    Accept @ 01,36 Width 04 "A1" picture "1,2,3" Tag "TG_PRBASE" to VSDGPRBASE
    Accept @ 01,41 Width 36 "A48" Picture "!*!" Tag "TG_NOM_OPPRBASE" To VSDGNOM_OPPRBASE
    
    Label  @ 02,35 "Opera‡Æo" For "TG_OPMUDANCA"
    Accept @ 03,36 Width 04 "A1" picture "1,2,3,4" Tag "TG_OPMUDANCA" to VSDGOPMUDANCA
    Accept @ 03,41 Width 36 "A48" Picture "!*!" Tag "TG_NOM_OPMUDANCA" To VSDGNOM_OPMUDANCA

    Label  @ 04,35 "% Reajuste"  For "TG_TAXA"
    Accept @ 05,36 Width 13 "N" picture "[-]#*#.[###]" Tag "TG_TAXA" To VSDGTAXA

    Label  @ 06,35 "Novo Valor"  For "TG_NOVO_VALOR"
    Accept @ 07,36 Width 13 "N" picture "#*#.[###]" Tag "TG_NOVO_VALOR" To VSDGNOVO_VALOR

    Label  @ 08,35 "Valor/Kg"  For "TG_VALOR_KG"
    Accept @ 09,36 Width 13 "N" picture "#*#.[###]" Tag "TG_VALOR_KG" To VSDGVALOR_KG
    
    Label  @ 10,35 "Valor +/-"  For "TG_VALOR"
    Accept @ 11,36 Width 13 "N" picture "[-]#*#.[###]" Tag "TG_VALOR" To VSDGVALOR

    Label  @ 14,35 "Data Altera‡Æo"  For "TG_DATA"
    Accept @ 15,36 Width 13 "D"  Picture "#[#];.#[#];.##[##]" Tag "TG_DATA"    To VSDGDATA

    Pushbutton @ 18,54 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 18,66 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  LimpaRodape(0)

  if isblank(VSDGTABELA)   then Mensagem("Tabela nÆo informada !") loop endif

  DISPOSITIVO()
  If OK="" 
     Then Loop          
  endif
  LimpaRodape(0)

  if Ajusta_Tabela()
     Then Mensagem("Processo Concluido !")
     Else Mensagem("Processo Abortado !")
  EndIf

  Delete "Answer"
  
EndWhile
ClearAll
Release Vars All
Release Procs All
