;** Rm_2020 *********************************************************************
;*  Imprime Boleta                                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/11/95 por Anivel Augusto Rodrigues
;Ultima Alteracao: 14/05/03 por Karen Lauar Nery
;Motivo Alteracao: Mudan‡a de Vers„o
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes Show Dialog TG_DESTINAT

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

MESEXTENSO=MESEXT(NumVal(Substr(VSDGDTREF,4,2)))

{Ask} {CalcCob} Check
Moveto [Formulario       ] TypeIn "1.."
Moveto [Codigo da Empresa] TypeIn "~VSDGEMPRESA.."
If Not IsBlank(VSDGDESTINAT)
   Then Moveto [Codigo         ] TypeIn "~VSDGDESTINAT.."
   Else Moveto [Codigo         ] TypeIn ">=~VSDGDESTINATINI, <=~VSDGDESTINATFIM"
EndIf
Do_It!
ClearAll
If IsEmpty("Answer")
   Then Return
EndIf

 CoEdit "Answer"
 Scan
   [Documento no Banco]=StrVal(NumVal(VSDGBOLETA))
   VSDGBOLETA=StrVal(NumVal(VSDGBOLETA)+1)
 EndScan
 Do_It!
 ClearAll

 Add "Answer" "CalcCob"
 ClearAll

  CopyReport "Rm_2000" PARAM_REPORT_NORMAL "Answer" "R"   ;10

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_DTREF"         : Campo="TG_DESTINAT"
            Case Campo="TG_BOLETA"        : Campo="TG_DTREF"
            Case Campo="TG_TAXA"          : Campo="TG_FORMULARIO"
            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_DTREF"
                            Else Campo="TG_DESTINATINI"
                         EndIf
                    Case Campo="TG_DESTINATINI": Campo="TG_DESTINATFIM"
                    Case Campo="TG_DESTINATFIM": Campo="TG_DTREF"
                    Case Campo="TG_DTREF"      : Campo="TG_BOLETA"
                    Case Campo="TG_BOLETA" :
                         VSDGBOLETA=ControlValue("TG_BOLETA")
                         Campo= "TG_TAXA"
                    Case Campo="TG_TAXA"         :
                         VSDGTAXA=ControlValue("TG_TAXA")
                         If IsBlank(VSDGTAXA)
                            Then VSDGTAXA="N"
                            Else Campo="YES"
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
 Case Campo="TG_BOLETA":
     MSG_CAMPO="Informe o numero da Boleta inicial sem o Digito Verificador"
 Case Campo="TG_TAXA":
    MSG_CAMPO=" S=Sim  N=N„o  "
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

View NoWindow "P_Boleta"
PARAM_REPORT_NORMAL    =[Report Normal]

SEQUENCIA         ="0"
VSDGEMPRESA       = ""
VSDGDESTINAT      =""
VSDGBOLETA        ="0"
VSDGDESTINATINI   = ""
VSDGDESTINATFIM   = ""
VSDGTAXA          = ""
VSDGDTREF         = BlankDate()

While True

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

    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 1,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 1,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMP" 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 "Data Referente" For "TG_DTREF"
    Accept @ 05,01 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTREF" To VSDGDTREF

    Label  @ 04,17 "Boleta Inicial"  For "TG_BOLETA"
    Accept @ 05,18 Width 18 "A18"  Picture "#*#" Tag "TG_BOLETA" To VSDGBOLETA

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

    Pushbutton @ 09,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,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, Processando ...")
  Seleciona()

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

  If VSDGTAXA<> "S"
     Then CopyReport "Rm_2000" PARAM_REPORT_NORMAL     "Answer" "R"
     Else CopyReport "Rm_2000" PARAM_REPORT_TX_BALANCO "Answer" "R"
  Endif


  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

