diff --git a/src/FileCabinet/SuiteScripts/InventoryAdjustment/HC_MR_ExportedInventoryAdjustmentCSV.js b/src/FileCabinet/SuiteScripts/InventoryAdjustment/HC_MR_ExportedInventoryAdjustmentCSV.js
new file mode 100644
index 0000000..a1872cf
--- /dev/null
+++ b/src/FileCabinet/SuiteScripts/InventoryAdjustment/HC_MR_ExportedInventoryAdjustmentCSV.js
@@ -0,0 +1,230 @@
+/**
+ * @NApiVersion 2.1
+ * @NScriptType MapReduceScript
+ */
+define(['N/file', 'N/record', 'N/search', 'N/sftp', 'N/error', 'N/task'],
+ (file, record, search, sftp, error, task) => {
+ const internalIdList = new Set([]);
+
+ const checkInternalId = (internalid) => {
+ if (internalIdList.has(internalid)) {
+ return false;
+ } else {
+ internalIdList.add(internalid);
+ return true;
+ }
+ }
+
+ const getInputData = (inputContext) => {
+ var inventoryAdjustmentSearch = search.load({ id: 'customsearch_hc_exp_inventory_adjustment' });
+ return inventoryAdjustmentSearch;
+ }
+
+ const map = (mapContext) => {
+ var contextValues = JSON.parse(mapContext.value);
+
+ var internalid = contextValues.values.internalid.value;
+ var productSku = contextValues.values.item.value;
+ var lineId = contextValues.values.line;
+ var quantity = contextValues.values.quantity;
+ var locationInternalId = contextValues.values.location.value;
+ var comments = "Inventory Adjusted from Inventory Adjustment Transaction # " + internalid + " in NetSuite ";
+
+ if (internalid) {
+ var checkId = checkInternalId(internalid);
+ if (checkId) {
+ var id = record.submitFields({
+ type: record.Type.INVENTORY_ADJUSTMENT,
+ id: internalid,
+ values: {
+ custbody_hc_inven_adjustment_exported: true
+ }
+ });
+ }
+ }
+
+ var inventoryDeltaData = {
+ 'externalFacilityId': locationInternalId,
+ 'idValue': productSku,
+ 'idType': "NETSUITE_PRODUCT_ID",
+ 'availableDelta': quantity,
+ 'comments': comments
+ };
+
+ mapContext.write({
+ key: contextValues.id + '-' + lineId,
+ value: inventoryDeltaData
+ });
+ }
+
+ const reduce = (reduceContext) => {
+ var contextValues = JSON.parse(reduceContext.values);
+ var keyId = reduceContext.key;
+
+ var content = contextValues.externalFacilityId + ',' + contextValues.idValue + ',' + contextValues.idType + ',' + contextValues.availableDelta + ',' + contextValues.comments + '\n';
+ reduceContext.write(keyId, content);
+ }
+
+ const summarize = (summaryContext) => {
+ try {
+ var fileLines = 'externalFacilityId,idValue,idType,availableDelta,comments\n';
+ var totalRecordsExported = 0;
+
+ summaryContext.output.iterator().each(function(key, value) {
+ fileLines += value;
+ totalRecordsExported = totalRecordsExported + 1;
+ return true;
+ });
+ log.debug("====totalRecordsExported=="+totalRecordsExported);
+ if (totalRecordsExported > 0) {
+
+ var fileName = summaryContext.dateCreated + '-ExportInventoryAdjustment.csv';
+ var fileObj = file.create({
+ name: fileName,
+ fileType: file.Type.CSV,
+ contents: fileLines
+ });
+
+ //Get Custom Record Type SFTP details
+ var customRecordSFTPSearch = search.create({
+ type: 'customrecord_ns_sftp_configuration',
+ columns: [
+ 'custrecord_ns_sftp_server',
+ 'custrecord_ns_sftp_userid',
+ 'custrecord_ns_sftp_port_no',
+ 'custrecord_ns_sftp_host_key',
+ 'custrecord_ns_sftp_guid',
+ 'custrecord_ns_sftp_default_file_dir'
+ ]
+
+ });
+ var sftpSearchResults = customRecordSFTPSearch.run().getRange({
+ start: 0,
+ end: 1
+ });
+
+ var sftpSearchResult = sftpSearchResults[0];
+
+ var sftpUrl = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_server'
+ });
+
+ var sftpUserName = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_userid'
+ });
+
+ var sftpPort = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_port_no'
+ });
+
+ var hostKey = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_host_key'
+ });
+
+ var sftpKeyId = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_guid'
+ });
+
+ var sftpDirectory = sftpSearchResult.getValue({
+ name: 'custrecord_ns_sftp_default_file_dir'
+ });
+
+ sftpDirectory = sftpDirectory + 'inventoryadjustment';
+ sftpPort = parseInt(sftpPort);
+
+ var connection = sftp.createConnection({
+ username: sftpUserName,
+ secret: sftpKeyId,
+ url: sftpUrl,
+ port: sftpPort,
+ directory: sftpDirectory,
+ hostKey: hostKey
+ });
+ log.debug("Connection established successfully with SFTP server!");
+
+ if (fileObj.size > connection.MAX_FILE_SIZE) {
+ throw error.create({
+ name:"FILE_IS_TOO_BIG",
+ message:"The file you are trying to upload is too big"
+ });
+ }
+ connection.upload({
+ directory: '/import/',
+ file: fileObj
+ });
+ log.debug("Inventory Adjustment File Uploaded Successfully to SFTP server with file" + fileName);
+ }
+ } catch (e) {
+ //Generate error csv
+ var errorFileLine = 'orderId,Recordtype\n';
+
+ summaryContext.output.iterator().each(function (key, value) {
+ var index = key.split('-')
+ var internalId = index[0]
+ var recordType = "INVENTORY_ADJUSTMENT"
+
+ var valueContents = internalId + ',' + recordType + '\n'
+ errorFileLine += valueContents;
+
+ return true;
+ });
+
+ var fileName = summaryContext.dateCreated + '-FailedInventoryTransferExport.csv';
+ var failExportCSV = file.create({
+ name: fileName,
+ fileType: file.Type.CSV,
+ contents: errorFileLine
+ });
+
+ // Check HotWax Export Fail Record CSV is created or not
+ var folderInternalId = search
+ .create({
+ type: search.Type.FOLDER,
+ filters: [['name', 'is', 'HotWax Export Fail Record CSV']],
+ columns: ['internalid']
+ })
+ .run()
+ .getRange({ start: 0, end: 1 })
+ .map(function (result) {
+ return result.getValue('internalid');
+ })[0];
+
+ // Made Export Fail Sales Order CSV folder in NetSuite File Cabinet
+ if (folderInternalId == null) {
+ var folder = record.create({ type: record.Type.FOLDER });
+ folder.setValue({
+ fieldId: 'name',
+ value: 'HotWax Export Fail Record CSV'
+ });
+
+ var folderInternalId = folder.save();
+ }
+
+ failExportCSV.folder = folderInternalId;
+ failExportCSV.save();
+
+ if (folderInternalId) {
+ var scriptTask = task.create({
+ taskType: task.TaskType.MAP_REDUCE,
+ });
+
+ scriptTask.scriptId = 'customscript_hc_mr_mark_false',
+ scriptTask.deploymentId = 'customdeploy_hc_mr_mark_false'
+ scriptTask.params = { "custscript_hc_mr_mark_false": folderInternalId }
+
+ var mapReduceTaskId = scriptTask.submit();
+ log.debug("Map/reduce task submitted!");
+ }
+
+ log.error({
+ title: 'Error in exporting and uploading inventory adjustment csv files',
+ details: e,
+ });
+ throw error.create({
+ name:"Error in exporting and uploading inventory adjustment csv files",
+ message: e
+ });
+ }
+ }
+ return {getInputData, map, reduce, summarize}
+ });
\ No newline at end of file
diff --git a/src/FileCabinet/SuiteScripts/POSReturn/HC_SC_CreatePOSReturn.js b/src/FileCabinet/SuiteScripts/POSReturn/HC_SC_CreatePOSReturn.js
index 7244286..8f300cf 100644
--- a/src/FileCabinet/SuiteScripts/POSReturn/HC_SC_CreatePOSReturn.js
+++ b/src/FileCabinet/SuiteScripts/POSReturn/HC_SC_CreatePOSReturn.js
@@ -88,6 +88,7 @@ define(['N/sftp', 'N/record', 'N/error', 'N/search', 'N/file'], function (sftp,
for (var dataIndex = 0; dataIndex < returnAuthorizationDataList.length; dataIndex++) {
var orderId = returnAuthorizationDataList[dataIndex].order_id;
var posReturnTotal = returnAuthorizationDataList[dataIndex].pos_return_total;
+ var hcReturnId = returnAuthorizationDataList[dataIndex].hc_return_id;
var itemList = returnAuthorizationDataList[dataIndex].items;
var paymentlist = returnAuthorizationDataList[dataIndex].payment_list;
// exchange credit value contain giftcard amount.
@@ -113,6 +114,11 @@ define(['N/sftp', 'N/record', 'N/error', 'N/search', 'N/file'], function (sftp,
fieldId: 'orderstatus',
value: "B"
});
+
+ returnAuthorizationRecord.setValue({
+ fieldId: 'custbody_hc_pos_return_id',
+ value: hcReturnId
+ });
var lineCount = returnAuthorizationRecord.getLineCount({
sublistId: 'item'
diff --git a/src/Objects/InventoryAdjustment/custbody_hc_inven_adjustment_exported.xml b/src/Objects/InventoryAdjustment/custbody_hc_inven_adjustment_exported.xml
new file mode 100644
index 0000000..1b40b12
--- /dev/null
+++ b/src/Objects/InventoryAdjustment/custbody_hc_inven_adjustment_exported.xml
@@ -0,0 +1,59 @@
+
+ 2
+ F
+ F
+
+ F
+ F
+ F
+ T
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+
+
+
+
+ NORMAL
+
+
+ F
+ CHECKBOX
+
+ F
+
+ F
+ F
+ F
+
+
+
+
+
+
+
+
+
+ 2
+
+ F
+ F
+
+
+
+ T
+ [scriptid=custtab_hc_tab]
+
\ No newline at end of file
diff --git a/src/Objects/InventoryAdjustment/customscript_exp_inventory_adj.xml b/src/Objects/InventoryAdjustment/customscript_exp_inventory_adj.xml
new file mode 100644
index 0000000..e92f2c2
--- /dev/null
+++ b/src/Objects/InventoryAdjustment/customscript_exp_inventory_adj.xml
@@ -0,0 +1,29 @@
+
+
+ F
+ HC_MR_ExportedInventoryAdjustmentCSV
+ F
+
+ T
+ [/SuiteScripts/InventoryTransfer/HC_MR_ExportedInventoryAdjustmentCSV.js]
+
+
+ 1
+ 1
+ T
+ DEBUG
+ T
+ SCHEDULED
+ HC_MR_ExportedInventoryAdjustmentCSV
+ 60
+
+
+ 1
+ PT1H
+ 2023-08-22
+ 05:00:00Z
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Objects/POSReturn/custbody_hc_pos_return_id.xml b/src/Objects/POSReturn/custbody_hc_pos_return_id.xml
new file mode 100644
index 0000000..533e4b7
--- /dev/null
+++ b/src/Objects/POSReturn/custbody_hc_pos_return_id.xml
@@ -0,0 +1,59 @@
+
+ 2
+ F
+ T
+
+ F
+ F
+ F
+ F
+ F
+ F
+ T
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ F
+ T
+ F
+ F
+ F
+ F
+
+
+
+
+ NORMAL
+
+
+ F
+ TEXT
+
+ T
+
+ F
+ F
+ F
+
+
+
+
+
+
+
+
+
+ 2
+
+ F
+ F
+
+
+
+ T
+ [scriptid=custtab_hc_tab]
+
\ No newline at end of file
diff --git a/src/deploy.xml b/src/deploy.xml
index df3da15..4e7f2da 100644
--- a/src/deploy.xml
+++ b/src/deploy.xml
@@ -60,6 +60,7 @@
~/FileCabinet/SuiteScripts/Product/HC_MR_ExportedKITProductCSV.js
~/FileCabinet/SuiteScripts/SalesOrder/HC_MR_ExportedGiftCardFulfillmentCSV.js
~/FileCabinet/SuiteScripts/POSReturn/HC_SC_CreatePOSReturn.js
+ ~/FileCabinet/SuiteScripts/InventoryAdjustment/HC_MR_ExportedInventoryAdjustmentCSV.js
@@ -89,6 +90,8 @@
~/Objects/SalesOrder/custcolisbopis.xml
~/Objects/POSReturn/custcol_hc_retrun_reason.xml
~/Objects/InventoryTransfer/custbody_hc_inv_transfer_no.xml
+ ~/Objects/InventoryAdjustment/custbody_hc_inven_adjustment_exported.xml
+ ~/Objects/POSReturn/custbody_hc_pos_return_id.xml
~/Objects/SalesOrder/custform_hc_sales_order_form.xml
@@ -160,6 +163,7 @@
~/Objects/Product/customscript_exp_kitproducts.xml
~/Objects/SalesOrder/customscript_exp_giftcard_fulfillment.xml
~/Objects/POSReturn/customscript_create_pos_return.xml
+ ~/Objects/InventoryAdjustment/customscript_exp_inventory_adj.xml
~/Objects/CashSale/customsearch_hc_export_cashsales.xml