;** Rm_0200 ********************************************************************
;*  Emissao dos Titulos Baixados                                               *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 31/12/2020 por Bruno Carvalho
;Ultima Alteracao:   /  /     por                          
;Motivo Alteracao:

;*******************************************************************************
;* 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_NCONTROLE" : Campo="TG_EMPRESA"   
            Case Campo="TG_NCARREG"   : Campo="TG_NCONTROLE"   
            Case Campo="TG_AREA"      : Campo="TG_NCARREG"     
            Case Campo="TG_CONTA"     : Campo="TG_AREA"        
            Case Campo="TG_REPRESEN"  : Campo="TG_CONTA"       
            Case Campo="TG_OPCAO"     : Campo="TG_REPRESEN"    
            Case Campo="TG_DTINI"     : Campo="TG_OPCAO"       
            Case Campo="TG_DTFIM"     : Campo="TG_DTINI"       
            Case Campo="TG_DESTINAT"  : Campo="TG_DTFIM"       
            Case Campo="TG_CHAPA"     : Campo="TG_DESTINAT"    
            Case Campo="TG_TPBAIXA"   : Campo="TG_CHAPA"       
            Case Campo="TG_CODMODELO" : Campo="TG_TPBAIXA"            
            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_NCONTROLE"
                    Case Campo="TG_NCONTROLE" : Campo="TG_NCARREG"  
                    Case Campo="TG_NCARREG"   : Campo="TG_AREA"     
                         If IsBlank(VSDGNCARREG)
                            Then Campo="TG_AREA"
                            Else VSDGAREA    =""
                                 VSDGCONTA   =""
                                 VSDGREPRESEN=""
                                 VSDGDESTINAT=""
                                 VSDGCHAPA   =""
                                 VSDGDTINI   =BlankDate()
                                 VSDGDTFIM   =BlankDate()
                                 VSDGOPCAO   =""
                                 Campo="TG_TPBAIXA"
                         EndIf
                    Case Campo="TG_AREA"      : Campo="TG_CONTA"    
                    Case Campo="TG_CONTA"     : Campo="TG_REPRESEN" 
                    Case Campo="TG_REPRESEN"  : Campo="TG_OPCAO"    
                    Case Campo="TG_OPCAO"     : Campo="TG_DTINI"
                         VSDGOPDT=ControlValue("TG_OPCAO")
                         Switch
                           Case VSDGOPDT="2": VSDGDESCOPDT="DATA DE INCLUSAO"
                           OtherWise        : VSDGOPDT="1"
                                              VSDGDESCOPDT="DATA DE PAGAMENTO"
                         EndSwitch    
                    Case Campo="TG_DTINI"     : Campo="TG_DTFIM"    
                    Case Campo="TG_DTFIM"     : Campo="TG_DESTINAT" 
                    Case Campo="TG_DESTINAT"  : Campo="TG_CHAPA"    
                    Case Campo="TG_CHAPA"     : Campo="TG_TPBAIXA"  
                    Case Campo="TG_TPBAIXA"   : Campo="TG_CODMODELO"
                         VSDGTPBAIXA=ControlValue("TG_TPBAIXA")
                         Switch
                           Case VSDGTPBAIXA="D": VSDGNOMTPBAIXA="DEVOLUCAO"
                           Case VSDGTPBAIXA="C": VSDGNOMTPBAIXA="CANCELADO"
                           Case VSDGTPBAIXA="N": VSDGNOMTPBAIXA="NORMAL"
                           OtherWise           : VSDGNOMTPBAIXA="TODAS"
                         EndSwitch
                    Case Campo="TG_CODMODELO" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPCAO":
       MSG_CAMPO="Op‡„o: 1=Pagamento  2=Inclusao"
  Case Campo="TG_TPBAIXA":
       MSG_CAMPO=" N=Normal  D=Devolu‡„o  C=Cancelado"
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("61A Data de Inclusao - Modelo I")
ModeloRelatoriosAdd("61B Data de Inclusao - Modelo II")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("61C N§ Controle - Modelo I")
ModeloRelatoriosAdd("61D N§ Controle - Modelo II")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("13  Modelo III")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA  =""
VSDGCHAPA    =""
VSDGNCONTROLE=""
VSDGNCARREG =""
VSDGAREA    =""
VSDGCONTA   =""
VSDGDESTINAT=""
VSDGTPBAIXA =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()

ModeloRelatoriosCarregaLista()

While True
  ShowDialog "T¡tulos Baixados" 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 20 Width 72
    
    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP
    
    Label  @ 02,00 "Controle Dia" For "TG_NCONTROLE"
    Accept @ 03,01 Width 9  "A6"  Picture "#*#" Tag "TG_NCONTROLE"    To VSDGNCONTROLE
    Accept @ 03,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMNCONTROLE" To VSDGNOMNCONTROLE    

    Label  @ 04,00 "Carregamento" For "TG_NCARREG"
    Accept @ 05,01 Width 9  "A6"  Picture "[&,#][#*#]" Tag "TG_NCARREG"    To VSDGNCARREG
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMNCARREG" To VSDGNOMNCARREG

    Label  @ 06,00 "Area"  For "TG_AREA"
    Accept @ 07,03 Width 05 "A2"  Picture "#*#" Tag "TG_AREA" To VSDGAREA
    Accept @ 07,09 Width 25 "A30"  Picture "!*!" Tag "TG_NOMAREA" To VSDGNOMAREA

    Label  @ 08,00 "Conta"  For "TG_CONTA"
    Accept @ 09,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA" To VSDGCONTA
    Accept @ 09,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMCONT" To VSDGNOMCONTA

    Label  @ 10,00 "Representante"  For "TG_REPRESEN"
    Accept @ 11,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN" To VSDGREPRESEN
    Accept @ 11,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMREPR"  To VSDGNOMREPR

    Label  @ 00,35 "Op‡äes de Datas"  For "TG_OPCAO"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPCAO" To VSDGOPCAO
    Accept @ 01,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMOPCAO" To VSDGNOMOPCAO    
    
    Label  @ 02,35 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 03,38 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 03,51 "at‚" For "TG_DTFIM"
    Accept @ 03,56 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 04,35 "Pessoa"  For "TG_DESTINAT"
    Accept @ 05,36 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMCLI" To VSDGNOMDEST

    Label  @ 06,35 "Usuario"  For "TG_CHAPA"
    Accept @ 07,36 Width 07 "A4"  Picture "#*#" Tag "TG_CHAPA"     To VSDGCHAPA
    Accept @ 07,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMCHAPA"  To VSDGNOMCHAPA

    Label  @ 08,35 "Op‡Æo de Baixa"  For "TG_TPBAIXA"
    Accept @ 09,39 Width 04 "A1"  Picture "N,D,C" Tag "TG_TPBAIXA" To VSDGTPBAIXA
    Accept @ 09,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMTPBAIXA" To VSDGNOMTPBAIXA
    
    Label  @ 13,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 14,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 14,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf
  if not ValidarModelosRelatorios() then loop endif         

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

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

  DISPOSITIVO()
  If OK="" Then Loop EndIf
  
  Switch
    case VSDGCODMODELO="61A" Or
         VSDGCODMODELO="61B" Or
         VSDGCODMODELO="61C" Or
         VSDGCODMODELO="61D" : Play "RM_2010A"
    case VSDGCODMODELO="13"  : Play "RM_0200A" 
  Endswitch
EndWhile
ClearAll
Release Vars All
Release Procs All