update
This commit is contained in:
@ -3,8 +3,10 @@ const db = require('./config/dbproc.js');
|
||||
|
||||
const RECIPIENT = 'rizki.rmdhn1304@gmail.com';
|
||||
|
||||
function buildHtml(approverName, title, priorName, idxjustification) {
|
||||
function buildHtml(approverName, title, priorName, idxjustification, remark, status) {
|
||||
const url = `https://e-portal.telkomcel.tl/app/ext/eproc/circulation/${idxjustification}`;
|
||||
const statusLabel = status || 'READY FOR APPROVAL';
|
||||
const notesLine = remark ? ` <li><strong>Notes:</strong> ${remark}</li>\n` : '';
|
||||
return `<p>Dear ${approverName},</p>
|
||||
|
||||
<p>A new workflow task requires your review and approval. Please find the details regarding this justification below:</p>
|
||||
@ -12,8 +14,8 @@ function buildHtml(approverName, title, priorName, idxjustification) {
|
||||
<ul>
|
||||
<li><strong>Justification:</strong> ${title}</li>
|
||||
<li><strong>Task Type:</strong> OPEN</li>
|
||||
<li><strong>Status:</strong> READY FOR APPROVAL</li>
|
||||
<li><strong>Sent By:</strong> ${priorName}</li>
|
||||
<li><strong>Status:</strong> ${statusLabel}</li>
|
||||
${notesLine} <li><strong>Sent By:</strong> ${priorName}</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>Action Required:</strong><br>
|
||||
@ -29,13 +31,16 @@ Procurement Division<br>
|
||||
Finance Business Partner Unit</p>`;
|
||||
}
|
||||
|
||||
function postEmail(approverName, title, priorName, idxjustification) {
|
||||
function postEmail(approverName, title, priorName, idxjustification, remark, status) {
|
||||
const subject = status === 'RETURNED'
|
||||
? `[Returned] Justification for ${title}`
|
||||
: `[Approval Required] Justification for ${title}`;
|
||||
const payload = JSON.stringify({
|
||||
to: [RECIPIENT],
|
||||
cc: [],
|
||||
bcc: [],
|
||||
subject: `[Approval Required] Justification for ${title}`,
|
||||
html: buildHtml(approverName, title, priorName, idxjustification)
|
||||
subject,
|
||||
html: buildHtml(approverName, title, priorName, idxjustification, remark, status)
|
||||
});
|
||||
|
||||
const req = http.request({
|
||||
@ -64,7 +69,7 @@ function postEmail(approverName, title, priorName, idxjustification) {
|
||||
*/
|
||||
function notifyOnSubmit(idxjustification) {
|
||||
const qryJustification = `
|
||||
select j.title, e.fullname as creator_name
|
||||
select j.title, j.remark, e.fullname as creator_name
|
||||
from tbl_justification j
|
||||
join dbssotcel.tbl_employee e on e.nik = j.iby
|
||||
where j._idx = '${idxjustification}' limit 1
|
||||
@ -75,6 +80,7 @@ function notifyOnSubmit(idxjustification) {
|
||||
return;
|
||||
}
|
||||
const title = rows[0].title;
|
||||
const remark = rows[0].remark || '';
|
||||
const creatorName = rows[0].creator_name;
|
||||
|
||||
const qryApprover = `
|
||||
@ -89,7 +95,7 @@ function notifyOnSubmit(idxjustification) {
|
||||
console.error('[email-notif] notifyOnSubmit: no approver found', err2);
|
||||
return;
|
||||
}
|
||||
postEmail(rows2[0].fullname, title, creatorName, idxjustification);
|
||||
postEmail(rows2[0].fullname, title, creatorName, idxjustification, remark);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -98,13 +104,14 @@ function notifyOnSubmit(idxjustification) {
|
||||
* Notify next approver after someone signs.
|
||||
*/
|
||||
function notifyOnSigned(idxjustification, signerNik) {
|
||||
const qryTitle = `select title from tbl_justification where _idx = '${idxjustification}' limit 1`;
|
||||
const qryTitle = `select title, remark from tbl_justification where _idx = '${idxjustification}' limit 1`;
|
||||
db.query(qryTitle, [], function(err, rows) {
|
||||
if (err || rows.length === 0) {
|
||||
console.error('[email-notif] notifyOnSigned: failed to get justification title', err);
|
||||
return;
|
||||
}
|
||||
const title = rows[0].title;
|
||||
const remark = rows[0].remark || '';
|
||||
|
||||
const qrySigner = `select fullname from dbssotcel.tbl_employee where nik = '${signerNik}' limit 1`;
|
||||
db.query(qrySigner, [], function(err2, rows2) {
|
||||
@ -126,10 +133,41 @@ function notifyOnSigned(idxjustification, signerNik) {
|
||||
console.log('[email-notif] notifyOnSigned: no more approvers to notify');
|
||||
return;
|
||||
}
|
||||
postEmail(rows3[0].fullname, title, signerName, idxjustification);
|
||||
postEmail(rows3[0].fullname, title, signerName, idxjustification, remark);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { notifyOnSubmit, notifyOnSigned };
|
||||
/**
|
||||
* Notify creator when justification is returned.
|
||||
*/
|
||||
function notifyOnReturn(idxjustification, returnerNik) {
|
||||
const qryJustification = `
|
||||
select j.title, j.remark, e.fullname as creator_name
|
||||
from tbl_justification j
|
||||
join dbssotcel.tbl_employee e on e.nik = j.iby
|
||||
where j._idx = '${idxjustification}' limit 1
|
||||
`;
|
||||
db.query(qryJustification, [], function(err, rows) {
|
||||
if (err || rows.length === 0) {
|
||||
console.error('[email-notif] notifyOnReturn: failed to get justification data', err);
|
||||
return;
|
||||
}
|
||||
const title = rows[0].title;
|
||||
const remark = rows[0].remark || '';
|
||||
const creatorName = rows[0].creator_name;
|
||||
|
||||
const qryReturner = `select fullname from dbssotcel.tbl_employee where nik = '${returnerNik}' limit 1`;
|
||||
db.query(qryReturner, [], function(err2, rows2) {
|
||||
if (err2 || rows2.length === 0) {
|
||||
console.error('[email-notif] notifyOnReturn: failed to get returner name', err2);
|
||||
return;
|
||||
}
|
||||
const returnerName = rows2[0].fullname;
|
||||
postEmail(creatorName, title, returnerName, idxjustification, remark, 'RETURNED');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { notifyOnSubmit, notifyOnSigned, notifyOnReturn };
|
||||
|
||||
Reference in New Issue
Block a user