;** Rm_0275  *******************************************************************
;*  Emissao dos Titulos Emitidos por Cliente                                   *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 14/05/2003 por Karen Lauar Nery
;Motivo Alteracao: Mudan‡a Base
;Ultima Alteracao: 20/09/2012 por Anivel Augusto Rodrigues
;Motivo Alteracao: Mudan‡a Base

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc SELECIONA()
ClearAll
{Ask} {Duplic} Check
Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."
If VSDGTPDATA="1"
   Then Moveto [Data de Emissao    ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
   Else Moveto [Data de Vencimento ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
EndIf
Moveto [Codigo do Destinatario ] TypeIn "~VSDGDESTINAT.."
Do_It!
ClearAll
If Not IsEmpty("Answer")
   Then If VSDGOPRELANALSINT="1"
           Then CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0200" "R" "Answer" "R"
           Else CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0200" "1" "Answer" "R"
        EndIf
EndIf
EndProc

;*******************************************************************************
;* Rotina p/ processar Db temporaria                                           *
;*******************************************************************************
Proc Processa()

Coedit "Answer"
Scan
  If IsBlank([Valor da Comissao]) Then [Valor da Comissao]=0 EndIf
  If IsBlank([Saldo da Comissao]) Then [Saldo da Comissao]=0 EndIf
EndScan
Do_It!
ClearAll
EndProc   ; (Processa)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA    =""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     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_TPDATA"        : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"         : Campo="TG_TPDATA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_OPRELANALSINT" : Campo="TG_DTFIM"
            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"   : Campo="TG_TPDATA"
                    Case Campo="TG_TPDATA"          :
                         VSDGTPDATA   =ControlValue("TG_TPDATA")
                         If VSDGTPDATA="1"
                            Then VSDGNOMTPDATA="EMISSAO"
                            Else VSDGNOMTPDATA="VENCIMENTO"
                         EndIf
                         If IsBlank(VSDGTPDATA)
                            Then VSDGTPDATA   ="1"
                                 VSDGNOMTPDATA="EMISSAO"
                         EndIf
                         Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_OPRELANALSINT"
                    Case Campo="TG_OPRELANALSINT" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
       MSG_CAMPO=""
  Case Campo="TG_TPDATA":
       MSG_CAMPO="1 = EMISSAO  2 = VENCIMENTO"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGDESTINAT=""
VSDGTPDATA           =""
VSDGNOMTPDATA        =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()
VSDGOPRELANALSINT=""

While True
  ShowDialog "Tˇtulos Emitidos por Cliente" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 15 Width 56

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

    Label  @ 04,00 "Op‡„o de Data" For "TG_TPDATA"
    Accept @ 05,01 Width 07 "A1"  Picture "1,2"  Tag "TG_TPDATA"     To VSDGTPDATA
    Accept @ 05,09 Width 23 "A18" Picture "!*!"  Tag "TG_NOMOTPDATA" To VSDGNOMTPDATA

    Label  @ 06,00 "Perˇodo de Referente" For "TG_DTINI"
    Label  @ 07,00 "de" For "TG_DTINI"
    Accept @ 07,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 07,17 "at‚" For "TG_DTFIM"
    Accept @ 07,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 08,00 "Op‡„o do Relat˘rio" For "TG_OPRELANALSINT"
    Accept @ 09,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELANALSINT" To VSDGOPRELANALSINT
    Accept @ 09,06 Width 28 "A25"  Picture "!*!" Tag "TG_NOMOPRELANASINT" To VSDGNOMOPRELANALSINT

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Selecionando registros")
  SELECIONA()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o existem registros a processar")
          Loop
  EndIf
  Processa()

  IMPRIREL("Answer","R")
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

