/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define([
"N/log",
"N/record",
"N/task",
"N/ui/serverWidget",
"N/util",
"N/url",
"../../Library/JJ CM NS Utility.js",
"../../Model/JJ CM Resolver Model.js",
"../../Excel Template/JJ CM Resolver Template.js",
]
/**
* @param{log} log
* @param{record} record
* @param{task} task
* @param{serverWidget} serverWidget
* @param{util} util
* @param{url} url
* @param{jjUtil} jjUtil
* @param{modelResolver} modelResolver
* @param{templateResolver} templateResolver
*/, (
log,
record,
task,
serverWidget,
util,
url,
jjUtil,
modelResolver,
templateResolver
) => {
try {
let fetchModel;
let templateFetch;
const PAGE_SIZE = 1000;
const DEFAULT_SUBSIDIARY = "ALL";
const form = {
/**
* to refer suitelet form object
*/
formObj: null,
/**
* repository to refer all buttons
*/
buttons: {},
/**
* repository to refer all body fields
*/
bodyFields: {},
/**
* repository to refer all sublists
*/
subLists: {},
/**
* repository to refer all fieldgroups
*/
fieldGroups: {},
init(formObj) {
this.formObj = formObj;
},
setformFieldProperty(field, propObj) {
const setFieldProp = {
updateLayoutType: function (field, value) {
field.updateLayoutType({
layoutType: value,
});
},
updateBreakType: function (field, value) {
field.updateBreakType({
breakType: value,
});
},
updateDisplayType: function (field, value) {
field.updateDisplayType({
displayType: value,
});
},
setHelpText: function (field, value) {
field.setHelpText({
help: value,
});
},
isMandatory: function (field, value) {
field.isMandatory = value;
},
defaultValue: function (field, value) {
field.defaultValue = value;
},
};
for (let prop in propObj)
if (propObj[prop]) setFieldProp[prop](field, propObj[prop]);
},
/**
* To set buttons in the Suitelet form
*/
setBodyButtons() {
let formObj = form.formObj;
form.buttons.custpage_btn_export = formObj.addButton({
id: "custpage_btn_export",
label: "Download",
functionName: "triggerExport",
});
// form.buttons.custpage_btn_search = formObj.addButton({
// id: "custpage_btn_search",
// label: "Search",
// functionName: 'triggerSearch',
// });
},
/**
* To set body fields in the Suitelet form
*/
setBodyFields() {
let formObj = form.formObj;
form.bodyFields.custpage_field_hidden_inlinehtml = formObj.addField({
id: "custpage_field_hidden_inlinehtml",
type: serverWidget.FieldType.INLINEHTML,
label: "Inline HTML",
});
form.setformFieldProperty(
form.bodyFields.custpage_field_hidden_inlinehtml,
{
setHelpText: "Inline HTML",
isMandatory: true,
defaultValue: `<script>
window.ns_screenfields_suiteletform = window.ns_screenfields_suiteletform || {};
window.ns_screenfields_suiteletform.suiteletFormUrl = "${url.resolveScript(
{
scriptId: "customscript_jj_sl_cash_vcprl_22",
deploymentId: "customdeploy_jj_sl_cash_vcprl_22",
}
)}";
</script>`,
}
);
form.fieldGroups.custpage_group_filter = formObj.addFieldGroup({
id: "custpage_group_filter",
label: "Filter",
});
//form.fieldGroups.custpage_group_filter.isSingleColumn = true;
//Subsidiary
form.bodyFields.custpage_filter_subsidiary = formObj.addField({
id: "custpage_filter_subsidiary",
label: "Subsidiary",
type: serverWidget.FieldType.SELECT,
//source: 'subsidiary',
container: "custpage_group_filter",
});
const subsidiarySavedSearchResult = fetchModel.models.fetchSubsidiary({
filterConfig: {},
searchConfig: {
PAGE_INDEX: false,
PAGE_SIZE: 1000,
},
});
form.bodyFields.custpage_filter_subsidiary.addSelectOption({
value: "ALL",
text: "- All -",
//isSelected: true,
});
for (let elem of subsidiarySavedSearchResult) {
form.bodyFields.custpage_filter_subsidiary.addSelectOption({
value: elem?.["InternalID"].value,
text: elem?.["NameNoHierarchy"].value,
//isSelected: true,
});
}
form.setformFieldProperty(form.bodyFields.custpage_filter_subsidiary, {
// updateLayoutType: serverWidget.FieldLayoutType.STARTROW,
setHelpText: "Choose subsidiary",
isMandatory: true,
defaultValue:
exports.parameters?.custpage_filter_subsidiary || DEFAULT_SUBSIDIARY,
});
const departmentSavedSearchResult = fetchModel.models.fetchDepartment({
filterConfig: {},
searchConfig: {
PAGE_INDEX: false,
PAGE_SIZE: 1000,
},
});
form.bodyFields.custpage_filter_department = formObj.addField({
id: "custpage_filter_department",
label: "Department",
type: serverWidget.FieldType.SELECT,
//source: 'subsidiary',
container: "custpage_group_filter",
});
form.bodyFields.custpage_filter_department.addSelectOption({
value: "ALL",
text: "- All -",
//isSelected: true,
});
for (let elem of departmentSavedSearchResult) {
form.bodyFields.custpage_filter_department.addSelectOption({
value: elem?.["InternalID"].value,
text: elem?.["Name"].value,
//isSelected: true,
});
}
form.setformFieldProperty(form.bodyFields.custpage_filter_department, {
// updateLayoutType: serverWidget.FieldLayoutType.STARTROW,
setHelpText: "Choose Department",
isMandatory: true,
defaultValue: exports.parameters?.custpage_filter_department || "ALL",
});
//Vendor
const vendorSavedSearchResult = fetchModel.models.fetchVendor({
filterConfig: {},
searchConfig: {
PAGE_INDEX: false,
PAGE_SIZE: 1000,
},
});
form.bodyFields.custpage_filter_vendor = formObj.addField({
id: "custpage_filter_vendor",
label: "Vendor",
type: serverWidget.FieldType.SELECT,
container: "custpage_group_filter",
});
form.bodyFields.custpage_filter_vendor.addSelectOption({
value: "ALL",
text: "- All -",
//isSelected: true,
});
form.bodyFields.custpage_filter_vendor.addSelectOption({
value: "NONE",
text: "- None -",
//isSelected: true,
});
for (let elem of vendorSavedSearchResult) {
form.bodyFields.custpage_filter_vendor.addSelectOption({
value: elem?.["InternalID"].value,
text: elem?.["Name"].value,
//isSelected: true,
});
}
form.setformFieldProperty(form.bodyFields.custpage_filter_vendor, {
// updateLayoutType: serverWidget.FieldLayoutType.STARTROW,
setHelpText: "Choose Vendor",
isMandatory: true,
defaultValue: exports.parameters?.custpage_filter_vendor || "ALL",
});
},
/**
* To set the sublist in the Suitelet form
*/
setSublistFields() {
form.subLists.custpage_subl_report = form.formObj.addSublist({
id: "custpage_subl_report",
type: serverWidget.SublistType.LIST,
label: "Cash Projection Report",
});
const columnMap = {
Rows: {
id: "custpage_market_name",
label: "",
type: serverWidget.FieldType.TEXT,
},
WK0: {
id: "custpage_vendor_name",
label: "WKO",
type: serverWidget.FieldType.CURRENCY,
},
WK1: {
id: "custpage_total_payable",
label: "WK1",
type: serverWidget.FieldType.CURRENCY,
},
WK2: {
id: "custpage_total_receivable",
label: "WK2",
type: serverWidget.FieldType.CURRENCY,
},
WK3: {
id: "custpage_difference",
label: "Wk3",
type: serverWidget.FieldType.CURRENCY,
},
};
for (let column in columnMap)
form.subLists.custpage_subl_report.addField({
id: columnMap[column].id,
label: columnMap[column].label,
type: columnMap[column].type,
align: serverWidget.LayoutJustification.LEFT,
});
},
generateForm() {
log.debug("generateForm", "generateForm");
//Initialize Suitelet Form
form.init(
serverWidget.createForm({
title: "Cash Projection Report",
})
);
//Associate Client Script with Suitelet
// form.formObj.clientScriptModulePath =
// "./JJ CS Payments Received Paid Report VCPRL-32.js";
//Set Body Buttons
form.setBodyButtons();
//Set Body Fields
form.setBodyFields();
//Set Sublist Fields
form.setSublistFields();
return this.formObj;
},
};
jjUtil.applyTryCatch(
form,
"JJ SL Cash Projection Report VCPRL-22.js, form"
);
const exports = {
context: "",
method: "",
parameters: {
custpage_filter_subsidiary: "",
//custpage_filter_period_of_year: "",
// custpage_filter_period_of_quarter: "",
custpage_filter_vendor: "",
// custpage_filter_buyer: "",
custpage_filter_department: "",
//custpage_filter_year_formatted: "",d
// custpage_filter_quarter_formatted: "",
custpage_filter_vendor_formatted: "",
// custpage_filter_buyer_formatted: "",
custpage_filter_department_formatted: "",
custpage_filter_pageindex: "",
//custpage_filter_isclosed: "",
toBeDownloaded: false,
toBeScheduled: false,
},
body: "",
/**
* To initialise the
* @param {Object} scriptContext
* @param {ServerRequest} scriptContext.request - Incoming request
* @param {ServerResponse} scriptContext.response - Suitelet response
* @since 2015.2
*/
init(scriptContext) {
this.context = scriptContext;
this.method = scriptContext.request.method;
this.parameters = scriptContext.request.parameters;
this.body = scriptContext.request.body;
},
onRequest(scriptContext) {
try {
exports.init(scriptContext);
if (this.method == "GET") {
log.debug("exports.parameters", exports.parameters);
fetchModel = modelResolver.modelFetch('CASH_PROJECTION_REPORT');
const suiteletForm = form.generateForm();
log.debug("form",suiteletForm)
if (suiteletForm)
return exports.context.response.writePage(suiteletForm), true;
return exports.context.response.write("SOMETHING_WENT_WRONG"), false;
}
return exports.context.response.write("SOMETHING_WENT_WRONG"), false;
} catch (e) {
log.debug("error", e);
}
},
};
return exports;
//
// /**
// * Defines the Suitelet script trigger point.
// * @param {Object} scriptContext
// * @param {ServerRequest} scriptContext.request - Incoming request
// * @param {ServerResponse} scriptContext.response - Suitelet response
// * @since 2015.2
// */
// const onRequest = (scriptContext) => {
// try{
// // exports.init(scriptContext);
// if(scriptContext.request==="GET"){
// const suiteletForm = form.generateForm();
// if (suiteletForm)
// return exports.context.response.writePage(suiteletForm), true;
// return exports.context.response.write("SOMETHING_WENT_WRONG"), false;
// }
// scriptContext.response.writePage(suiteletForm)
// }catch (e) {
//
// }
//
// }
}catch (e) {
log.debug("Eoor",e)
}
});