Provision to enter the bill of entry amount. There is an assessable value for calculating IGST. Based on this amount the IGST will be calculated for an item. Foreign currency amount as the tax base amount for each tax item line. This will calculate the IGST based on the Ass. Val for IGST and the amount will reflect in the report as well.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/* Script Description
*
******************************************************************************************************
Manglam
Update Tax Basis for Item After bill Record Submit
******************************************************************************************************
* Date: 14/05/2019
*
* Author: Jobin & Jismi IT Services LLP*/
/*****************************************************************************************************/
define(['N/record', 'N/search', 'N/file', 'N/https'],
function(record, search, file, https) {
var main = {
afterSubmit: function(scriptContext) {
if (scriptContext.type == "edit" || scriptContext.type == "create") {
log.debug("scriptContext", scriptContext.type);
var recordObj = record.load({
type: scriptContext.newRecord.type,
id: scriptContext.newRecord.id,
isDynamic: true
});
var currencyExchange = recordObj.getValue({ fieldId: "exchangerate" });
var igstObj = main.getIgst(recordObj, currencyExchange);
log.debug("igstObj", igstObj);
main.updateTaxbasis(recordObj, igstObj);
var id = recordObj.save({ ignoreMandatoryFields: true });
log.debug("id", id);
}
},
getIgst: function(recordObj, currencyExchange) {
var numLines = recordObj.getLineCount({
sublistId: 'item'
});
var recData = {};
for (var i = 0; i < numLines; i++) {
var item = recordObj.getSublistText({
sublistId: 'item',
fieldId: 'item',
line: i
});
var itemtype = recordObj.getSublistValue({
sublistId: 'item',
fieldId: 'itemtype',
line: i
});
// if (itemtype == "InvtPart") {
recData[item] = {};
recData[item].igst = recordObj.getSublistValue({
sublistId: 'item',
fieldId: 'custcol_tran_ass_val_for_igst',
line: i
});
recData[item].customs = recordObj.getSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_customs_duty',
line: i
});
recData[item].surcharge = recordObj.getSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_surcharge',
line: i
});
if (!recData[item].customs)
recData[item].customs = 0;
if (!recData[item].surcharge)
recData[item].surcharge = 0;
if (!recData[item].igst)
recData[item].igst = 0;
recData[item].convertedTotal = (parseFloat(main.getNum(recData[item].igst)) + parseFloat(main.getNum(recData[item].customs)) + parseFloat(main.getNum(recData[item].surcharge))) / currencyExchange;
//}
}
return recData;
},
updateTaxbasis: function(recordObj, igstObj) {
var numLines = recordObj.getLineCount({
sublistId: 'taxdetails'
});
for (var i = 0; i < numLines; i++) {
recordObj.selectLine({
sublistId: 'taxdetails',
line: i
});
var item = recordObj.getSublistValue({
sublistId: 'taxdetails',
fieldId: 'linename',
line: i
});
log.debug("items", item);
recordObj.setCurrentSublistValue({
sublistId: 'taxdetails',
fieldId: 'taxbasis',
value: igstObj[item].convertedTotal,
ignoreFieldChange: true
});
var taxrate = recordObj.getSublistValue({
sublistId: 'taxdetails',
fieldId: 'taxrate',
line: i
});
log.debug("gstObj[item].convertedTotal", igstObj[item].convertedTotal);
log.debug("taxrate", taxrate);
recordObj.setCurrentSublistValue({
sublistId: 'taxdetails',
fieldId: 'taxamount',
value: igstObj[item].convertedTotal * (taxrate / 100),
ignoreFieldChange: true
});
recordObj.commitLine({
sublistId: 'taxdetails'
});
}
return recordObj;
},
getNum: function(val) {
if (isNaN(val) || (val == 'Infinity')) {
return 0;
}
return val;
}
};
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
function logDetails(error) {
log.debug('Error on function ' + key, error);
}
return function() {
try {
return myfunction.apply(this, arguments);
} catch (error) {
logDetails(error);
var response = {
summary: {
status: 'FAILED',
message: error
}
};
return response;
}
};
}
return main;
});