× Linguagem de Programação ADVPL

Perguntas Schedule

Mais
11 anos 3 meses atrás #10235 por Rick
Schedule foi criado por Rick
E aí galera,

O que eu posso fazer para rodar automaticamente um relatório custumizado

Desenvolvi o relatório X. Gostaria que todos os dias na hora X esse relatório seja estraído, salvo em algum diretório específico ou mesmo enviado por e-mail.

Quem pode me ajudar?

Por favor Acessar ou Registrar para participar da conversa.

Mais
11 anos 3 meses atrás #10239 por lalberto
Respondido por lalberto no tópico Schedule
Segue um exemplo, o ideal é vc ao inves de mandar o relatorio, manda-lo em formato de email.

#include "ap5mail.ch"
#Include 'Rwmake.ch'
#include 'Topconn.ch'

/*
ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
±±ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿±±
±±³Programa ³ RELEXP ³ Luiz Alberto ³ Data ³ 08/09/10 ³±±
±±ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄ´±±
±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
*/
User Function RelExp()
RPCSetType( 3 )
RpcSetEnv('01','01',,,,GetEnvServer(),{ }) // atencao para esta linha.
sleep( 5000 ) // aguarda 5 segundos para que as jobs IPC subam.
ConOut('Gera Envio de Email - Funcionários com Contrato de Experiência a Vencer... '+Dtoc(DATE())+' - '+Time())

xExecExp()

RpcClearEnv() // Libera o Environment
ConOut('Finaliza Envio de Email - Funcionários com Contrato de Experiência a Vencer... '+Dtoc(DATE())+' - '+Time())
Return

Static Function xExecExp()
Local dDataExp := dDataBase + 15


cSQL :="SELECT RA_MAT, RA_CC, RA_NOME, RA_ADMISSA, RA_VCTOEXP, RA_EMAIL "
cSQL +="FROM " + RetSqlName("SRA") + " RA "
cSQL +="WHERE RA_SITFOLH NOT IN('A','D','F') "
cSQL +="AND RA.D_E_L_E_T_ = '' "
cSQL +="AND RA.RA_VCTOEXP >= '" + DtoS(dDataBase) + "' "
cSQL +="AND RA.RA_VCTOEXP <= '" + DtoS(dDataExp) + "' "
cSQL +="AND RA.RA_VCTOEXP <> '' "

TCQUERY(CSQL) NEW ALIAS "RAEXP"

TcSetField("RAEXP","RA_ADMISSA","D")
TcSetField("RAEXP","RA_VCTOEXP","D")

aFuncs:={}

RAEXP->(dbGoTop())
While RAEXP->(!Eof())

AAdd(aFuncs,{RAEXP->RA_MAT,RAEXP->RA_NOME,RAEXP->RA_EMAIL,DtoC(RAEXP->RA_ADMISSA),DtoC(RAEXP->RA_VCTOEXP),RAEXP->RA_CC})


dbSkip(1)

Enddo

If !Empty(Len(aFuncs))
EnvMail('elizeth.ferreira@araya.com.br;maria.duarte@araya.com.br','Funcionários com Contrato de Experiência a Vencer',aFuncs)
Endif

Return




/// ENVIA EMAIL


Static Function EnvMail(cPara,cAssunto,aFuncs)
Private nLineSize := 60
Private nTabSize := 3
Private lWrap := .T.
Private nLine := 0
Private lServErro := .T.
Private _cAnexo := 'EX'+DTOS(DDATABASE)+'.HTML'

GeraHtml(_cAnexo,aFuncs) //Gera HTML

lServERRO := .F.

CONNECT SMTP ;
SERVER GetMV("MV_RELSERV"); // Nome do servidor de e-mail
ACCOUNT GetMV("MV_RELACNT"); // Nome da conta a ser usada no e-mail
PASSWORD GetMV("MV_RELPSW") ; // Senha
Result lConectou

cDe := GetMV("MV_RELACNT")
cPara := Rtrim(cPara)
cAssunto:= Rtrim(cAssunto)
_cAnexo := Rtrim(_cAnexo)
mCorpo := AllTrim(MemoRead(_cAnexo))


SEND MAIL FROM cDe ;
To cPara ;
SUBJECT cAssunto ;
Body mCorpo;
RESULT lEnviado

DISCONNECT SMTP SERVER

If lConectou .AND. lEnviado
FErase(_cAnexo)
Else
cMensagem := ""
GET MAIL ERROR cMensagem
MsgAlert(cMensagem)

Endif
Return

