;** Rm_0330  *******************************************************************
;*  Emissao dos Titulos por Emitente/EmissÆo                                   *
;*******************************************************************************
;Autor: Visao/Vise
;Desenvolvido    : 13/01/2021 por Bruno Carvalho 
;Ultima Alteracao: 14/01/2021 por Bruno Carvalho                                         
;Motivo Alteracao: Ajustes para padronizar o layout do ShowDialog
 
;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA=""
MSG_CAMPO=""
If Disparo="OPEN"  
   Then AoCriarShowDialog()
        TiraSombraShowDialog()  
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_EMPRESATE"     : Campo="NO"
            Case Campo="TG_CONTA"         : Campo="TG_EMPRESATE"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_ATIVIDADE"     : Campo="TG_DESTINAT"
            Case Campo="TG_PLCONTAS"      : Campo="TG_ATIVIDADE"
            Case Campo="TG_CCUSTO"        : Campo="TG_PLCONTAS"
            Case Campo="TG_OPCCUSTO"      : Campo="TG_CCUSTO"
            Case Campo="TG_TPPGTO"        : Campo="TG_OPCCUSTO"
            Case Campo="TG_OPDATA"        : Campo="TG_TPPGTO" 
            Case Campo="TG_DTINI"         : Campo="TG_OPDATA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_CODMODELO"     : Campo="TG_DTFIM"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESATE"
          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_EMPRESATE"     : Campo="TG_CONTA"
                    Case Campo="TG_CONTA"         : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT"      : Campo="TG_ATIVIDADE"
                    Case Campo="TG_ATIVIDADE"     : Campo="TG_PLCONTAS"
                    Case Campo="TG_PLCONTAS"      : Campo="TG_CCUSTO"   
                    Case Campo="TG_CCUSTO"        : Campo="TG_OPCCUSTO"
                    Case Campo="TG_OPCCUSTO"      : Campo="TG_TPPGTO"
                    Case Campo="TG_TPPGTO"        : Campo="TG_OPDATA"
                         VSDGTPPGTO=ControlValue("TG_TPPGTO")
                         Switch
                           Case VSDGTPPGTO="2" : VSDGNOMTPPGTO="éLTIMO/ACUMULADO"
                           otherwise           : VSDGTPPGTO="1"
                                                 VSDGNOMTPPGTO="DETALHAR"
                         EndSwitch
                    Case Campo="TG_OPDATA"        : Campo="TG_DTINI"
                         VSDGOPDATA=ControlValue("TG_OPDATA")
                         Switch
                           Case VSDGOPDATA="3" : VSDGNOMTPDATA="DATA DE COMPETENCIA"
                           Case VSDGOPDATA="2" : VSDGNOMTPDATA="DATA DE VENCIMENTO"
                           otherwise           : VSDGOPDATA="1"
                                                 VSDGNOMTPDATA="DATA DE EMISSAO"
                         EndSwitch               
                    Case Campo="TG_DTINI"         : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"         : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"     : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPDATA" :
       MSG_CAMPO="1=Data de Emiss„o  2=Data de Vencimento  3=Data de Competˆncia"
  Case Campo="TG_TPPGTO" :
       MSG_CAMPO="1=Detalhar  2=éltimo Pagto/Acumulado"     
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("26A  Por Emitente/Vencimento/Titulos")                     ;RM_0330
ModeloRelatoriosAdd("26B Por Vencimento/Emitente/Titulos")                      ;RM_0330
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("33A Por Fornecedor/Documentos/Vencimentos")                ;RM_1270
ModeloRelatoriosAdd("33B Por Fornecedor - Sint‚tico")                           ;RM_1270
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("78A Por Ordem de Data de Competˆncia")                     ;RM_1260
ModeloRelatoriosAdd("78B Por Ordem de Numero do Documento")                     ;RM_1260
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("23  Anal¡tico por Plano de contas")                        ;RM_0012   
ModeloRelatoriosAdd("27  Anal¡tico por Plano de contas/Centro de custo")        ;RM_0012A
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("24  Sint‚tico por Plano de contas")                        ;RM_0210
ModeloRelatoriosAdd("28  Sint‚tico por Plano de contas/Centro de custo")        ;RM_0210A
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("04  T¡tulos Emitidos e n„o Pagos at‚ Data Final")          ;RM_0050
ModeloRelatoriosAdd("Fim")
                                                    
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA    = ""
VSDGCONTA      = ""
VSDGDESTINAT   = ""
VSDGDTINI      = BlankDate()
VSDGDTFIM      = BlankDate()
VSDGATIVIDADE  = ""
VSDGNOMATIV    = ""
VSDGPLCONTAS   = ""
VSDGCCUSTO     = ""
VSDGTPPGTO     = ""
VSDGNOMTPPGTO  = ""  
VSDGOPDATA     = ""
VSDGNOMTPDATA  = ""
VSDGPAGINI     = 1

