;** PC_0001 *******************************************************************
;*  ShowDialog parametros para gera‡Æo de comissao no contas a pagar/Consignado 
;****************************************************************************** 
;Autor           : Vise Informatica (VISERP) 
;Desenvolvido    : 26/11/2019 por Anivel Augusto Rodrigues
;Ultima Alteracao: 18/03/2020 por Bruno Carvalho 
;Motivo Alteracao: Ajustes p/ nÆo deixar prosseguir quando campos obrigat¢rios nÆo forem informados

;*******************************************************************************
;* Exportacao p/ Contas a Pagar                                                *
;*******************************************************************************
Proc PC_0001_Atualiza_CTAPG()
private CP_LANC, PROXLANCTO_NLANC, 
        OBS, CODDOCTO, NUMDOCTO

CODDOCTO=rtrim(substr(RELDOCTO_VENDAPC,1,4))
NUMDOCTO=substr(RELDOCTO_VENDAPC,6,6)

OBS=PC_0001_PARAM+" A PAGAR GERADO PELO ACERTO EM "+StrVal(Today())+ "\n"
OBS=OBS+"NOTA DE VENDA: "+RELDOCTO_VENDA

Aguarde("Aguarde, gerando lan‡amentos/"+PC_0001_PARAM)

CoEdit "\\Sistemas\\CtaPag\\Titulos"

While True
  End
  Moveto [Numero do Lancamento]
  If Numero_Lancamento("Interno","Locked_Down")
     Then CP_LANC = PROXLANCTO_NLANC
          Release Vars PROXLANCTO_NLANC
          quitloop
  EndIf    
EndWhile

[Codigo da Conta         ]=VSDGCONTA
[Codigo da Empresa       ]=VSDGEMPRESA
[Codigo do Documento     ]=CODDOCTO
[Numero do Documento     ]=NUMDOCTO
[Documento Referente     ]=PC_0001_PARAM
[Codigo do Emitente      ]=VSDGDESTINAT
[Data de Emissao         ]=today()            
[Data de Entrada         ]=today()            
[Data de Vencimento      ]=VSDGDTVENCTO    
[Data a Pagar            ]=VSDGDTVENCTO
[Data Competencia        ]=VSDGDTCOMPET     
[Valor do Documento      ]=COMISSAOLIQ
[Saldo do Documento      ]=COMISSAOLIQ
[Observacoes             ]=OBS
[Tipo do Lancamento      ]=VSDGTPLANC     
[Tipo do Pagamento       ]=VSDGTPPAGTO
[Codigo Plano_Conta      ]=VSDGPLCONTAS  
[Sistema Gerador         ]="FT"
Controle_Dia()
UnLockRecord

Do_It!
Clearall

Mensagem("Fim do processo !// // Conferir lan‡amentos no Contas a Pagar/"+PC_0001_PARAM)

LimpAguarde()
endproc


;*******************************************************************************
;* Rotina gravar/ler configura‡äes/parametros                                  *
;*******************************************************************************
Proc PC_0001_ConfigOpcoesPC(operacao)
private operacao,arquivo,arqini,arqsc

arqini=PC_0001_AquivoDeParametrosGeraComissao+".ini"
arqsc =PC_0001_AquivoDeParametrosGeraComissao+".sc"

Switch
  Case operacao="Ler":

    VSDGCONTA       =""
    VSDGTPLANC      ="B"
    VSDGTPPAGTO     ="CO"
    VSDGPLCONTAS    =""
    VSDGDTCOMPET    = blankdate()
    VSDGDTVENCTO    = blankdate()

    If IsFile(arqini)
       Then
            FileRead           arqini  To   vartemp
            FileWrite Privdir()+arqsc  From vartemp
                 Play Privdir()+PC_0001_AquivoDeParametrosGeraComissao
            Deleta_Arquivo(Privdir()+arqsc)
            Deleta_Arquivo(Privdir()+PC_0001_AquivoDeParametrosGeraComissao+".sc2")
    EndIf
       
  Case operacao="Gravar":
       FileWrite        arqini From ";****** Variaveis de Parƒmetros PC_0000 Vise Informatica"+"\n"
       FileWrite Append arqini From "VSDGCONTA=\""   +VSDGCONTA+"\""     +"\n"
       FileWrite Append arqini From "VSDGTPLANC=\""  +VSDGTPLANC+"\""    +"\n"
       FileWrite Append arqini From "VSDGTPPAGTO=\"" +VSDGTPPAGTO+"\""   +"\n"
       FileWrite Append arqini From "VSDGPLCONTAS=\""+VSDGPLCONTAS+"\"" +"\n"
       FileWrite Append arqini From "VSDGPLCONTAS=\""+VSDGPLCONTAS+"\"" +"\n"
       
EndSwitch

endproc

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc PC_0001_SD_Dialog(Disparo,Campo,Evento,Elemento)
private Disparo,Campo,Evento,Elemento

