;** Rm_0090  *******************************************************************
;*  Relacao de Pagamentos                                                      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/02/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Mudan‡a Tabela Temporaria PrivDir()
;Ultima Alteracao: 28/05/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Modelo Relatorio
;Ultima Alteracao: 04/06/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Modelo Relatorio
;Ultima Alteracao: 21/09/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Modelo Relatorio
;Ultima Alteracao: 05/05/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: TOTALIZA EMPRESAS
;Ultima Alteracao: 28/07/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes de data para cheques Pre-Datados
;Ultima Alteracao: 29/03/2010 por Bruno Carvalho
;Motivo Alteracao: Ajustes de Relat¢rio p/ Controle Emitente/Dia

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

If IsTable("\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont")
  Then {Ask} TypeIn "\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont" Enter Check
       Moveto [Codigo da Empresa ] TypeIn "~VSDGEMPRESA2.."
       Moveto [Codigo da Conta   ] TypeIn "~VSDGCONTA.."
       Moveto [Tipo de Operacao  ] TypeIn "06 Or 13 Or 14"
       Moveto [Tipo Movimento    ] TypeIn "S"
       Moveto [Data              ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
       Moveto [Codigo do EmitDest] TypeIn "~VSDGDESTINAT.."
       Moveto [Tipo do Lancamento] TypeIn "~VSDGTPLANC.."
       Do_It!
       ClearAll

       If IsTable(Tabela)
          Then Add "Answer" Tabela
          Else Rename "Answer" Tabela
       EndIf

       {Ask} TypeIn "\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont" Enter Check
       Moveto [Codigo da Empresa ] TypeIn "~VSDGEMPRESA2.."
       Moveto [Codigo da Conta   ] TypeIn "~VSDGCONTA.."
       Moveto [Tipo de Operacao  ] TypeIn "05"
       Moveto [Tipo Movimento    ] TypeIn "S"
       Moveto [Cheque Pre-Datado ] TypeIn "N"
       Moveto [Data              ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
       Moveto [Codigo do EmitDest] TypeIn "~VSDGDESTINAT.."
       Moveto [Tipo do Lancamento] TypeIn "~VSDGTPLANC.."
       Do_It!
       ClearAll

       If IsTable(Tabela)
          Then Add "Answer" Tabela
          Else Rename "Answer" Tabela
       EndIf



       {Ask} TypeIn "\\Sistemas\\Ctacor\\"+Dir_Trab+"MovCont" Enter Check
       Moveto [Codigo da Empresa     ] TypeIn "~VSDGEMPRESA2.."
       Moveto [Codigo da Conta       ] TypeIn "~VSDGCONTA.."
       Moveto [Tipo de Operacao      ] TypeIn "05"
       Moveto [Tipo Movimento        ] TypeIn "S"
       Moveto [Cheque Pre-Datado     ] TypeIn "S"
       Switch
         Case VSDGTPDATA="1": Moveto [Data                  ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
         Case VSDGTPDATA="2": Moveto [Data Cheque Pre-Datado] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
         Case VSDGTPDATA="3": Moveto [Data Cheque Descontado] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
       EndSwitch
       Moveto [Codigo do EmitDest    ] TypeIn "~VSDGDESTINAT.."
       Moveto [Tipo do Lancamento    ] TypeIn "~VSDGTPLANC.."
       Do_It!
       ClearAll

       If Not IsEmpty("Answer")
          Then If VSDGTPDATA="2" Or VSDGTPDATA="3"
                  Then {Ask} {Answer} TypeIn "Fast"
                       Moveto [Data                  ] TypeIn "Changeto " Example "dt"
                       Switch
                         Case VSDGTPDATA="2": Moveto [Data Cheque Pre-Datado] Example "dt"
                         Case VSDGTPDATA="3": Moveto [Data Cheque Descontado] Example "dt"
                       EndSwitch
                       Do_It!
                       ClearAll

                       If IsTable(Tabela)
                          Then Add "Answer" Tabela
                          Else Rename "Answer" Tabela
                       EndIf
               EndIf
       EndIf
EndIf

EndProc   ;  (Seleciona)

;*******************************************************************************
;* ROTINA Ajusta Dados Empresa                                                 *
;*******************************************************************************
Proc Processa()

;***** Ajusta Dados ************************************
If VSDGEMPRESA="0000"
   Then {Ask} TypeIn Tabela Enter TypeIn "Fast"
        Moveto [Codigo da Empresa      ] TypeIn "changeto 0000"
        Moveto [Nome Fantasia Empresa  ] TypeIn "changeto TOTALIZA EMPRESAS"
        Do_It!
        ClearAll
EndIf

EndProc

;*******************************************************************************
;* 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_CONTA"         : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINAT"      : Campo="TG_CONTA"
            Case Campo="TG_TPDATA"        : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"         : Campo="TG_TPDATA"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_TPLANC"        : Campo="TG_DTFIM"
            Case Campo="TG_MODELOREL"     : Campo="TG_TPLANC"
            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_CONTA"
                    Case Campo="TG_CONTA"   : Campo="TG_DESTINAT"
                    Case Campo="TG_DESTINAT": Campo="TG_TPDATA"
                    Case Campo="TG_TPDATA"  : Campo="TG_DTINI"
                         VSDGTPDATA=ControlValue("TG_TPDATA")
                         Switch
                           Case VSDGTPDATA="1": VSDGNOMTPDATA="EMISSAO"
                           Case VSDGTPDATA="3": VSDGNOMTPDATA="DESCONTADO"
                           OtherWise          : VSDGNOMTPDATA="PRE-DATADO"
                                                VSDGTPDATA="2"
                         EndSwitch
                    Case Campo="TG_DTINI"   : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   : Campo="TG_TPLANC"
                    Case Campo="TG_TPLANC"  : Campo="TG_MODELOREL"
                    Case Campo="TG_MODELOREL"  : Campo="YES"
                         VSDGMODELOREL=ControlValue("TG_MODELOREL")
                         Switch
                           Case VSDGMODELOREL="2": VSDGNOMMODELOREL="EMITENTE"
                           Case VSDGMODELOREL="3": VSDGNOMMODELOREL="DATA ANO/MES/DIA"
                           Case VSDGMODELOREL="4": VSDGNOMMODELOREL="DATA ANO/MES"
                           Case VSDGMODELOREL="5": VSDGNOMMODELOREL="EMITENTE/DIA"
                           OtherWise:
                                VSDGMODELOREL="1"  VSDGNOMMODELOREL="TPLANCTO/EMITENTE"
                         EndSwitch
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_MODELOREL":
       MSG_CAMPO="Modelo: 1=TpLan‡/Emitente 2=Emitente 3=DtAno/M/D 4=DtAno/Mes 5=Emitente/Dia"
  Case Campo="TG_TPDATA":
       MSG_CAMPO="DATA CH: 1 = EMISSAO  2 = PRE-DATADO  3 = DESCONTADO"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA  =""
VSDGCONTA    =""
VSDGDESTINAT =""
VSDGTPLANC   =""
VSDGDTINI    =BlankDate()
VSDGDTFIM    =BlankDate()
VSDGMODELOREL=""
VSDGTPDATA   ="2"

While True
  ShowDialog "Posi‡„o de Pagamentos Realizados" 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 17 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 "Conta"  For "TG_CONTA"
    Accept @ 03,01 Width 07 "A4"  Picture "#*#" Tag "TG_CONTA"    To VSDGCONTA
    Accept @ 03,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMCONTA" To VSDGNOMCONTA

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

    Label  @ 06,00 "Op‡„o de Data Cheque Pre-Datado" For "TG_TPDATA"
    Accept @ 07,01 Width 07 "A1"  Picture "1,2,3"  Tag "TG_TPDATA"     To VSDGTPDATA
    Accept @ 07,09 Width 23 "A18" Picture "!*!"  Tag "TG_NOMTPDATA" To VSDGNOMTPDATA

    Label  @ 08,00 "Periodo Referente" For "TG_DTINI"
    Label  @ 09,00 "de" For "TG_DTINI"
    Accept @ 09,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 09,17 "at‚" For "TG_DTFIM"
    Accept @ 09,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 10,00 "Tipo de Lan‡amento"  For "TG_TPLANC"
    Accept @ 11,01 Width 04 "A1"  Picture "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Z" Tag "TG_TPLANC" To VSDGTPLANC
    Accept @ 11,06 Width 23 "A20" Picture "!*!" Tag "TG_NOMLANC"  To VSDGNOMLANC

    Label  @ 10,30 "Modelo Relat¢rio" For "TG_MODELOREL"
    Accept @ 11,31 Width 04 "A1"   Picture "1,2,3,4,5" Tag "TG_MODELOREL" To VSDGMODELOREL
    Accept @ 11,36 Width 18 "A15"  Picture "!*!" Tag "TG_NOMMODELOREL" To VSDGNOMMODELOREL

    Pushbutton @ 13,14 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 13,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

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

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  Tabela=Cria_Temp(PrivDir())

  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    Seleciona()
  EndWhile

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

  Processa()

  If VSDGMODELOREL="1" Then CopyReport "\\Base\\Sistemas\\Ctacor\\MovCont" "2" Tabela "R" EndIf
  If VSDGMODELOREL="2" Then CopyReport "\\Base\\Sistemas\\Ctacor\\MovCont" "3" Tabela "R" EndIf
  If VSDGMODELOREL="3" Then CopyReport "\\Base\\Sistemas\\Ctacor\\MovCont" "8" Tabela "R" EndIf
  If VSDGMODELOREL="4" Then CopyReport "\\Base\\Sistemas\\Ctacor\\MovCont" "9" Tabela "R" EndIf
  If VSDGMODELOREL="5" Then CopyReport "\\Base\\Sistemas\\Ctacor\\MovCont" "10" Tabela "R" EndIf  

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
