;** Rm_3000 *********************************************************************
;*  Imprime D.A.R.F                                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/06/96 por Anivel Augusto Rodrigues
;Ultima Alteracao: 09/05/03 por Karen Lauar Nery
;Motivo Alteracao: Mudan‡a Nova Vers„o
;Ultima Alteracao: 07/12/2015 por Anivel Augusto Rodrigues
;Motivo Alteracao: exclusao referencia ao campo IR se nÆo for utilizado!
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes Show Dialog TG_DESTINAT
;Ultima Alteracao: 20/05/2020 por Bruno Carvalho
;Motivo Alteracao: Ajustes para o Base no CopyReport do "CalcCob" para "\\Base\\Sistemas\\Cobranca\\CalcCob"

;*******************************************************************************
;* Rotina p/ Selecionar Registros                                              *
;*******************************************************************************
Proc SELECIONA()
ClearAll
{Ask} {CalcCob} Check
If Not IsBlank(VSDGDESTINAT)
   Then Moveto [Codigo         ] TypeIn "~VSDGDESTINAT.."
   Else Moveto [Codigo         ] TypeIn ">=~VSDGDESTINATINI, <=~VSDGDESTINATFIM"
EndIf
Moveto [Valor??] TypeIn ">0"
Do_It!
ClearAll
If IsEmpty("Answer")
   Then Return
EndIf

View   "Answer"
Coedit "CalcCob"
Moveto "Answer"

Scan
    Moveto "CalcCob"
    Moveto [Codigo]
    Locate [Answer->Codigo]
    If RetVAl
       Then [Vencimento Darf]=DateVal(VSDGDTINI)
    EndIf
    Moveto "Answer"
EndScan
Do_It!
EndProc

;*******************************************************************************
;* 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_DESTINAT"       : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINATINI"    : Campo="TG_DESTINAT"
            Case Campo="TG_DESTINATFIM"    : Campo="TG_DESTINATINI"
            Case Campo="TG_TAXA"           : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"          : Campo="TG_TAXA"
            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"      : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT"     :
                         If Not IsBlank(VSDGDESTINAT)
                            Then VSDGDESTINATINI=""
                                 VSDGDESTINATFIM=""
                                 Campo="TG_TAXA"
                            Else Campo="TG_DESTINATINI"
                         EndIf
                    Case Campo="TG_DESTINATINI": Campo="TG_DESTINATFIM"
                    Case Campo="TG_DESTINATFIM": Campo="TG_TAXA"
                    Case Campo="TG_TAXA"         :
                         VSDGTAXA=ControlValue("TG_TAXA")
                         If IsBlank(VSDGTAXA)
                            Then VSDGTAXA="N"
                         EndIf
                         Campo="TG_DTINI"
                    Case Campo="TG_DTINI"        :
                        If VSDGDTINI=BlankDate()
                           Then Mensagem("Data de Emissao Invalida !")
                                Campo="TG_DTINI"
                           Else Campo="YES"
                        EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
Case Campo="TG_TAXA":
    MSG_CAMPO=" S=Sim  N=N„o  "
Case Campo="TG_DTINI":
    MSG_CAMPO=" Informa a Data de Emiss„o "

EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA       = ""
VSDGDESTINAT      = ""
VSDGTAXA          = ""
VSDGDESTINATINI   = ""
VSDGDESTINATFIM   = ""
VSDGDTINI         = BlankDate()

While True

  ShowDialog " Emiss„o de D.A.R.F " Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 09,05   Height 11 Width 57

    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  @ 02,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 03,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    Label  @ 02,33 "Inicial"  For "TG_DESTINATINI"
    Accept @ 03,34 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATINI" To VSDGDESTINATINI
    Label  @ 02,41 "Final"  For "TG_DESTINATFIM"
    Accept @ 03,42 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINATFIM" To VSDGDESTINATFIM

    Label  @ 04,00 "Taxa p/ Balan‡o"  For "TG_TAXA"
    Accept @ 05,01 Width 07 "A4"  Picture "S,N" Tag "TG_TAXA" To VSDGTAXA

    Label  @ 04,17 "Data de Emiss„o" For "TG_DTINI"
    Accept @ 05,18 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf


  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("Nao Existem Registros a Processar")
          Loop
  EndIf

   If VSDGTAXA <> "S"
      Then CopyReport "\\Base\\Sistemas\\Cobranca\\CalcCob" "3"  "Answer" "R"
      Else CopyReport "\\Base\\Sistemas\\Cobranca\\CalcCob" "9"  "Answer" "R"
   Endif

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