Temp=True
TECLA=""
MSG_CAMPO=""
If Disparo="OPEN"  
   Then 
        AoCriarShowDialog()

        Campo="TG_CONTA"        Checa_TAG()
        Campo="TG_TPLANC"       Checa_TAG()
        Campo="TG_TPPAGTO"      Checa_TAG()
        Campo="TG_PLCONTAS"     Checa_TAG()

        Campo="TG_CONTA"
         
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_CONTA" Or        
                 Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_TPLANC"        : Campo="TG_CONTA"
            Case Campo="TG_TPPAGTO"       : Campo="TG_TPLANC"
            Case Campo="TG_PLCONTAS"      : Campo="TG_TPPAGTO"
            Case Campo="TG_DTCOMPET"      : Campo="TG_PLCONTAS"
            Case Campo="TG_DTVENCTO"      : Campo="TG_DTCOMPET"
            Case Campo="YES" Or Campo="NO": Campo="TG_CONTA"
          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" 
                         If IsBlank(VSDGEMPRESA) Then FastMsg("Informe o c¢digo da empresa!")  Campo="TG_EMPRESA" EndIf
                    Case Campo="TG_CONTA"        : Campo="TG_TPLANC" 
                         If IsBlank(VSDGCONTA)   Then FastMsg("Informe a Conta!")              Campo="TG_CONTA"   EndIf
                    Case Campo="TG_TPLANC"       : Campo="TG_TPPAGTO"                                             
                         If IsBlank(VSDGTPLANC)  Then FastMsg("Informe o Tipo de Lan‡amento!") Campo="TG_TPLANC"  EndIf
                    Case Campo="TG_TPPAGTO"      : Campo="TG_PLCONTAS"
                         If IsBlank(VSDGTPPAGTO) Then FastMsg("Informe a Forma de Pagamento!") Campo="TG_TPPAGTO" EndIf
                    Case Campo="TG_PLCONTAS"     : Campo="TG_DTCOMPET"
                    Case Campo="TG_DTCOMPET"     : Campo="TG_DTVENCTO"
                    Case Campo="TG_DTVENCTO"     : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo=""        : MSG_CAMPO=""
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
Proc PC_0001_Principal()
private rotinaok

LimpAguarde()

;fazer verifica‡Æo de clientes, liber rotina mediante pagamento de valor, ver com An¡vel
;verificar rotina que gera os dados, padronizar e personalizar conforme necessario
;orientar cliente do funcionamento desta rotina 

rotinaok=false
switch
;;case sys_Codigo_Cliente="0000" and PC_0001_AquivoDeParametrosGeraComissao="PC_1501" : rotinaok=true 

  otherwise                                                                           : rotinaok=true
endswitch

if not rotinaok
   then
        Mensagem("Gerar lan‡amentos das comissäes no Contas a Pagar// //"+
                 "Rotina nÆo configurada e personalizada para o cliente !!// //"+
                 " Verificar com Suporte da Vise !")
        return
endif   

PC_0001_ConfigOpcoesPC("Ler")

While True
  ShowDialog PC_0001_PARAM+", gerar lan‡amentos no Contas a Pagar" Proc "PC_0001_SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 16 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 "Tipo de Lan‡amento * "  For "TG_TPLANC"
    Accept @ 05,04 Width 04 "A1"  Picture "!*!" Tag "TG_TPLANC" To VSDGTPLANC
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMLANC"  To VSDGNOMLANC

    Label  @ 06,00 "Forma de Pagamento * "  For "TG_TPPAGTO"
    Accept @ 07,03 Width 05 "A2"  Picture "!*!" Tag "TG_TPPAGTO"    To VSDGTPPAGTO
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMTPPG"    To VSDGNOMTPPAGTO

    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  @ 00,35 "Data de Competˆncia * " For "TG_DTCOMPET"
    Accept @ 01,36 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTCOMPET" To VSDGDTCOMPET

    Label  @ 02,35 "Data de Vencimento * " For "TG_DTVENCTO"
    Accept @ 03,36 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTVENCTO" To VSDGDTVENCTO

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If isblank(VSDGEMPRESA)     or
     isblank(VSDGCONTA)       or
     isblank(VSDGTPPAGTO)     or
     isblank(VSDGTPLANC)      or
     VSDGDTCOMPET=BlankDate() or
     VSDGDTVENCTO=BlankDate()
     Then FastMsg("Verificar campos obrigat¢rios (*) !")
          Loop
  EndIf

  PC_0001_ConfigOpcoesPC("Gravar")

  AGUARDE("Aguarde, Gerando Dados")

  PC_0001_Atualiza_CTAPG()
  
  QuitLoop
  
EndWhile
ClearAll

endproc

;*******************************************************************************
;*                                                                             *
;*******************************************************************************

PC_0001_Principal()

Release Vars VSDGCONTA, VSDGTPLANC, VSDGTPPAGTO, VSDGPLCONTAS, VSDGDTCOMPET, VSDGDTVENCTO, 
             PC_0001_AquivoDeParametrosGeraComissao,PC_0001_PARAM
             
Release Procs PC_0001_Atualiza_CTAPG, PC_0001_ConfigOpcoesPC , PC_0001_SD_Dialog, PC_0001_Principal