Static Function GeraHtml(cArqOrc,aFuncs)
Private nTotOrc := 0
Private nLin := 0
//Private cOrc := "000010"

nHdl := Fcreate(cArqOrc)

//+CHR(13)+CHR(10)

cLin := '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
cLin := cLin + '<BODY leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">'
cLin := cLin + '<DIV align=center>'
cLin := cLin + ' <TABLE cellSpacing=0 cellPadding=0 width=642 border=1>'
cLin := cLin + ' <TBODY>'
cLin := cLin + ' <TR> '
cLin := cLin + ' <TD height="59" colspan="6"> <DIV align=center><STRONG><FONT '
cLin := cLin + ' face="Geneva, Arial, Helvetica, sans-serif" color=#ffffff '
cLin := cLin + ' size=4>FUNCIONÁRIOS COM DATA DE EXPERIÊNCIA A VENCER NOS PRÓXIMOS 15 DIAS </FONT></STRONG></DIV>'
cLin := cLin + ' <DIV align=center><STRONG><FONT size=5> '+DtoC(DDATABASE) + " - " + Str(Len(aFuncs),6) + ' FUNCIONÁRIO(S)</FONT></STRONG></DIV>'
cLin := cLin + ' <DIV align=center> '
cLin := cLin + ' <P align=center><STRONG><FONT size=3>ATENCAO ESSE EMAIL '
cLin := cLin + ' FOI GERADO AUTOMATICAMENTE PELO SISTEMA MICROSIGA.</FONT></STRONG></P>'
cLin := cLin + ' </DIV></TD>'
cLin := cLin + ' </TR>'
cLin := cLin + ' <TR bgColor=#cccccc> <TD width="85"> <DIV align=center><EM><STRONG>Matricula</STRONG></EM></DIV></TD> <TD width=343><EM><STRONG>Nome Funcionário(a)</STRONG></EM></TD> <TD width=85><EM><STRONG>Email</STRONG></EM></TD> <TD width=101> <DIV align=center><EM><STRONG>Dt.Admissão</STRONG></EM></DIV></TD> <TD width=85> <DIV align=center><EM><STRONG>Dt.Experiência</STRONG></EM></DIV></TD> <TD width=85> <DIV align=center><EM><STRONG>C.Custo</STRONG></EM></DIV></TD> </TR>'

For nItem :=1 To Len(aFuncs)
cLin := cLin + ' <td><div align="center"><font size="2"><strong>'+ aFuncs[nItem,1]+'</strong></font></div></td><td><font size="2"><strong>' + aFuncs[nItem,2] + '</strong></font></td><td><div align="center"><font size="2"><strong>'+aFuncs[nItem,3]+'</strong></font></div></td> <td><div align="center"><font size="2"><strong>'+aFuncs[nItem,4]+'</strong></font></div></td> <td><div align="center"><font size="3"><strong>'+aFuncs[nItem,5]+'</strong></font></div></td>'+'</strong></font></div></td><td><div align="center"><font size="2"><strong>' + aFuncs[nItem,6] + '</strong></font></td> </tr> '
Next nItem

cLin := cLin + ' <tr> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> </tr> '
cLin := cLin + ' <tr> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> <td><font size="3">&nbsp;</font></td> </tr> '

cLin := cLin + ' <tr> <td colspan="5"><p align="center"><font size="2"><br> <font size="3"><em><strong></strong></em></font></font></p> </td> </tr></table></div><p>&nbsp;</p><p>&nbsp;</p></body></html>'

FWrite(nHdl,cLin,Len(cLin))
FClose(nHdl)

Return (cArqOrc)

Luiz Alberto Vieira Alves
Proprietário
55 (12) 9 8256-5905 (Vivo)
www.3lsystems.com.br
www.masteradvpl.com.br

Por favor Acessar ou Registrar para participar da conversa.

Mais
11 anos 3 meses atrás #10241 por Rick
Respondido por Rick no tópico Schedule
A minha dúvida na vdd, é como eu posso startar esse relatório customizado de forma automatizada.

Por favor Acessar ou Registrar para participar da conversa.

Mais
11 anos 3 meses atrás #10243 por lalberto
Respondido por lalberto no tópico Schedule
Assim que criar esse fonte no schedule vc vai criar uma tarefa e colocar o nome do fonte

U_REL()

Luiz Alberto Vieira Alves
Proprietário
55 (12) 9 8256-5905 (Vivo)
www.3lsystems.com.br
www.masteradvpl.com.br

Por favor Acessar ou Registrar para participar da conversa.

Tempo para a criação da página:0.096 segundos
Joomla templates by a4joomla