ModeloRelatoriosCarregaLista()
Array CheckTG_OPCCUSTO[1] CheckTG_OPCCUSTO[1]=False

While True
  ShowDialog "Rela‡Æo de T¡tulos por Emitente/Data EmissÆo" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 01,00 Height 22 Width 80

    Label  @ 00,00 "Empresa"  For "TG_EMPRESATE"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESATE" To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Conta"  For "TG_CONTA"
    Accept @ 03,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

    Label  @ 04,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 05,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    Label  @ 06,00 "Atividade"  For "TG_ATIVIDADE"
    Accept @ 07,01 Width 07 "A4"  Picture "!*!" Tag "TG_ATIVIDADE" To VSDGATIVIDADE
    Accept @ 07,09 Width 25 "A30"  Picture "#*#" Tag "TG_NOMATIV" To VSDGNOMATIV

    Label  @ 08,00 "Plano de Contas" For "TG_PLCONTAS"
    Accept @ 09,01 Width 33 "A13"  Picture "!*!" Tag "TG_PLCONTAS" To VSDGPLCONTAS                   
    Accept @ 10,01 Width 33 "A40" Picture "!*!" Tag "TG_NOMPLCONTAS"  To VSDGNOMPLCONTAS

    Label  @ 11,00 "CentroDeCusto" For "TG_CCUSTO"
    Accept @ 12,01 Width 33 "A7"  Picture "###.###" Tag "TG_CCUSTO" To VSDGCCUSTO
    Accept @ 13,01 Width 33 "A20" Picture "!*!" Tag "TG_NOMCUST"  To VSDGNOMCUST

    CheckBoxes @ 11,14 Height 1 Width 20 Tag "TG_OPCCUSTO" "NÆoVerEmBrancos" to CheckTG_OPCCUSTO[1]
 
    Label  @ 00,35 "Op‡„o de Pagamento" For "TG_TPPGTO"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2"  Tag "TG_TPPGTO"     To VSDGTPPGTO
    Accept @ 01,44 Width 25 "A20" Picture "!*!"  Tag "TG_NOMTPPGTO" To VSDGNOMTPPGTO
    
    Label  @ 02,35 "Op‡äes de Datas" For "TG_OPDATA"                                           
    Accept @ 03,39 Width 04 "A1"  Picture "1,2,3"  Tag "TG_OPDATA"    To VSDGOPDATA
    Accept @ 03,44 Width 25 "A20" Picture "!*!"  Tag "TG_NOMOPDATA" To VSDGNOMTPDATA
    
    Label  @ 04,35 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 05,38 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 05,51 "at‚" For "TG_DTFIM"
    Accept @ 05,56 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
                                                                                                              
    Label  @ 15,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 16,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 16,06  Width 71 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO        

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

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

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf
  
  If Len(VSDGPLCONTAS)<13
     Then PLCONTAS=VSDGPLCONTAS + ".."
     Else PLCONTAS=VSDGPLCONTAS
  EndIf

  If VSDGEMPRESA="0000"
     Then VSDGEMPRESA2=""
     Else VSDGEMPRESA2=VSDGEMPRESA
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf
  If Ok="A" Then IMPRIME_ARQUIVO = True Else IMPRIME_ARQUIVO=False EndIf

  Switch
    Case VSDGCODMODELO="26A" Or
         VSDGCODMODELO="26B"  : Play "RM_0330A"
    Case VSDGCODMODELO="33A" Or
         VSDGCODMODELO="33B"  : Play "RM_0330B"
    Case VSDGCODMODELO="78A" Or
         VSDGCODMODELO="78B"  : Play "RM_0330C"
    Case VSDGCODMODELO="23" Or
         VSDGCODMODELO="27" Or
         VSDGCODMODELO="24" Or
         VSDGCODMODELO="28"  : Play "RM_0330D"
    Case VSDGCODMODELO="04"  : Play "RM_0330E"          
  Endswitch
EndWhile
ClearAll
Release Vars All                     
Release Procs All
