/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/currentRecord', 'N/email', 'N/record', 'N/recordContext', 'N/render', 'N/runtime', 'N/search'],
/**
* @param{currentRecord} currentRecord
* @param{email} email
* @param{record} record
* @param{recordContext} recordContext
* @param{render} render
* @param{runtime} runtime
* @param{search} search
*/
(currentRecord, email, record, recordContext, render, runtime, search) => {
const checkForParameter = function checkForParameter(parameter, parameterName) {
if (parameter !== "" && parameter !== null && parameter !== undefined && parameter !== false && parameter !== "null" && parameter !== "undefined" && parameter !== " " && parameter !== 'false') {
return true;
} else {
if (parameterName)
log.debug('Empty Value found', 'Empty Value for parameter ' + parameterName);
return false;
}
}
const afterSubmit = (scriptContext) => {
try {
log.debug("scriptContext",scriptContext);
if (scriptContext.type === scriptContext.UserEventType.CREATE) {
var currentRec = scriptContext.newRecord;
var billPayment = currentRec.id;
var forEft=currentRec.getValue({
fieldId:'custbody_9997_is_for_ep_eft'
})
var toAch=currentRec.getValue({
fieldId:'toach'
})
var donotEmail=currentRec.getValue({
fieldId:'custbody_jj_do_not_email'
})
//check if payment is done using EFT
if((forEft== true || toAch== true) && donotEmail== false){
let vendorId = currentRec.getValue({
fieldId: 'entity'
})
//get email ids
var custEmails = search.lookupFields({
type: "vendor",
id: vendorId,
columns: ["custentity_2663_email_address_notif","email"]
});
var eftEmail = custEmails.custentity_2663_email_address_notif;
var primeEmail = custEmails.email;
var respEmail = [];
if (checkForParameter(eftEmail)) {
respEmail.push(eftEmail)
} else if(checkForParameter(primeEmail)) {
respEmail.push(primeEmail)
}
if (respEmail.length>0) {
var transactionFile = render.transaction({
entityId:billPayment,
printMode: render.PrintMode.PDF
});
//send email to the vendor
email.send({
author: '43659',
recipients: respEmail,
subject: 'DIRECT DEPOSIT REMITTANCE ADVICE ' ,
body: '<div>Please be advised of the attached direct deposit payment made to your bank account today.<br />If you have not received the funds into your bank account within 2-3 business days, please notify us immediately and we will put a tracer on the payment.<br /> I can be reached at 1-587-773-3272 if you have any questions or need assistance regarding this payment.<br /><br/>Thank you,<br /><br /><b>PURE CARE INC.</b><br /><b>Accounts Payable Dept.</b></div>',
attachments: [transactionFile],
relatedRecords:{
entityId:vendorId,
transactionId:billPayment
}
});
}
}
else {
var paymentAccount=currentRec.getValue({
fieldId:'account'
})
//check if payment done through credit card
if((paymentAccount == '978' || paymentAccount == '1111') && donotEmail==false){
let vendorId = currentRec.getValue({
fieldId: 'entity'
})
//get email ids
var custEmails = search.lookupFields({
type: "vendor",
id: vendorId,
columns: ["custentity_2663_email_address_notif","email"]
});
var eftEmail = custEmails.custentity_2663_email_address_notif;
var primeEmail = custEmails.email;
var respEmail = [];
if (checkForParameter(eftEmail)) {
respEmail.push(eftEmail)
} else if(checkForParameter(primeEmail)) {
respEmail.push(primeEmail)
}
if (respEmail.length>0) {
var transactionFile = render.transaction({
entityId:billPayment,
printMode: render.PrintMode.PDF
});
//send email to the vendor
email.send({
author: '43659',
recipients: respEmail,
subject: 'NOTIFICATION TO RUN PAYMENT ON CREDIT CARD',
body: '<div>Please run the attached payment through on the credit card you have on file for Pure Care Inc.<br />I can be reached at 1-587-773-3272 if you have any questions or need assistance regarding this payment.<br/> <br />Thank you,<br /><br /><b>PURE CARE INC.</b><br /><b>Accounts Payable Dept.</b></div>',
attachments: [transactionFile],
relatedRecords:{
entityId:vendorId,
transactionId:billPayment
}
});
}
}
else if((paymentAccount == '1021' || paymentAccount == '1108' || paymentAccount =='1046') && donotEmail== false ){
let vendorId = currentRec.getValue({
fieldId: 'entity'
})
//get email ids
var custEmails = search.lookupFields({
type: "vendor",
id: vendorId,
columns: ["custentity_2663_email_address_notif","email"]
});
var eftEmail = custEmails.custentity_2663_email_address_notif;
var primeEmail = custEmails.email;
var respEmail = [];
if (checkForParameter(eftEmail)) {
respEmail.push(eftEmail)
} else if(checkForParameter(primeEmail)) {
respEmail.push(primeEmail)
}
if (respEmail.length>0) {
var transactionFile = render.transaction({
entityId:billPayment,
printMode: render.PrintMode.PDF
});
//send email to the vendor
email.send({
author: '43659',
recipients: respEmail,
subject: 'DIRECT DEPOSIT REMITTANCE ADVICE' ,
body: '<div>Please be advised of the attached direct deposit payment made to your bank account today.<br /> If you have not received the funds into your bank account within 3-5 business days, please notify us immediately and we will put a tracer on the payment.<br />I can be reached at 1-587-773-3272 if you have any questions or need assistance regarding this payment<br /><br/>Thank you,<br /><br /><b>PURE CARE INC.</b><br /><b>Accounts Payable Dept.</b></div>',
attachments: [transactionFile],
relatedRecords:{
entityId:vendorId,
transactionId:billPayment
}
});
}
}
}
}
}catch(e){
log.debug("error@afterSubmit",e)
}
}
return {afterSubmit}
});