;** PONTOS *********************************************************************
;*  Sistema de Pontua‡Æo de Cliente                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 17/09/2019 por Bruno Carvalho
;Ultima Alteracao:   /  /     por
;Motivo Alteracao: 

;*******************************************************************************
;*                                                                             *
;*******************************************************************************
Proc CHAVEC()                                

FACA_CHAVEC=True
INICIO_PAGINA=True

While True
  Moveto [Codigo da Empresa]
  End                          
  EMPRESA=[Codigo da Empresa]
  Moveto [Codigo da Empresa]
  
  If OPCAO_FORM="F"
     Then Down          
     Else CtrlPgDn
  EndIf
  Moveto [Codigo da Empresa]

  SetaCorRegistro("Editar")
  While True

  MSGCAMPO=""
  TECLA=""
  AguardaTeclasPadrao()

  Switch
    Case RetVal=-94 : MsgTeclasPadrao()
    Case RetVal="F3":
         If OPCAO_FORM="F"
            Then OPCAO_FORM="1"
            Else OPCAO_FORM="F"
         EndIf
         Del                     
         CHAVEC=5
         Return
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":
         Del
         While True
           FACA_CHAVEC=True
           INICIO_PAGINA=True
           If OPCAO_FORM="F"
              Then PAGINA("PontoC","MR")
              Else PAGINA("PontoC","MT")
           EndIf
           EMPRESA=[Codigo da Empresa]
           Switch
             Case EDITAR="S":
                  FastMsg("N„o ‚ poss¡vel incluir/alterar este registro!")
                  UnLockRecord
                  ;PickForm "1"
                  ;Echo Normal
                  ;Echo Off
                  ;CHAVEC=0
                  ;Controla_EdicaoC()
             Case EXCLUIR="S" :
                  CHAVEC=0
                  FastMsg("N„o ‚ poss¡vel excluir o registro!")
                  UnLockRecord
             OtherWise: QuitLoop
           EndSwitch
           If OPCAO_FORM="1"
              Then PickForm "1"
              Else PickForm "F"
           EndIf
           SetaPosForm()
         EndWhile
         QuitLoop
    Case Retval="ESC":
         CHAVEC=9
         Del
         Return
    Case Retval="ENTER" :
         FastMsg("N„o ‚ poss¡vel incluir/alterar este registro!")
         Loop
    EndSwitch
  EndWhile
EndWhile

EndProc  ;ChaveC()

;*******************************************************************************
;* Rotina para Digitacao da Cabeca                                             *
;*******************************************************************************
Proc DigitaC()  
                         
Moveto "PontoC"
SetaCorRegistro("Editar")

Calcular_Pontos()
FACA_CHAVEI = True
Return

EndProc ;DigitaC()  

;*******************************************************************************
;* Rotina para Localizar Cidades                                               *
;*******************************************************************************
Proc CHAVEI()
                  
Moveto "PontoC"
SetaCorRegistro("Padrao")

Moveto "PontoI"
While True 
  Calcular_Pontos()
  End
  NITEM = [Sequencia]
  Down
  Moveto [Sequencia]
  Seta_Sequencia(NITEM,False)
  If IsLockRecord()
     Then Del
          Loop
  EndIf
  SetaCorRegistro("Editar")
  While True  
    TECLA= " Esc=Retornar  PgDn=Finalizar  "
    
    Switch
      OtherWise                   : MSGCAMPO=Field()
    EndSwitch  

    Prompt TECLA
    Wait Field
         Until "F1","ESC","ENTER","F2","ZOOM","ZOOMNEXT","DOWN","UP","RIGHT","LEFT","HOME","END","PGDN","PGUP","ROTATE",-31,-33,"F4","F6",-62,-64,-33
            
    Switch  
    Case RetVal="F1":                                   
    Case Retval="PGDN":   
         Del
         FACA_CHAVEC=False
         FACA_CHAVEI=False
         CHAVEI=9
         Return 
    Case RetVal="ESC" :
         Switch
           Case Field()="Sequencia"   : ConfGeral("Confirma sair deste registro ?")
                                        If Ok<>"S"
                                           Then Loop          
                                        EndIf
                                        Del
                                        FACA_CHAVEC = False
                                        FACA_CHAVEI = False
                                        CHAVEI=9
                                        Return
         Endswitch
    Case RetVal="F7" Or RetVal="UP" Or RetVal="PGUP" Or RetVal="HOME":   
         Del
         While True
           Calcular_Pontos()
           PAGINA("PontoI","MR")   
           Switch
             Case EDITAR="S"  : FastMsg("NÆo ‚ poss¡vel editar este registro!")
             Case EXCLUIR="S" : FastMsg("NÆo ‚ poss¡vel excluir este registro!")
           EndSwitch
           QuitLoop
         EndWhile
         QuitLoop
    Case Retval="ENTER":
         FastMsg("NÆo ‚ possivel incluir registro nesta rela‡Æo!")
         Loop      
    EndSwitch
  EndWhile
