;** TransfCB  ******************************************************************
;*  Exportacao P/ Drive   (MovCont)                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 13/01/2009 por Anivel Augusto Rodrigues
;Ultima Alteracao: 06/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 05/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 22/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 08/08/2017 por Bruno Carvalho
;Motivo Alteracao: Adicionado Gera_Log()
;Ultima Alteracao: 24/10/2017 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes historico acerto            
;Ultima Alteracao: 07/06/2018 por Bruno Carvalho
;Motivo Alteracao: Adicionado/ajustado Grava_LogEx()
;Ultima Alteracao: 14/05/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_CCUSTO            

;*******************************************************************************
;* ROTINA PROCESSA  -> realiza o processamento da Transferencia                *
;*******************************************************************************
Proc PROCESSA()

AGUARDE("Aguarde, Transferindo Caixa/Banco")
ClearAll

{Ask} {MovCont} Check
Moveto [Codigo da Empresa  ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo da Conta    ] TypeIn "~VSDGCONTA.."
Moveto [Data               ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
Moveto [Codigo CCusto      ] TypeIn "~VSDGCCUSTO.."
Do_It!
ClearAll

switch
  case sys_Codigo_Cliente="0294":
    if not isempty("Answer")
       then
            Edit "Answer"
            scan 
              if [Sistema Gerador]="AF" and searchfrom("ACFIN",[Descricao do Historico],1)>0 and searchfrom(", ",[Descricao do Historico],1)>0
                 then [Descricao do Historico]="ACFIN, "+substr([Descricao do Historico],(searchfrom(", ",[Descricao do Historico],1)+2),70)
              endif                
            endscan
            do_it!
            clearall       
    endif   
 
endswitch

If IsTable(VSDGDRIVE+"\\Movcont")
   Then Delete VSDGDRIVE+"\\Movcont"
Endif
Create VSDGDRIVE+"\\Movcont" Like "Movcont"
Add "Answer" VSDGDRIVE+"\\Movcont"
ClearAll

Limpaguarde()
MENSAGEM("Opera‡„o Finalizada !")
EndProc

;*******************************************************************************
;* Rotina para gerar o log de registro por usu rio                             *
;*******************************************************************************
Proc Gera_Log()          
;---- Gravando LOG ---------------------------------------------------
If VSDGDTINI<>BlankDate()
   Then AUX_DATA = ", periodo de "+StrVal(VSDGDTINI)+" ate "+StrVal(VSDGDTFIM)
   Else AUX_DATA = ", periodo ate "+StrVal(VSDGDTFIM)
EndIf   

AUX_OPCAO = ""
If VSDGCONTA<>""  Then AUX_OPCAO = AUX_OPCAO + "Conta: "+VSDGCONTA+", "            EndIf 
If VSDGCCUSTO<>"" Then AUX_OPCAO = AUX_OPCAO + "Centro de Custo: "+VSDGCCUSTO+", " EndIf
AUX_OPCAO = Rtrim(AUX_OPCAO)
If SubStr(AUX_OPCAO,Len(AUX_OPCAO),1)="," Then AUX_OPCAO = Substr(AUX_OPCAO,1,Len(AUX_OPCAO)-1) EndIf

Grava_LogEx("Ctacor TransfCB")

EndProc ;Gera_Log() 

;*******************************************************************************
;* 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_CCUSTO"        : Campo="TG_CONTA"
            Case Campo="TG_DTINI"         : Campo="TG_CCUSTO"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_DRIVES"        : 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_CONTA"
                    Case Campo="TG_CONTA"      : Campo="TG_CCUSTO"
                    Case Campo="TG_CCUSTO"     : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_DRIVES"
                    Case Campo="TG_DRIVES"     : Campo="YES"
                         VSDGDRIVE=ControlValue("TG_DRIVES")
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO=""
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

sys_Valor()

VSDGEMPRESA=""
VSDGCONTA  =""
VSDGCCUSTO =""
VSDGDTINI  =BlankDate()
VSDGDTFIM  =BlankDate()

DynArray Array_Drives[]
SysInfo Drives To Array_Drives
VSDGDRIVE="C:"

While True
  ShowDialog "Exporta‡„o Movimentos Caixa/Banco" 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 "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 "CentroDeCusto" For "TG_CCUSTO"
    Accept @ 05,01 Width 33 "A7"  Picture "###.###" Tag "TG_CCUSTO" To VSDGCCUSTO
    Accept @ 06,01 Width 33 "A20" Picture "!*!" Tag "TG_NOMCUST"  To VSDGNOMCUST

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

    Label  @ 00,35 "Drives:" For "TG_DRIVES"
    PickDynArrayIndex @ 01,36 Height 4 width 33
     Columns 7
      Array_Drives
       Tag "TG_DRIVES"
        To VSDGDRIVE

    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

  Gera_Log()
  Processa()

EndWhile
ClearAll
Release Vars All
Release Procs All
