152 lines
4.8 KiB
Plaintext
152 lines
4.8 KiB
Plaintext
DEFINE usuarios, clave STRING
|
|
|
|
DEFINE encuesta_details DYNAMIC ARRAY OF RECORD
|
|
email STRING,
|
|
num_mes INT,
|
|
respuesta INT,
|
|
cotizacion_no INT,
|
|
NPS STRING,
|
|
vendedor STRING,
|
|
departamento STRING
|
|
END RECORD
|
|
|
|
DEFINE query, container STRING, i INT
|
|
|
|
DEFINE retractores, promotores, total_respuestas INT, nps DECIMAL(12,2)
|
|
|
|
|
|
MAIN
|
|
DEFER INTERRUPT
|
|
CALL ARG_VAL(1) RETURNING usuarios
|
|
CALL ARG_VAL(2) RETURNING clave
|
|
CONNECT TO "smarmotech" AS "MSSQL" USER usuarios USING clave
|
|
CALL supervisor_nps()
|
|
END MAIN
|
|
|
|
FUNCTION supervisor_nps()
|
|
|
|
LET query = "SELECT a.numero_mes, a.respuesta, a.cotizacion_no, a.NPS, a.vendedor, a.departamento FROM
|
|
encuestas.dbo.vwencuesta_cliente a where a.ano = 2025 order by a.vendedor, a.numero_mes"
|
|
|
|
DECLARE buscar CURSOR FROM query
|
|
|
|
LET i = 1
|
|
LET retractores = 0,promotores = 0, total_respuestas = 0
|
|
LET container = encuesta_details[i].vendedor
|
|
|
|
FOREACH buscar INTO encuesta_details[i].*
|
|
|
|
IF container <> encuesta_details[i].vendedor THEN
|
|
|
|
CALL calcular_nps() RETURNING nps
|
|
CALL send_info_mail(nps, total_respuestas,
|
|
encuesta_details[i - 1].departamento, encuesta_details[i - 1].vendedor,
|
|
encuesta_details[i - 1].email)
|
|
|
|
LET retractores = 0,promotores = 0, total_respuestas = 0
|
|
LET container = encuesta_details[i].vendedor
|
|
|
|
END IF
|
|
|
|
IF encuesta_details[i].respuesta <= 6 THEN
|
|
LET retractores = retractores + 1
|
|
ELSE
|
|
IF encuesta_details[i].respuesta >= 9 THEN
|
|
LET promotores = promotores + 1
|
|
END IF
|
|
END IF
|
|
|
|
LET total_respuestas = total_respuestas + 1
|
|
|
|
LET i = i + 1
|
|
|
|
END FOREACH
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION calcular_nps()
|
|
|
|
DEFINE porc_promotores, porc_retractores DECIMAL (12,2)
|
|
|
|
LET porc_promotores = promotores / total_respuestas
|
|
|
|
LET porc_retractores = retractores / total_respuestas
|
|
|
|
RETURN (porc_promotores - porc_retractores) * 100
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION send_info_mail(mail_nps, mail_totalrespuesta, mail_departamento, mail_vendedor, mail_correo)
|
|
|
|
DEFINE mail_nps DECIMAL (12,2)
|
|
DEFINE mail_totalrespuesta INT
|
|
DEFINE mail_departamento, mail_vendedor, mail_correo STRING
|
|
|
|
DEFINE strcuerpo,strusername,xsmtphost,strpassword,strport,srtsubject STRING
|
|
|
|
LET srtsubject = "NPS CLIENTES POR VENDEDOR"
|
|
|
|
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 strcuerpo ="<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<style>
|
|
table {
|
|
font-family: Arial, sans-serif;
|
|
border-collapse: collapse;
|
|
width: 100%;
|
|
max-width: 600px;
|
|
}
|
|
th, td {
|
|
border: 1px solid #dddddd;
|
|
text-align: center;
|
|
padding: 12px;
|
|
}
|
|
th {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
}
|
|
caption {
|
|
caption-side: top;
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
margin-bottom: 10px;
|
|
}
|
|
tr:nth-child(even) {
|
|
background-color: #f9f9f9;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table>
|
|
<caption>NPS CLIENTES - Vendedor " || mail_vendedor || "</caption>
|
|
<tr>
|
|
<th>Departamento</th>
|
|
<th>Total de respuestas</th>
|
|
<th>NPS</th>
|
|
</tr>
|
|
<tr>
|
|
<td>" || mail_departamento || "</td>
|
|
<td>" || mail_totalrespuesta || "</td>
|
|
<td>" || mail_nps || "</td>
|
|
</tr>
|
|
</table>
|
|
</body>
|
|
</html>"
|
|
|
|
|
|
IF mail_correo IS NOT NULL THEN
|
|
CALL enviaemail(mail_correo,srtsubject,strcuerpo,NULL,strusername,xsmtphost,strport,strpassword) #RETURNING retorne
|
|
ELSE
|
|
DISPLAY "NO HAY MAIL"
|
|
END IF
|
|
|
|
|
|
END FUNCTION
|
|
|
|
|
|
|