EndWhile

EndProc ;ChaveI()

;*******************************************************************************
;* Exclusao da Cabeca                                                          *
;*******************************************************************************
Proc EXCLUSAO()

Moveto "PontoI"
While RecordStatus("New")=False
  While IsLockRecord() EndWhile
  Del
EndWhile

Moveto "PontoC"
UnLockRecord
KeyPress "F7"
If CHAVEC=1
   Then If Not IsAssigned(ACHOU_RESGATE) 
           Then Grava_LogEx("PontoC")
        EndIf   
EnDIf   
Del

EndProc ;EXCLUSAO()

;*******************************************************************************
;* Rotina para Calcular o Valor da Comissao                                    *
;*******************************************************************************
Proc Calcular_Pontos()
Private TAB_ANT,CAMPO_ANT
  
TAB_ANT   = Table()
CAMPO_ANT = Field()

Moveto "PontoI"
Moveto [Pontos Saldo     ] PONTOS_SALDO   = ImageCSum()
Moveto [Pontos Resgate   ] PONTOS_RESGATE = ImageCSum()

Moveto "PontoC"
If PONTOS_SALDO=0 Then PONTOS_SALDO=BlankNum() EndIf
If PONTOS_RESGATE=0 Then PONTOS_RESGATE=BlankNum() EndIf
UnLockRecord
SaveTables

Moveto TAB_ANT
Moveto Field CAMPO_ANT

Release Vars TAB_ANT,CAMPO_ANT

EndProc ;Calcular_Pontos()

;*******************************************************************************
;* Rotina para controlar Edicao do registro                                    *
;*******************************************************************************
Proc Controla_EdicaoC()
 
CopyToArray REG_PONTOS

While FACA_CHAVEC
  DIGITAC()
  If CHAVEC = 9 Then QuitLoop EndIf
  If CHAVEC = 1
     Then Controle_Dia()
  EndIf
  While FACA_CHAVEI
    While True
      CHAVEI()
      If CHAVEI=9 Then QuitLoop EndIf
      If CHAVEI=7 Then     Loop EndIf
    EndWhile
  EndWhile
EndWhile
Moveto "PontoC"
If RecordStatus("Locked") Then UnLockRecord EndIf
If OPCAO_FORM="F"
   Then PickForm "F"
EndIf

SaveTables

EndProc ;Controla_EdicaoC()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"
If Not IsAssigned(SYS_CONTROLE_DIA)    Then SYS_CONTROLE_DIA=""        EndIf
If Not IsAssigned(SYS_EMPRESA_DEFAULT) Then SYS_EMPRESA_DEFAULT="0001" EndIf
If Not IsAssigned(SYS_NIVEL_USUARIO)   Then SYS_NIVEL_USUARIO=""       EndIf
SYS_VALOR()
                              
OPCAO_FORM = "F"

CoEdit "PontoC"
PickForm "F"
While True
  CHAVEC()
  If CHAVEC=9
     Then QuitLoop
  EndIf
  Controla_EdicaoC()
EndWhile
Do_It!
ClearAll

Release Vars All
Release Procs All
