{ PROGRAMA: enviaencuestalaboral.4gl OBJETIVO: EJECUTAR LAS ENCUESTAS QUE SE ENVIEN DESDE OTRO PROGRAMA DE CALENDARIZACION, COMO ES SCHEDULE TASK FECHA : ABRIL 8, 2024 DESARROLLADO POR: ING. JUAN SOTO } IMPORT util IMPORT com IMPORT os DEFINE url,dato STRING, usuarios,clave VARCHAR(50) MAIN CALL ARG_VAL(1) RETURNING usuarios CALL ARG_VAL(2) RETURNING clave CONNECT to "smarmotech" AS "MSSQL" USER usuarios USING clave DISPLAY "EN PROCESO...." CALL enviar() END MAIN FUNCTION enviar() DEFINE pnum_emp INT, email_emp,selec,datos_emp,urlk,strcuerpo,strusername,xsmtphost,strpassword,strport,srtsubject STRING, pnombre VARCHAR(100), data RECORD token STRING END RECORD LET selec = " SELECT a.num_emp,a.email_corporativo,RTRIM(a.nom1_emp)+' '+RTRIM(a.apell1_Emp) FROM adtb00003 a WHERE a.status_t IS NULL AND a.enviar_encuesta='SI' AND a.email_corporativo is not null ORDER BY a.num_emp " PREPARE comando FROM SELEC DECLARE buscar CURSOR FOR comando OPEN buscar FOREACH buscar INTO pnum_emp,email_emp,pnombre LET url = "https://encuestalaboral.vercel.app/api/encrypt" LET datos_emp = pnum_emp USING "<<<<<<<<" CALL jewt(url,datos_emp) RETURNING urlk CALL util.JSON.parse(urlk,data) LET url = "https://encuestalaboral.vercel.app/orden/encuesta1/",data.token LET strcuerpo = "

BIENVENIDO A LA ENCUESTA SATISFACCION LABORAL DE NUESTRA EMPRESA MARMOTECH, S. A.

Favor de Clickear en este linkClick

", "" # LET strcuerpo = "

", # "Encuesta", # "

" SELECT a.from_address,a.puerto,a.nombre_servidor,a.clave INTO strusername,strport,xsmtphost,strpassword FROM tbperfil_mail a WHERE cod_perfil =2 # LET strusername ='notificacion@marmotech.com.do' # LET xsmtphost ='smtp.office365.com' # LET xsmtpport = '587' # LET xpassword = 'Lmmjvsd2020' # LET vendedoremail = 'jsoto@marmotech.com.do' LET srtsubject = 'ENCUESTA SATISFACCION LABORAL MARMOTECH' TRY CALL enviaemail(email_emp,srtsubject,strcuerpo,NULL,strusername,xsmtphost,strport,strpassword) INSERT INTO encuestas_log (fecha,referencia,observacion,email,nombre_usuario,estado,idencuesta) VALUES (getdate(),datos_emp,'SATISFACCION LABORAL',email_emp,pnombre,'VALIDO','4') CATCH INSERT INTO encuestas_log (fecha,referencia,observacion,email,nombre_usuario,estado,idencuesta) VALUES (getdate(),datos_emp,'SATISFACCION LABORAL',email_emp,pnombre,'NO VALIDO','') END TRY END FOREACH END FUNCTION FUNCTION jewt(url,dato) DEFINE jwtk,ret,res,url,s,dato STRING LET s = dato CLIPPED CALL sync_send_command(url, s) RETURNING ret, res LET jwtk = res RETURN jwtk END FUNCTION # ## Communications library using com (http or https) # FUNCTION sync_send_command(url, cmd) DEFINE url, cmd STRING DEFINE result, tmp STRING DEFINE http_req com.HTTPRequest DEFINE http_resp com.HTTPResponse TRY LET http_req = com.HTTPRequest.Create(url) CALL http_req.setConnectionTimeout(40) CALL http_req.setTimeout(40) CALL http_req.setMethod("POST") CALL http_req.setCharset("UTF-8") CALL http_req.setHeader("DBSync-Client","mbs") CALL http_req.setHeader("Content-Type","dbsync/json") DISPLAY "request ",cmd CALL http_req.doTextRequest(cmd) LET http_resp=http_req.getResponse() IF http_resp.getStatusCode() != 200 THEN RETURN http_resp.getStatusCode(), http_resp.getStatusDescription() END IF LET tmp = http_resp.getStatusDescription() IF (tmp == "OK" || tmp == "no error" ) THEN RETURN -1, SFMT("HTTP request status description: %1 ",tmp) END IF LET result = http_resp.getTextResponse() CATCH RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM) END TRY RETURN 0, result END FUNCTION FUNCTION show_sync_err(msg) DEFINE msg STRING CALL fgl_winmessage(%"ERROR", msg, "exclamation") END FUNCTION