;** FT_DTCAN *******************************************************************
;*  Grava a Data do Cancelamento Extemporaneo Fatura/Nota                      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 15/01/2014 por Kamila Gomes 
;Ultima Alteracao: 14/05/2014 por Bruno Carvalho                
;Motivo Alteracao: Ajustes Grava() onde o procedimento nÆo estava saindo do form                    

;*******************************************************************************
;* Rotina p/ Estornar Movimenta‡Æo                                             *
;*******************************************************************************
 Proc Grava()
 
If Tab_Ref = "Faturac"
   Then Moveto "FaturaC" 
        UnLockRecord
        Do_It!
        SaveTables
        
        CoEditKey                            
        FormKey 
EndIf 

Moveto "NotaC"
Moveto [Codigo da Empresa]
Locate EMPRESAFISC, NOTAFISC, SERIEFISC
If Not RetVal 
   Then Mensagem("NÆo existe registro a processar!//Opera‡Æo nÆo realizada !")
        Return
   Else If IsLockRecord() 
          Then Mensagem("Opera‡Æo nÆo realizada !")
               Return
        EndIf       
EndIf

[Data de Acerto]= VSDGDTINI
GRAVA_OK=True

If Tab_Ref = "Faturac"
   Then Moveto "FaturaC"
        UnLockRecord
        FormKey
        
        SaveTables
   Else Moveto Tab_Ref
        CoeditKey      
EndIf

EndProc ;Grava()
 
;*******************************************************************************
;* Rotina p/ Estornar Movimenta‡Æo                                             *
;******************************************************************************* 
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"] =  27:
          Temp=False
          Switch
            Case Campo="TG_DTINI" : Campo="NO"
            Case Campo="YES" Or Campo="NO": Campo="TG_DTINI"
          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_DTINI" : 
                         If IsBlank(VSDGDTINI)
                            Then Mensagem("Data Invalida !")
                            Else Campo="YES"        
                         EndIf
                    Case Campo="YES"      : AcceptDialog
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO="Data do Cancelamento"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp

EndProc ;SD_Dialog()

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
TAB_Ref=Table()
 
VSDGDTINI=BlankDate() 
EMPRESAFISC=[Codigo da Empresa ]
If Tab_Ref = "Faturac"
  Then NOTAFISC =[Numero Nota Gerada ]
       SERIEFISC=[Serie Nota Gerada  ] 
  Else NOTAFISC =[Numero do Documento]
       SERIEFISC=[Serie do Documento ] 
EndIf 

ShowDialog "Data de Cancelamento" Proc "SD_Dialog"
Trigger "OPEN","ARRIVE"
Key "F1","ENTER","ESC","TAB",
    -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
 @ 05,12   Height 09 Width 56

  Label  @ 01,04 "Data da Efetiva‡Æo do Cancelamento Extemporƒneo" For "TG_DTINI"
  Accept @ 03,20 Width 13 "D"  Picture "#[#].##.##[##]" Tag "TG_DTINI" To VSDGDTINI
  
  Pushbutton @ 05,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
  Pushbutton @ 05,28 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

EndDialog

If Retval 
   Then Grava()
EndIf  

UnLockRecord
KeyPress "F7"
IsLockRecord()

Moveto Tab_Ref
KeyPress "F7"
UnLockRecord

Release Vars EMPRESAFISC,NOTAFISC,SERIEFISC,Tab_Ref, VSDGDTCANC, TG_DTCANC             
Release Procs Grava,SD_Dialog