;** Rm_0310  *******************************************************************
;*  Relacao de Borderos de Cheques                                             *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 26/11/2003 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/02/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Mudan‡a Tabela Temporaria PrivDir()
;Ultima Alteracao: 26/04/2012 por Bruno Carvalho
;Motivo Alteracao: Add Filtro por Destinat rio
;Ultima Alteracao: 09/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 26/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes showdialog TG_DESTINAT                   
;Ultima Alteracao: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog modelo relatorio  

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc Seleciona()
ClearAll
If IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"BordChC") And
   IsTable("\\Sistemas\\Cheqrec\\"+Dir_Trab+"BordChI")
  Then {Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"BordChC" Enter Check
        Moveto [Numero do Lote      ] Example "NUM"
        Moveto [Codigo da Empresa   ] TypeIn  "~VSDGEMPRESA.."
        Moveto [Data do Lote        ] TypeIn  ">=~VSDGDTINI ,<=~VSDGDTFIM"
        Moveto [Codigo              ] TypeIn "~VSDGDESTINAT.."
        {Ask} TypeIn "\\Sistemas\\CheqRec\\"+Dir_Trab+"BordChI" Enter Check
        Moveto [Numero do Lote      ] Example "NUM"
        Do_It!
        ClearAll
EndIf
EndProc   ; (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc Processa()

{Modify} {Restructure} TypeIn Tabela Enter
End Down
"Numero de Dias"    Enter "S" Enter
"Valor do Desconto" Enter  "$"
Do_It! ClearImage

View "\\Sistemas\\Cadastro\\Feriados"
CoEdit Tabela
Scan 
  if isBlank([Data Vencimento]) then loop endif

  While True
      NDIAS=0
      If Dow([Data Vencimento])="Sat"
         Then NDIAS=2
         Else If Dow([Data Vencimento])="Sun"
                 Then NDIAS=1
              EndIf
      EndIf

      DIA = [Data Vencimento]
      Moveto "\\Sistemas\\Cadastro\\Feriados"
      Moveto [Data do Feriado]
      Locate DIA
      If Retval
         Then If [Dias a Receber]>0
                 Then NDIAS=[Dias a Receber]
              EndIf
      EndIf

      Moveto Tabela
      [Data Vencimento]=DIA+NDIAS
      If NDIAS=0
         Then QuitLoop
      EndIf
   EndWhile

   [Numero de Dias   ]=[Data Vencimento]-[Data do Lote]
   [Valor do Desconto]=Round(([Valor]*(([Taxa Mensal]/30)*[Numero de Dias]))/100,2)
EndScan
Do_It!
ClearAll

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_DESTINAT"      : Campo="TG_EMPRESA"
            Case Campo="TG_DTINI"         : Campo="TG_DESTINAT"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_CODMODELO"     : 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_DTINI"
                    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
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc   ; (SD_Dialog)

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

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Por Lote + Cheques")
ModeloRelatoriosAdd("01B Por Lote")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

VSDGEMPRESA =""
VSDGDESTINAT=""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()

ModeloRelatoriosCarregaLista()

While True
  ShowDialog "Rela‡„o de Borderos de Cheques" 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 14 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 "Pessoa"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    Label  @ 04,00 "Perˇodo Referente de" For "TG_DTINI"
    Accept @ 05,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 05,16 "at‚" For "TG_DTFIM"
    Accept @ 05,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 07,00  "Modelo de ~R~elat˘rio"  For "TG_CODMODELO"
    Accept @ 08,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 08,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO        

    Pushbutton @ 10,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 10,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 VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          Loop
  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()
    If Not IsTable("Answer") Then Loop EndIf
    If IsTable(Tabela)
       Then Add "Answer" Tabela
       Else Rename "Answer" Tabela
    EndIf
  EndWhile

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

  Processa()
  switch
    case VSDGCODMODELO="01"  : CopyReport "\\Base\\Sistemas\\Cheqrec\\Rm_0021" "2" Tabela "R"
    case VSDGCODMODELO="01B" : CopyReport "\\Base\\Sistemas\\Cheqrec\\Rm_0021" "3" Tabela "R"
  endswitch
  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All

