IMPORT util IMPORT os IMPORT security DEFINE j INT, url_folder STRING, tmpfile STRING FUNCTION respuesta_laboral(pdata) DEFINE pdata,selec STRING, foto_empleado BYTE, cuenta_alegre,cuenta_malo int DEFINE credenciales RECORD usuario VARCHAR(50), clave VARCHAR(50), num_emp , departamento INT, nombre VARCHAR(100), respuesta SMALLINT, comentario STRING, dispositivo STRING, idpregunta VARCHAR(1) END RECORD, mensajes RECORD cod_msg INT, descripcion STRING END RECORD, instString,selecString string DISPLAY "llegue: ",pdata CALL util.JSON.parse(pdata,credenciales) IF STATUS < 0 THEN LET mensajes.cod_msg=400 LET mensajes.descripcion = 'ERROR EN CONEXION ',SQLCA.sqlerrm RETURN util.JSON.stringify(mensajes) END IF IF credenciales.usuario = 'demo' THEN LET mensajes.cod_msg=200 LET mensajes.descripcion = 'LLEGO DEMO ' RETURN util.JSON.stringify(mensajes) END IF DISPLAY "USUARIO: ",credenciales.usuario," pass ",credenciales.clave CONNECT TO "smarmotech" USER credenciales.usuario USING credenciales.clave IF STATUS < 0 THEN LET mensajes.cod_msg=STATUS LET mensajes.descripcion = 'ERROR EN CONEXION ',SQLCA.sqlerrm DISCONNECT CURRENT RETURN util.JSON.stringify(mensajes) END IF LET selec = 'SELECT distinct a.num_emp FROM encuestas.dbo.respuesta_laboral a WHERE month(a.fech_crea) =month(getdate()) and a.num_emp = ? and year(a.fech_crea) = year(getdate())' PREPARE busca FROM selec EXECUTE busca USING credenciales.num_emp IF STATUS = NOTFOUND THEN LET instString = "INSERT INTO encuestas.dbo.respuesta_laboral( [num_emp] ,[empleado] ,[dispositivo] ,[respuesta] ,[comentario] ,[fech_crea] ) VALUES ( ?,?,?,?,?,getdate() ) " PREPARE comando FROM instString EXECUTE comando USING credenciales.num_emp,credenciales.nombre,credenciales.dispositivo, credenciales.respuesta, credenciales.comentario LET mensajes.descripcion = 'RESPUESTA ADICIONADA EXITOSAMENTE' DISCONNECT CURRENT LET mensajes.cod_msg=200 RETURN util.JSON.stringify(mensajes) ELSE DISCONNECT CURRENT LET mensajes.descripcion = 'RESPUESTA NO ADICIONADA, USUARIO YA HABIA LLENADO' LET mensajes.cod_msg=401 RETURN util.JSON.stringify(mensajes) END IF END FUNCTION